From 3dc0454c24d099b8c5173ec2637932b44f118c13 Mon Sep 17 00:00:00 2001 From: Revone Date: Sat, 25 Nov 2023 22:49:54 +0800 Subject: [PATCH] docs: Integration tests and documentation for free conversion between data structures. --- README.md | 71 ++++++++++++++++++++++++++++++ package.json | 2 +- test/integration/index.html | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index deae4ba..23ae822 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 05c2ab1..bae6d62 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/integration/index.html b/test/integration/index.html index 097a5d7..eedb362 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -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); + }