test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 51.22 | 19.52 | 0.00 |
10,000 add & delete randomly | 110.40 | 9.06 | 0.00 |
10,000 addMany | 58.39 | 17.13 | 6.35e-4 |
10,000 get | 50.59 | 19.77 | 3.87e-4 |
# data-structure-typed ![npm](https://img.shields.io/npm/v/data-structure-typed) ![npm](https://img.shields.io/npm/dm/data-structure-typed) ![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/data-structure-typed) ![GitHub top language](https://img.shields.io/github/languages/top/zrwusa/data-structure-typed) ![eslint](https://aleen42.github.io/badges/src/eslint.svg) ![NPM](https://img.shields.io/npm/l/data-structure-typed) [//]: # (![npm bundle size](https://img.shields.io/bundlephobia/min/data-structure-typed))
## Why Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL. **`API standards`** aligned with ES6 and Java. **`Usability`** is comparable to Python ### We provide data structures that are not available in JS/TS Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, Directed Graph, Undirected Graph, BST, AVL Tree, Priority Queue, Queue, Tree Multiset, Linked List. ### Performance superior to native JS/TS **`Queue vs. native Array, 100,000 scale`**Test Methods | Time Taken (ms) |
---|---|
Queue push & shift | 5.83 |
Array push & shift | 2829.59 |
Test Methods | Time Taken (ms) |
---|---|
Deque unshift & shift | 2.44 |
Array unshift & shift | 4750.37 |
Method | Time Taken (ms) |
---|---|
HashMap 1,000,000 set | 122.51 |
Native Map 1,000,000 set | 223.80 |
Native Set 1,000,000 add | 185.06 |
Data Structure | Unit Test | Performance Test | API Docs |
---|---|---|---|
Binary Tree | View | ||
Binary Search Tree (BST) | View | ||
AVL Tree | View | ||
Red Black Tree | View | ||
Tree Multimap | View | ||
Heap | View | ||
Priority Queue | View | ||
Max Priority Queue | View | ||
Min Priority Queue | View | ||
Trie | View | ||
Graph | View | ||
Directed Graph | View | ||
Undirected Graph | View | ||
Queue | View | ||
Deque | View | ||
Hash Map | View | ||
Linked List | View | ||
Singly Linked List | View | ||
Doubly Linked List | View | ||
Stack | View | ||
Segment Tree | View | ||
Binary Indexed Tree | View |
Data Structure Typed | C++ STL | java.util | Python collections |
---|---|---|---|
Heap<E> | priority_queue<T> | PriorityQueue<E> | heapq |
Deque<E> | deque<T> | ArrayDeque<E> | deque |
Queue<E> | queue<T> | Queue<E> | - |
HashMap<K, V> | unordered_map<K, V> | HashMap<K, V> | defaultdict |
DoublyLinkedList<E> | list<T> | LinkedList<E> | - |
SinglyLinkedList<E> | - | - | - |
BinaryTree<K, V> | - | - | - |
BST<K, V> | - | - | - |
RedBlackTree<E> | set<T> | TreeSet<E> | - |
RedBlackTree<K, V> | map<K, V> | TreeMap<K, V> | - |
TreeMultimap<K, V> | multimap<K, V> | - | - |
TreeMultimap<E> | multiset<T> | - | - |
Trie | - | - | - |
DirectedGraph<V, E> | - | - | - |
UndirectedGraph<V, E> | - | - | - |
PriorityQueue<E> | priority_queue<T> | PriorityQueue<E> | - |
Array<E> | vector<T> | ArrayList<E> | list |
Stack<E> | stack<T> | Stack<E> | - |
HashMap<E> | unordered_set<T> | HashSet<E> | set |
- | unordered_multiset | - | Counter |
LinkedHashMap<K, V> | - | LinkedHashMap<K, V> | OrderedDict |
- | unordered_multimap<K, V> | - | - |
- | bitset<N> | - | - |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 51.22 | 19.52 | 0.00 |
10,000 add & delete randomly | 110.40 | 9.06 | 0.00 |
10,000 addMany | 58.39 | 17.13 | 6.35e-4 |
10,000 get | 50.59 | 19.77 | 3.87e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000 add randomly | 13.83 | 72.29 | 1.19e-4 |
1,000 add & delete randomly | 21.49 | 46.54 | 2.34e-4 |
1,000 addMany | 15.93 | 62.78 | 1.27e-4 |
1,000 get | 18.19 | 54.98 | 1.79e-4 |
1,000 has | 18.20 | 54.93 | 1.71e-4 |
1,000 dfs | 161.79 | 6.18 | 7.45e-4 |
1,000 bfs | 56.68 | 17.64 | 4.77e-4 |
1,000 morris | 262.64 | 3.81 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 add randomly | 51.51 | 19.41 | 8.70e-4 |
10,000 add & delete randomly | 114.09 | 8.76 | 9.66e-4 |
10,000 addMany | 47.86 | 20.90 | 2.77e-4 |
10,000 get | 51.93 | 19.26 | 6.56e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 add | 86.63 | 11.54 | 0.00 |
100,000 add & delete randomly | 218.88 | 4.57 | 0.01 |
100,000 getNode | 261.16 | 3.83 | 0.00 |
100,000 add & iterator | 117.64 | 8.50 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
SRC PQ 10,000 add | 0.14 | 6949.20 | 1.53e-6 |
CJS PQ 10,000 add | 0.14 | 6943.68 | 1.74e-6 |
MJS PQ 10,000 add | 0.57 | 1758.40 | 6.26e-6 |
SRC PQ 10,000 add & pop | 3.40 | 293.94 | 3.50e-5 |
CJS PQ 10,000 add & pop | 3.42 | 292.69 | 5.34e-5 |
MJS PQ 10,000 add & pop | 3.30 | 303.01 | 3.97e-5 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000 addVertex | 0.10 | 9930.74 | 1.11e-6 |
1,000 addEdge | 6.13 | 163.19 | 1.84e-4 |
1,000 getVertex | 0.05 | 2.15e+4 | 5.00e-7 |
1,000 getEdge | 23.57 | 42.43 | 0.00 |
tarjan | 252.05 | 3.97 | 0.03 |
tarjan all | 221.15 | 4.52 | 0.00 |
topologicalSort | 181.07 | 5.52 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 set | 122.90 | 8.14 | 0.04 |
Native Map 1,000,000 set | 215.97 | 4.63 | 0.02 |
Native Set 1,000,000 add | 179.11 | 5.58 | 0.02 |
1,000,000 set & get | 123.10 | 8.12 | 0.04 |
Native Map 1,000,000 set & get | 271.80 | 3.68 | 0.02 |
Native Set 1,000,000 add & has | 176.65 | 5.66 | 0.02 |
1,000,000 ObjKey set & get | 341.97 | 2.92 | 0.07 |
Native Map 1,000,000 ObjKey set & get | 316.86 | 3.16 | 0.04 |
Native Set 1,000,000 ObjKey add & has | 285.14 | 3.51 | 0.06 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 add & pop | 80.37 | 12.44 | 0.00 |
100,000 add & dfs | 36.20 | 27.63 | 0.00 |
10,000 fib add & pop | 362.24 | 2.76 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 216.09 | 4.63 | 0.06 |
1,000,000 unshift | 220.68 | 4.53 | 0.02 |
1,000,000 unshift & shift | 172.93 | 5.78 | 0.04 |
1,000,000 insertBefore | 332.25 | 3.01 | 0.08 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push & shift | 222.99 | 4.48 | 0.10 |
10,000 push & pop | 214.82 | 4.66 | 0.01 |
10,000 insertBefore | 251.24 | 3.98 | 0.01 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
10,000 refill & poll | 8.91 | 112.19 | 1.57e-4 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 add & pop | 101.70 | 9.83 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 13.80 | 72.47 | 1.56e-4 |
1,000,000 push & pop | 22.72 | 44.02 | 2.02e-4 |
100,000 push & shift | 2.35 | 425.67 | 5.80e-5 |
Native Array 100,000 push & shift | 2511.14 | 0.40 | 0.36 |
100,000 unshift & shift | 2.23 | 447.89 | 3.30e-4 |
Native Array 100,000 unshift & shift | 4140.23 | 0.24 | 0.33 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 43.65 | 22.91 | 0.01 |
100,000 push & shift | 4.99 | 200.28 | 9.54e-5 |
Native Array 100,000 push & shift | 2335.63 | 0.43 | 0.33 |
Native Array 100,000 push & pop | 4.39 | 227.81 | 0.00 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
1,000,000 push | 45.38 | 22.04 | 0.01 |
1,000,000 push & pop | 49.52 | 20.19 | 0.01 |
test name | time taken (ms) | executions per sec | sample deviation |
---|---|---|---|
100,000 push | 42.99 | 23.26 | 0.00 |
100,000 getWords | 89.78 | 11.14 | 0.00 |
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 |
Principle | Description |
---|---|
Practicality | Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names. |
Extensibility | Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures. |
Modularization | Includes data structure modularization and independent NPM packages. |
Efficiency | All methods provide time and space complexity, comparable to native JS performance. |
Maintainability | Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns. |
Testability | Automated and customized unit testing, performance testing, and integration testing. |
Portability | Plans for porting to Java, Python, and C++, currently achieved to 80%. |
Reusability | Fully decoupled, minimized side effects, and adheres to OOP. |
Security | Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects. |
Scalability | Data structure software does not involve load issues. |