test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 30.52 | 32.76 | 3.28e-4 |
10,000 add & delete randomly | 66.96 | 14.94 | 0.00 |
10,000 addMany | 39.78 | 25.14 | 3.67e-4 |
10,000 get | 27.38 | 36.52 | 0.00 |
# Data Structure Typed ![NPM](https://img.shields.io/npm/l/data-structure-typed) ![GitHub top language](https://img.shields.io/github/languages/top/zrwusa/data-structure-typed) ![npm](https://img.shields.io/npm/dw/data-structure-typed) ![eslint](https://aleen42.github.io/badges/src/eslint.svg) ![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/data-structure-typed) ![npm bundle size](https://img.shields.io/bundlephobia/min/data-structure-typed) ![npm](https://img.shields.io/npm/v/data-structure-typed) Data Structures of Javascript & TypeScript. Do you envy C++ with [STL](), Python with [collections](), and Java with [java.util]() ? Well, no need to envy anymore! JavaScript and TypeScript now have [data-structure-typed](). Now you can use this library in Node.js and browser environments in CommonJS(require export.modules = ), ESModule(import export), Typescript(import export), UMD(var Queue = dataStructureTyped.Queue) [//]: # (![Branches](https://img.shields.io/badge/branches-55.47%25-red.svg?style=flat)) [//]: # (![Statements](https://img.shields.io/badge/statements-67%25-red.svg?style=flat)) [//]: # (![Functions](https://img.shields.io/badge/functions-66.38%25-red.svg?style=flat)) [//]: # (![Lines](https://img.shields.io/badge/lines-68.6%25-red.svg?style=flat)) ## Built-in classic algorithms
Algorithm | Function Description | Iteration Type |
---|---|---|
Binary Tree DFS | Traverse a binary tree in a depth-first manner, starting from the root node, first visiting the left subtree, and then the right subtree, using recursion. | Recursion + Iteration |
Binary Tree BFS | Traverse a binary tree in a breadth-first manner, starting from the root node, visiting nodes level by level from left to right. | Iteration |
Graph DFS | Traverse a graph in a depth-first manner, starting from a given node, exploring along one path as deeply as possible, and backtracking to explore other paths. Used for finding connected components, paths, etc. | Recursion + Iteration |
Binary Tree Morris | Morris traversal is an in-order traversal algorithm for binary trees with O(1) space complexity. It allows tree traversal without additional stack or recursion. | Iteration |
Graph BFS | Traverse a graph in a breadth-first manner, starting from a given node, first visiting nodes directly connected to the starting node, and then expanding level by level. Used for finding shortest paths, etc. | Recursion + Iteration |
Graph Tarjan's Algorithm | Find strongly connected components in a graph, typically implemented using depth-first search. | Recursion |
Graph Bellman-Ford Algorithm | Finding the shortest paths from a single source, can handle negative weight edges | Iteration |
Graph Dijkstra's Algorithm | Finding the shortest paths from a single source, cannot handle negative weight edges | Iteration |
Graph Floyd-Warshall Algorithm | Finding the shortest paths between all pairs of nodes | Iteration |
Graph getCycles | Find all cycles in a graph or detect the presence of cycles. | Recursion |
Graph getCutVertexes | Find cut vertices in a graph, which are nodes that, when removed, increase the number of connected components in the graph. | Recursion |
Graph getSCCs | Find strongly connected components in a graph, which are subgraphs where any two nodes can reach each other. | Recursion |
Graph getBridges | Find bridges in a graph, which are edges that, when removed, increase the number of connected components in the graph. | Recursion |
Graph topologicalSort | Perform topological sorting on a directed acyclic graph (DAG) to find a linear order of nodes such that all directed edges go from earlier nodes to later nodes. | Recursion |
Data Structure | Unit Test | Performance Test | API Documentation | Implemented |
---|---|---|---|---|
Binary Tree | Binary Tree | |||
Binary Search Tree (BST) | BST | |||
AVL Tree | AVLTree | |||
Red Black Tree | AVLTree | |||
Tree Multiset | TreeMultimap | |||
Segment Tree | SegmentTree | |||
Binary Indexed Tree | BinaryIndexedTree | |||
Graph | AbstractGraph | |||
Directed Graph | DirectedGraph | |||
Undirected Graph | UndirectedGraph | |||
Linked List | SinglyLinkedList | |||
Singly Linked List | SinglyLinkedList | |||
Doubly Linked List | DoublyLinkedList | |||
Queue | Queue | |||
Object Deque | ObjectDeque | |||
Array Deque | ArrayDeque | |||
Stack | Stack | |||
Coordinate Set | CoordinateSet | |||
Coordinate Map | CoordinateMap | |||
Heap | Heap | |||
Priority Queue | PriorityQueue | |||
Max Priority Queue | MaxPriorityQueue | |||
Min Priority Queue | MinPriorityQueue | |||
Trie | Trie |
Data Structure Typed | C++ STL | java.util | Python collections |
---|---|---|---|
DoublyLinkedList<E> | list<T> | LinkedList<E> | deque |
SinglyLinkedList<E> | - | - | - |
Array<E> | vector<T> | ArrayList<E> | list |
Queue<E> | queue<T> | Queue<E> | - |
Deque<E> | deque<T> | - | - |
PriorityQueue<E> | priority_queue<T> | PriorityQueue<E> | - |
Heap<E> | priority_queue<T> | PriorityQueue<E> | heapq |
Stack<E> | stack<T> | Stack<E> | - |
Set<E> | set<T> | HashSet<E> | set |
Map<K, V> | map<K, V> | HashMap<K, V> | dict |
- | unordered_set<T> | HashSet<E> | - |
HashMap<K, V> | unordered_map<K, V> | HashMap<K, V> | defaultdict |
Map<K, V> | - | - | OrderedDict |
BinaryTree<K, V> | - | - | - |
BST<K, V> | - | - | - |
TreeMultimap<K, V> | multimap<K, V> | - | - |
AVLTree<E> | - | TreeSet<E> | - |
AVLTree<K, V> | - | TreeMap<K, V> | - |
AVLTree<E> | set | TreeSet<E> | - |
Trie | - | - | - |
- | multiset<T> | - | - |
DirectedGraph<V, E> | - | - | - |
UndirectedGraph<V, E> | - | - | - |
- | unordered_multiset | - | Counter |
- | - | LinkedHashSet<E> | - |
- | - | LinkedHashMap<K, V> | - |
- | unordered_multimap<K, V> | - | - |
- | bitset<N> | - | - |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 30.52 | 32.76 | 3.28e-4 |
10,000 add & delete randomly | 66.96 | 14.94 | 0.00 |
10,000 addMany | 39.78 | 25.14 | 3.67e-4 |
10,000 get | 27.38 | 36.52 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000 add randomly | 10.50 | 95.20 | 2.30e-4 |
1,000 add & delete randomly | 16.18 | 61.81 | 2.48e-4 |
1,000 addMany | 10.80 | 92.62 | 1.83e-4 |
1,000 get | 18.03 | 55.45 | 1.41e-4 |
1,000 dfs | 157.86 | 6.33 | 0.00 |
1,000 bfs | 56.68 | 17.64 | 0.00 |
1,000 morris | 37.21 | 26.88 | 2.79e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 27.61 | 36.21 | 4.73e-4 |
10,000 add & delete randomly | 62.93 | 15.89 | 5.86e-4 |
10,000 addMany | 28.70 | 34.84 | 0.00 |
10,000 get | 27.67 | 36.14 | 2.92e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 add randomly | 87.51 | 11.43 | 0.01 |
100,000 add & delete randomly | 189.06 | 5.29 | 0.01 |
100,000 getNode | 35.33 | 28.31 | 8.93e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000 addVertex | 0.10 | 9899.91 | 8.58e-7 |
1,000 addEdge | 6.06 | 165.02 | 1.68e-4 |
1,000 getVertex | 0.05 | 2.17e+4 | 4.22e-7 |
1,000 getEdge | 23.05 | 43.38 | 0.00 |
tarjan | 222.59 | 4.49 | 0.01 |
tarjan all | 226.89 | 4.41 | 0.01 |
topologicalSort | 187.34 | 5.34 | 0.01 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add & pop | 4.66 | 214.54 | 9.38e-5 |
10,000 fib add & pop | 364.30 | 2.74 | 0.01 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 unshift | 243.61 | 4.10 | 0.07 |
1,000,000 unshift & shift | 173.32 | 5.77 | 0.03 |
1,000,000 insertBefore | 315.86 | 3.17 | 0.04 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 push & pop | 228.06 | 4.38 | 0.03 |
10,000 insertBefore | 252.07 | 3.97 | 0.01 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 refill & poll | 11.53 | 86.71 | 2.27e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 227.24 | 4.40 | 0.07 |
1,000,000 shift | 25.60 | 39.07 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 45.98 | 21.75 | 0.01 |
1,000,000 push & shift | 81.12 | 12.33 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 push | 59.40 | 16.83 | 0.01 |
100,000 getWords | 90.07 | 11.10 | 0.00 |