diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e2c14..7dc92b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.51.7](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) +## [v1.51.8](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) ## [v1.51.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...v1.51.5) (18 January 2024) diff --git a/README.md b/README.md index ad45276..5b46716 100644 --- a/README.md +++ b/README.md @@ -736,43 +736,43 @@ Version 11.7.9 [//]: # (No deletion!!! Start of Replace Section)
heap
-
test nametime taken (ms)executions per secsample deviation
100,000 add6.42155.781.88e-4
100,000 add & poll31.6031.659.13e-4
+
test nametime taken (ms)executions per secsample deviation
100,000 add6.34157.781.90e-4
100,000 add & poll31.3931.868.18e-4
rb-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add59.2816.877.81e-4
100,000 add randomly71.6113.969.02e-4
100,000 get104.139.600.00
100,000 iterator27.0337.000.00
100,000 add & delete orderly126.427.910.00
100,000 add & delete randomly214.364.660.00
+
test nametime taken (ms)executions per secsample deviation
100,000 add59.6416.770.00
100,000 add randomly73.6713.570.00
100,000 get89.9111.120.00
100,000 iterator26.0838.340.00
100,000 add & delete orderly145.446.880.00
100,000 add & delete randomly204.814.880.00
queue
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push44.9822.230.01
100,000 push & shift4.89204.396.15e-4
Native JS Array 100,000 push & shift2251.130.440.26
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push40.8424.480.00
100,000 push & shift4.83207.165.59e-4
Native JS Array 100,000 push & shift2376.780.420.34
deque
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push22.2145.020.00
1,000,000 push & pop30.9732.290.00
1,000,000 push & shift30.8132.460.00
100,000 push & shift3.24308.252.08e-4
Native JS Array 100,000 push & shift2279.950.440.21
100,000 unshift & shift2.93341.783.21e-4
Native JS Array 100,000 unshift & shift4076.040.250.42
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push24.7340.440.00
1,000,000 push & pop30.0833.240.00
1,000,000 push & shift30.5332.750.00
100,000 push & shift3.19313.763.01e-4
Native JS Array 100,000 push & shift2184.780.460.19
100,000 unshift & shift2.94339.723.66e-4
Native JS Array 100,000 unshift & shift4196.690.240.37
hash-map
-
test nametime taken (ms)executions per secsample deviation
1,000,000 set118.118.470.02
Native JS Map 1,000,000 set206.184.850.01
Native JS Set 1,000,000 add167.505.970.01
1,000,000 set & get116.158.610.01
Native JS Map 1,000,000 set & get269.113.720.02
Native JS Set 1,000,000 add & has168.025.950.01
1,000,000 ObjKey set & get335.362.980.04
Native JS Map 1,000,000 ObjKey set & get327.783.050.06
Native JS Set 1,000,000 ObjKey add & has281.643.550.04
+
test nametime taken (ms)executions per secsample deviation
1,000,000 set117.778.490.03
Native JS Map 1,000,000 set200.534.990.00
Native JS Set 1,000,000 add172.755.790.03
1,000,000 set & get117.618.500.02
Native JS Map 1,000,000 set & get265.243.770.01
Native JS Set 1,000,000 add & has168.615.930.01
1,000,000 ObjKey set & get325.913.070.04
Native JS Map 1,000,000 ObjKey set & get301.513.320.03
Native JS Set 1,000,000 ObjKey add & has274.473.640.04
trie
-
test nametime taken (ms)executions per secsample deviation
100,000 push43.6422.918.01e-4
100,000 getWords82.9512.060.00
+
test nametime taken (ms)executions per secsample deviation
100,000 push42.9323.298.30e-4
100,000 getWords82.1412.170.00
avl-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add263.013.800.02
100,000 add randomly353.892.830.01
100,000 get131.657.600.00
100,000 iterator31.6231.630.01
100,000 add & delete orderly468.812.130.00
100,000 add & delete randomly628.301.590.03
+
test nametime taken (ms)executions per secsample deviation
100,000 add231.624.320.00
100,000 add randomly304.233.290.00
100,000 get113.938.780.00
100,000 iterator30.3732.920.00
100,000 add & delete orderly395.022.530.02
100,000 add & delete randomly542.161.840.00
binary-tree-overall
-
test nametime taken (ms)executions per secsample deviation
10,000 RBTree add randomly5.79172.737.35e-5
10,000 RBTree get randomly9.58104.379.96e-5
10,000 RBTree add & delete randomly17.8256.121.90e-4
10,000 AVLTree add randomly27.8535.913.16e-4
10,000 AVLTree get randomly10.7393.196.38e-5
10,000 AVLTree add & delete randomly48.9820.423.91e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 RBTree add randomly6.02166.109.19e-5
10,000 RBTree get randomly7.96125.617.80e-5
10,000 RBTree add & delete randomly16.6660.021.52e-4
10,000 AVLTree add randomly21.6446.211.93e-4
10,000 AVLTree get randomly8.40119.091.34e-4
10,000 AVLTree add & delete randomly40.8424.492.56e-4
directed-graph
-
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109624.607.61e-7
1,000 addEdge6.02166.181.45e-4
1,000 getVertex0.052.17e+43.52e-7
1,000 getEdge23.8841.880.00
tarjan215.084.650.01
topologicalSort187.835.320.00
+
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109892.748.38e-7
1,000 addEdge6.07164.741.70e-4
1,000 getVertex0.052.13e+42.16e-6
1,000 getEdge38.6625.870.02
tarjan208.114.810.01
topologicalSort184.455.420.02
doubly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push221.694.510.03
1,000,000 unshift227.334.400.07
1,000,000 unshift & shift170.085.880.02
1,000,000 addBefore321.293.110.07
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push218.494.580.04
1,000,000 unshift213.524.680.06
1,000,000 unshift & shift155.826.420.02
1,000,000 addBefore325.793.070.08
singly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push & shift213.144.690.04
10,000 push & pop217.844.590.01
10,000 addBefore250.813.990.01
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push & shift191.945.210.04
10,000 push & pop214.824.660.01
10,000 addBefore247.534.040.00
priority-queue
-
test nametime taken (ms)executions per secsample deviation
100,000 add26.9137.161.96e-4
100,000 add & poll75.0913.325.04e-4
+
test nametime taken (ms)executions per secsample deviation
100,000 add26.6337.561.30e-4
100,000 add & poll76.8213.020.00
stack
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push39.9225.050.01
1,000,000 push & pop48.0820.800.01
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push38.5825.920.00
1,000,000 push & pop46.0621.710.00
[//]: # (No deletion!!! End of Replace Section) diff --git a/package-lock.json b/package-lock.json index 3e0ed04..741d735 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.51.7", + "version": "1.51.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.51.7", + "version": "1.51.8", "license": "MIT", "devDependencies": { "@swc/core": "^1.3.96", @@ -16,11 +16,11 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.51.6", + "avl-tree-typed": "^1.51.7", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.51.6", - "bst-typed": "^1.51.5", - "data-structure-typed": "^1.51.6", + "binary-tree-typed": "^1.51.7", + "bst-typed": "^1.51.7", + "data-structure-typed": "^1.51.7", "dependency-cruiser": "^14.1.0", "doctoc": "^2.2.1", "eslint": "^8.50.0", @@ -29,7 +29,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.51.5", + "heap-typed": "^1.51.7", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "js-sdsl": "^4.4.2", @@ -3097,12 +3097,12 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.51.6", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.51.6.tgz", - "integrity": "sha512-4nUw06qxBXPsjU26yzQo75ehQAGKaT3Tk8ffuFWcK7pwvsE+ZMDg2aD6bif5BZotjcexH9vgAfakEOzUYSwtGA==", + "version": "1.51.7", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.51.7.tgz", + "integrity": "sha512-7ylhTBu3u26sTqTOxp+JiypGc9Rwv6S3eVL2dDDuXFRMIMZR1BUwgjT3VnF3B3EM/cLulVJ6DeEiT13OodZcCA==", "dev": true, "dependencies": { - "data-structure-typed": "^1.51.6" + "data-structure-typed": "^1.51.7" } }, "node_modules/babel-jest": { @@ -3306,12 +3306,12 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.51.6", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.51.6.tgz", - "integrity": "sha512-l/qEKAjYbsYMZUDP5x3Imo477qFUkpJdZR8cKZTEJWor9S+29lCZ7EUHH+60S7jpY3Y+jD11F3N0hCW4u0EnLw==", + "version": "1.51.7", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.51.7.tgz", + "integrity": "sha512-oYFgefTymWz2N2dbTJYGkJXCjai7whlUaonfjVImqYElx41v7vcP2rAt+CxUcwUJdKRNDI70UtWpmpDd1pESrg==", "dev": true, "dependencies": { - "data-structure-typed": "^1.51.6" + "data-structure-typed": "^1.51.7" } }, "node_modules/brace-expansion": { @@ -3390,12 +3390,12 @@ } }, "node_modules/bst-typed": { - "version": "1.51.5", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.51.5.tgz", - "integrity": "sha512-HmpA3D4WmPBcWIbJMSTJ2wLPwwfl9ulNXJyuSIYGFLZoTa9+g1oA4HRL43IUnBCLgVWSXsq7Bhc/Jp1jvN/84w==", + "version": "1.51.7", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.51.7.tgz", + "integrity": "sha512-PoYbsvbyndqhwVwDx3AzATPaRo0KGm8mxapz0oonv7Ahg0RoAvOAL3w8+LxioGNFI9rfbYnDL33IjdxFyDpWew==", "dev": true, "dependencies": { - "data-structure-typed": "^1.51.5" + "data-structure-typed": "^1.51.7" } }, "node_modules/buffer-from": { @@ -3838,9 +3838,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.51.6", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.51.6.tgz", - "integrity": "sha512-yGWn77EAQWkg2LbegmpTrgk1Vf2RjY6y17ePTPXOCTkxLYBPrV0jS7MFUDYRuSMSRohSSnoM/3GZuzMcc1iXOw==", + "version": "1.51.7", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.51.7.tgz", + "integrity": "sha512-JiR6SYZi0hgojPdojTLGeSHzLL/v0ppIqzB168FGWje6dUbS1P4+/80T6cFPukjIfatHvnm+7L3Z11E4XXSUdg==", "dev": true }, "node_modules/debug": { @@ -5363,12 +5363,12 @@ } }, "node_modules/heap-typed": { - "version": "1.51.5", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.51.5.tgz", - "integrity": "sha512-mCD9etfviFYdbDEkXJWTyKVX7f2LPRCQHHLjo+VOsE+IBJRTScuNIJKSD+HKZOntNBCWW0VWdc+ZzkXEKU2mhw==", + "version": "1.51.7", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.51.7.tgz", + "integrity": "sha512-afq4w+3kDff5Axdt4ZsS4tTMKFb7sCRblk0+8vmGRNQcJ8wHnZIdTEmXmHY5xVLq/84lSayMgct7hyKp8II0LA==", "dev": true, "dependencies": { - "data-structure-typed": "^1.51.5" + "data-structure-typed": "^1.51.7" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index 8cd1523..ed65148 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.51.7", + "version": "1.51.8", "description": "Javascript Data Structure. Heap, Binary Tree, Red Black 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. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", @@ -66,11 +66,11 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.51.6", + "avl-tree-typed": "^1.51.7", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.51.6", - "bst-typed": "^1.51.5", - "data-structure-typed": "^1.51.6", + "binary-tree-typed": "^1.51.7", + "bst-typed": "^1.51.7", + "data-structure-typed": "^1.51.7", "dependency-cruiser": "^14.1.0", "doctoc": "^2.2.1", "eslint": "^8.50.0", @@ -79,7 +79,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.51.5", + "heap-typed": "^1.51.7", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "js-sdsl": "^4.4.2", diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index fb756c3..44a39a2 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -149,7 +149,7 @@ export class BinaryTree< * `Partial`, which means that not all properties of `BinaryTreeOptions` are * required. */ - constructor(keysOrNodesOrEntries: Iterable> = [], options?: BinaryTreeOptions) { + constructor(keysOrNodesOrEntries: Iterable> = [], options?: BinaryTreeOptions) { super(); if (options) { const { iterationType } = options; @@ -209,7 +209,7 @@ export class BinaryTree< * you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface. * @returns a new instance of a binary tree. */ - createTree(options?: Partial>): TREE { + createTree(options?: Partial): TREE { return new BinaryTree([], { iterationType: this.iterationType, ...options }) as TREE; } @@ -1831,10 +1831,10 @@ export class BinaryTree< console.log(`U for undefined `); if (opts.isShowNull) - console.log(`NODE for null + console.log(`N for null `); if (opts.isShowRedBlackNIL) - console.log(`S for Sentinel Node + console.log(`S for Sentinel Node(NIL) `); const display = (root: NODE | null | undefined): void => { diff --git a/src/interfaces/binary-tree.ts b/src/interfaces/binary-tree.ts index 5dba15f..1f6ec3d 100644 --- a/src/interfaces/binary-tree.ts +++ b/src/interfaces/binary-tree.ts @@ -17,7 +17,7 @@ export interface IBinaryTree< > { createNode(key: K, value?: N['value']): N; - createTree(options?: Partial>): TREE; + createTree(options?: Partial): TREE; add(keyOrNodeOrEntry: KeyOrNodeOrEntry, value?: V, count?: number): boolean; diff --git a/src/types/data-structures/binary-tree/binary-tree.ts b/src/types/data-structures/binary-tree/binary-tree.ts index 88c70f5..8fc595f 100644 --- a/src/types/data-structures/binary-tree/binary-tree.ts +++ b/src/types/data-structures/binary-tree/binary-tree.ts @@ -6,6 +6,6 @@ export type BinaryTreeNodeNested = BinaryTreeNode> = BinaryTree>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -export type BinaryTreeOptions = { +export type BinaryTreeOptions = { iterationType?: IterationType } diff --git a/src/types/data-structures/binary-tree/bst.ts b/src/types/data-structures/binary-tree/bst.ts index 72e47ab..b6112a6 100644 --- a/src/types/data-structures/binary-tree/bst.ts +++ b/src/types/data-structures/binary-tree/bst.ts @@ -7,6 +7,6 @@ export type BSTNodeNested = BSTNode> = BST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -export type BSTOptions = BinaryTreeOptions & { +export type BSTOptions = BinaryTreeOptions & { comparator?: Comparator } diff --git a/test/integration/all-in-one.test.ts b/test/integration/all-in-one.test.ts index d5a4398..7baf79b 100644 --- a/test/integration/all-in-one.test.ts +++ b/test/integration/all-in-one.test.ts @@ -27,7 +27,7 @@ describe('AVL Tree Test from data-structure-typed', () => { expect(subTreeSum).toBe(70); let lesserSum = 0; - tree.lesserOrGreaterTraverse(node => (lesserSum += node.key), 'LT', 10); + tree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10); expect(lesserSum).toBe(45); // node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class. diff --git a/test/integration/avl-tree.test.ts b/test/integration/avl-tree.test.ts index 082824e..09af032 100644 --- a/test/integration/avl-tree.test.ts +++ b/test/integration/avl-tree.test.ts @@ -44,7 +44,7 @@ describe('AVL Tree Test', () => { expect(subTreeSum).toBe(70); let lesserSum = 0; - tree.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10); + tree.lesserOrGreaterTraverse(node => (lesserSum += node.key), 'LT', 10); expect(lesserSum).toBe(45); // node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class. diff --git a/test/integration/bst.test.ts b/test/integration/bst.test.ts index 55f1ba3..61c915a 100644 --- a/test/integration/bst.test.ts +++ b/test/integration/bst.test.ts @@ -38,7 +38,7 @@ describe('Individual package BST operations test', () => { expect(subTreeSum).toBe(70); let lesserSum = 0; - bst.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10); + bst.lesserOrGreaterTraverse(node => (lesserSum += node.key), 'LT', 10); expect(lesserSum).toBe(45); expect(node15).toBeInstanceOf(BSTNode); @@ -235,7 +235,7 @@ describe('Individual package BST operations test', () => { expect(subTreeSum).toBe(70); let lesserSum = 0; - objBST.lesserOrGreaterTraverse(node => (lesserSum += node.key), -1, 10); + objBST.lesserOrGreaterTraverse(node => (lesserSum += node.key), 'LT', 10); expect(lesserSum).toBe(45); expect(node15).toBeInstanceOf(BSTNode); diff --git a/test/performance/reportor.ts b/test/performance/reportor.ts index 9e765a5..6d32008 100644 --- a/test/performance/reportor.ts +++ b/test/performance/reportor.ts @@ -2,13 +2,12 @@ import * as Benchmark from 'benchmark'; import * as path from 'path'; import * as fs from 'fs'; import * as fastGlob from 'fast-glob'; -import { Color, numberFix, render } from '../utils'; +import { ConsoleColor, numberFix, render } from '../utils'; import { PerformanceTest } from './types'; -import * as console from 'console'; const args = process.argv.slice(2); -const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = Color; +const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = ConsoleColor; const getRelativePath = (file: string) => { return path.relative(__dirname, file); diff --git a/test/utils/console.ts b/test/utils/console.ts index ff1fc72..460e526 100644 --- a/test/utils/console.ts +++ b/test/utils/console.ts @@ -1,4 +1,4 @@ -export const Color = { +export const ConsoleColor = { END: '\x1b[0m', BOLD: '\x1b[1m', DIM: '\x1b[2m',