Skip to content

Commit

Permalink
docs: Integration tests and documentation for free conversion between…
Browse files Browse the repository at this point in the history
… data structures.
  • Loading branch information
zrwusa committed Nov 25, 2023
1 parent 982152a commit 3dc0454
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 1 deletion.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,77 @@ graph.addEdge('B', 'D');

const dijkstraResult = graph.dijkstra('A');
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', 'D']


```
### Free conversion between data structures.
```js
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];

const queue = new Queue(orgArr);
queue.print();

const deque = new Deque(orgArr);
deque.print();

const sList = new SinglyLinkedList(orgArr);
sList.print();

const dList = new DoublyLinkedList(orgArr);
dList.print();

const stack = new Stack(orgArr);
stack.print();

const minHeap = new MinHeap(orgArr);
minHeap.print();

const maxPQ = new MaxPriorityQueue(orgArr);
maxPQ.print();

const biTree = new BinaryTree(entries);
biTree.print();

const bst = new BST(entries);
bst.print();

const rbTree = new RedBlackTree(entries);
rbTree.print();

const avl = new AVLTree(entries);
avl.print();

const treeMulti = new TreeMultimap(entries);
treeMulti.print();

const hm = new HashMap(entries);
hm.print()
const rbTreeH = new RedBlackTree(hm);
rbTreeH.print();

const pq = new MinPriorityQueue(orgArr);
pq.print();
const bst1 = new BST(pq);
bst1.print();

const dq1 = new Deque(orgArr);
dq1.print();
const rbTree1 = new RedBlackTree(dq1);
rbTree1.print();

const trie2 = new Trie(orgStrArr);
trie2.print();
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
heap2.print();
const dq2 = new Deque(heap2);
dq2.print();
const entries2 = dq2.map((el, i) => [i, el]);
const avl2 = new AVLTree(entries2);
avl2.print();
```
## API docs & Examples
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.47.6",
"version": "1.47.7",
"description": "Data Structures of Javascript & TypeScript. Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack.",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
87 changes: 87 additions & 0 deletions test/integration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,93 @@
} catch (e) {
console.error(e);
}

try {
const {
AVLTree,
BinaryTree,
BST,
Deque,
DoublyLinkedList,
HashMap,
Heap,
MaxPriorityQueue,
MinHeap,
MinPriorityQueue,
Queue,
RedBlackTree,
SinglyLinkedList,
Stack,
TreeMultimap,
Trie
} = dataStructureTyped;
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];

const queue = new Queue(orgArr);
queue.print();

const deque = new Deque(orgArr);
deque.print();

const sList = new SinglyLinkedList(orgArr);
sList.print();

const dList = new DoublyLinkedList(orgArr);
dList.print();

const stack = new Stack(orgArr);
stack.print();

const minHeap = new MinHeap(orgArr);
minHeap.print();

const maxPQ = new MaxPriorityQueue(orgArr);
maxPQ.print();

const biTree = new BinaryTree(entries);
biTree.print();

const bst = new BST(entries);
bst.print();

const rbTree = new RedBlackTree(entries);
rbTree.print();

const avl = new AVLTree(entries);
avl.print();

const treeMulti = new TreeMultimap(entries);
treeMulti.print();

const hm = new HashMap(entries);
hm.print()
const rbTreeH = new RedBlackTree(hm);
rbTreeH.print();

const pq = new MinPriorityQueue(orgArr);
pq.print();
const bst1 = new BST(pq);
bst1.print();

const dq1 = new Deque(orgArr);
dq1.print();
const rbTree1 = new RedBlackTree(dq1);
rbTree1.print();

const trie2 = new Trie(orgStrArr);
trie2.print();
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
heap2.print();
const dq2 = new Deque(heap2);
dq2.print();
const entries2 = dq2.map((el, i) => [i, el]);
const avl2 = new AVLTree(entries2);
avl2.print();
} catch (e) {
console.error(e);
}
</script>

</body>
Expand Down

0 comments on commit 3dc0454

Please sign in to comment.