From 64faf186eefd8eff11842bfccbf4b46b513a667b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 2 Jan 2024 19:46:38 +0100 Subject: [PATCH 01/35] feat: add ESM support for default exports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.d.ts | 4 +--- index.js | 4 ++-- index.mjs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++++++++---- 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 index.mjs diff --git a/index.d.ts b/index.d.ts index abaef492..fd2581d6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,8 +4,6 @@ * * Gathering the library's typings. */ -import * as set from './set'; - export {default as BiMap, InverseMap} from './bi-map'; export {default as BitSet} from './bit-set'; export {default as BitVector} from './bit-vector'; @@ -33,7 +31,7 @@ export {default as MultiMap} from './multi-map'; export {default as MultiSet} from './multi-set'; export {default as PassjoinIndex} from './passjoin-index'; export {default as Queue} from './queue'; -export {set}; +export * from './set'; export {default as SparseQueueSet} from './sparse-queue-set'; export {default as SparseMap} from './sparse-map'; export {default as SparseSet} from './sparse-set'; diff --git a/index.js b/index.js index 75bf74e9..649faf6e 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ /** - * Mnemonist Library Endpoint - * =========================== + * Mnemonist Library Endpoint (CommonJS) + * ===================================== * * Exporting every data structure through a unified endpoint. Consumers * of this library should prefer the modular access though. diff --git a/index.mjs b/index.mjs new file mode 100644 index 00000000..2cfbfe1a --- /dev/null +++ b/index.mjs @@ -0,0 +1,46 @@ +/** + * Mnemonist Library Endpoint (ESM) + * ================================ + * + * Exporting every data structure through a unified endpoint. + */ +export {default as BiMap} from './bi-map.js'; +export {default as BitSet} from './bit-set.js'; +export {default as BitVector} from './bit-vector.js'; +export {default as BloomFilter} from './bloom-filter.js'; +export {default as BKTree} from './bk-tree.js'; +export {default as CircularBuffer} from './circular-buffer.js'; +export {default as DefaultMap} from './default-map.js'; +export {default as DefaultWeakMap} from './default-weak-map.js'; +export {default as FixedDeque} from './fixed-deque.js'; +export {default as StaticDisjointSet} from './static-disjoint-set.js'; +export {default as FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap} from './fibonacci-heap.js'; +export {default as FixedReverseHeap} from './fixed-reverse-heap.js'; +export {default as FuzzyMap} from './fuzzy-map.js'; +export {default as FuzzyMultiMap} from './fuzzy-multi-map.js'; +export {default as HashedArrayTree} from './hashed-array-tree.js'; +export {default as Heap, MinHeap, MaxHeap} from './heap.js'; +export {default as StaticIntervalTree} from './static-interval-tree.js'; +export {default as InvertedIndex} from './inverted-index.js'; +export {default as KDTree} from './kd-tree.js'; +export {default as LinkedList} from './linked-list.js'; +export {default as LRUCache} from './lru-cache.js'; +export {default as LRUCacheWithDelete} from './lru-cache-with-delete.js'; +export {default as LRUMap} from './lru-map.js'; +export {default as LRUMapWithDelete} from './lru-map-with-delete.js'; +export {default as MultiMap} from './multi-map.js'; +export {default as MultiSet} from './multi-set.js'; +export {default as PassjoinIndex} from './passjoin-index.js'; +export {default as Queue} from './queue.js'; +export {default as FixedStack} from './fixed-stack.js'; +export {default as Stack} from './stack.js'; +export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array.js'; +export * from './set.js'; +export {default as SparseQueueSet} from './sparse-queue-set.js'; +export {default as SparseMap} from './sparse-map.js'; +export {default as SparseSet} from './sparse-set.js'; +export {default as SymSpell} from './symspell.js'; +export {default as Trie} from './trie.js'; +export {default as TrieMap} from './trie-map.js'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Array} from './vector.js'; +export {default as VPTree} from './vp-tree.js'; diff --git a/package.json b/package.json index 75d25af4..358f6168 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,27 @@ "version": "0.39.7", "description": "Curated collection of data structures for the JavaScript/TypeScript.", "scripts": { - "lint": "eslint --cache ./*.js ./utils ./test", - "lint:fix": "eslint --cache --fix ./*.js ./utils ./test", + "lint": "eslint --cache ./*.js ./*.mjs ./utils ./test", + "lint:fix": "eslint --cache --fix ./*.js ./*.mjs ./utils ./test", "prepublishOnly": "npm run lint && npm test && npm run test:types", "test": "mocha", "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" }, "main": "./index.js", "types": "./index.d.ts", + "exports": { + ".": { + "types": "./index.d.ts", + "require": "./index.js", + "import": "./index.mjs" + } + }, "files": [ "sort", "utils", "*.d.ts", - "*.js" + "*.js", + "*.mjs" ], "repository": { "type": "git", @@ -95,7 +103,8 @@ "ecmaVersion": 6, "ecmaFeatures": { "forOf": true - } + }, + "sourceType": "module" }, "rules": { "no-new": 0 From 7f1890a317460c85a2952e00e6ad884a43e3339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 2 Jan 2024 20:03:24 +0100 Subject: [PATCH 02/35] fix: fix set ops exports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.d.ts | 4 +++- index.mjs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index fd2581d6..abaef492 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,6 +4,8 @@ * * Gathering the library's typings. */ +import * as set from './set'; + export {default as BiMap, InverseMap} from './bi-map'; export {default as BitSet} from './bit-set'; export {default as BitVector} from './bit-vector'; @@ -31,7 +33,7 @@ export {default as MultiMap} from './multi-map'; export {default as MultiSet} from './multi-set'; export {default as PassjoinIndex} from './passjoin-index'; export {default as Queue} from './queue'; -export * from './set'; +export {set}; export {default as SparseQueueSet} from './sparse-queue-set'; export {default as SparseMap} from './sparse-map'; export {default as SparseSet} from './sparse-set'; diff --git a/index.mjs b/index.mjs index 2cfbfe1a..7fd7ac83 100644 --- a/index.mjs +++ b/index.mjs @@ -4,6 +4,8 @@ * * Exporting every data structure through a unified endpoint. */ +import * as set from './set.js'; + export {default as BiMap} from './bi-map.js'; export {default as BitSet} from './bit-set.js'; export {default as BitVector} from './bit-vector.js'; @@ -35,7 +37,7 @@ export {default as Queue} from './queue.js'; export {default as FixedStack} from './fixed-stack.js'; export {default as Stack} from './stack.js'; export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array.js'; -export * from './set.js'; +export {set}; export {default as SparseQueueSet} from './sparse-queue-set.js'; export {default as SparseMap} from './sparse-map.js'; export {default as SparseSet} from './sparse-set.js'; From 0dcfb1d49634a0937ebca619bb78f8861b31e857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 2 Jan 2024 20:10:18 +0100 Subject: [PATCH 03/35] fix: add missing export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.js | 6 ++++-- index.mjs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 649faf6e..5b0c7854 100644 --- a/index.js +++ b/index.js @@ -7,10 +7,12 @@ */ var Heap = require('./heap.js'), FibonacciHeap = require('./fibonacci-heap.js'), - SuffixArray = require('./suffix-array.js'); + SuffixArray = require('./suffix-array.js'), + BiMap = require('./bi-map.js'); module.exports = { - BiMap: require('./bi-map.js'), + BiMap: BiMap, + InverseMap: BiMap.InverseMap, BitSet: require('./bit-set.js'), BitVector: require('./bit-vector.js'), BloomFilter: require('./bloom-filter.js'), diff --git a/index.mjs b/index.mjs index 7fd7ac83..20ba210f 100644 --- a/index.mjs +++ b/index.mjs @@ -6,7 +6,7 @@ */ import * as set from './set.js'; -export {default as BiMap} from './bi-map.js'; +export {default as BiMap, InverseMap} from './bi-map.js'; export {default as BitSet} from './bit-set.js'; export {default as BitVector} from './bit-vector.js'; export {default as BloomFilter} from './bloom-filter.js'; From 90213ff800d1b85b92495b946c778d193678f121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 3 Jan 2024 19:09:56 +0100 Subject: [PATCH 04/35] fix: add missing module field in package.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 358f6168..65580908 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" }, "main": "./index.js", + "module": "./index.mjs", "types": "./index.d.ts", "exports": { ".": { From 2e442de3561dbf9f16d95cc2deea0b6ee3b1be19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 8 Jan 2024 21:52:08 +0100 Subject: [PATCH 05/35] test: add initial ESM and CommonJS import infrastructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.js | 2 +- package.json | 2 + test/cjs/.gitignore | 1 + test/cjs/package.json | 8 ++ test/cjs/require.js | 318 ++++++++++++++++++++++++++++++++++++++++++ test/esm/.gitignore | 1 + test/esm/import.mjs | 318 ++++++++++++++++++++++++++++++++++++++++++ test/esm/package.json | 9 ++ test/types.ts | 1 - 9 files changed, 658 insertions(+), 2 deletions(-) create mode 100644 test/cjs/.gitignore create mode 100644 test/cjs/package.json create mode 100644 test/cjs/require.js create mode 100644 test/esm/.gitignore create mode 100644 test/esm/import.mjs create mode 100644 test/esm/package.json diff --git a/index.js b/index.js index 5b0c7854..9b43b873 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ module.exports = { Stack: require('./stack.js'), SuffixArray: SuffixArray, GeneralizedSuffixArray: SuffixArray.GeneralizedSuffixArray, - Set: require('./set.js'), + set: require('./set.js'), SparseQueueSet: require('./sparse-queue-set.js'), SparseMap: require('./sparse-map.js'), SparseSet: require('./sparse-set.js'), diff --git a/package.json b/package.json index 65580908..685ba6b9 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "lint:fix": "eslint --cache --fix ./*.js ./*.mjs ./utils ./test", "prepublishOnly": "npm run lint && npm test && npm run test:types", "test": "mocha", + "test:cjs": "cd test/cjs && npm i && node require.js", + "test:esm": "cd test/esm && npm i && node import.mjs", "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" }, "main": "./index.js", diff --git a/test/cjs/.gitignore b/test/cjs/.gitignore new file mode 100644 index 00000000..d8b83df9 --- /dev/null +++ b/test/cjs/.gitignore @@ -0,0 +1 @@ +package-lock.json diff --git a/test/cjs/package.json b/test/cjs/package.json new file mode 100644 index 00000000..5241c165 --- /dev/null +++ b/test/cjs/package.json @@ -0,0 +1,8 @@ +{ + "name": "", + "description": "", + "version": "0.1.0", + "dependencies": { + "mnemonist": "file:../.." + } +} diff --git a/test/cjs/require.js b/test/cjs/require.js new file mode 100644 index 00000000..3f47cb20 --- /dev/null +++ b/test/cjs/require.js @@ -0,0 +1,318 @@ +/** + * Mnemonist ESM Import Testing + * ======================== + */ +const { + BiMap, InverseMap, + BitSet, + BitVector, + BKTree, + BloomFilter, + CircularBuffer, + DefaultMap, + FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap, + FixedReverseHeap, + FixedStack, + FuzzyMap, + FuzzyMultiMap, + HashedArrayTree, + Heap, MaxHeap, + InvertedIndex, + LinkedList, + LRUCache, + LRUCacheWithDelete, + LRUMap, + LRUMapWithDelete, + MultiSet, + MultiMap, + PassjoinIndex, + Queue, + set, + SparseSet, + Stack, + StaticDisjointSet, + StaticIntervalTree, + SuffixArray, GeneralizedSuffixArray, + SymSpell, + Trie, + TrieMap, + Vector, Uint16Vector, + VPTree +} = require('mnemonist'); + +/** + * BiMap. + */ +let bimap = new BiMap(); +bimap.set('one', 1); +let inversemap = bimap.inverse; +inversemap.get(1); + +/** + * BitSet. + */ +let bitset = new BitSet(4); +bitset.set(3); + +/** + * BitVector. + */ +let bitvector = new BitVector({initialCapacity: 34}); +bitvector.set(3); + +/** + * BKTree. + */ +let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); +bktree.search(2, 'three'); + +/** + * BloomFilter. + */ +let bloomfilter = new BloomFilter(45); +bloomfilter.add('hello'); + +/** + * CircularBuffer. + */ +let circularbuffer = new CircularBuffer(Array, 4); +circularbuffer.push('test'); + +/** + * DefaultMap. + */ +let defaultMap = new DefaultMap(() => []); +defaultMap.get('one').push(1); + +/** + * FibonacciHeap. + */ +let fibonacciHeap = new FibonacciHeap(); +fibonacciHeap.push('hello'); +fibonacciHeap.pop(); + +/** + * FixedReverseHeap. + */ +let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); +fixedReverseHeap.push(34); + +/** + * FixedStack. + */ +let fixedStack = new FixedStack(Uint8Array, 4); +fixedStack.push(4); +fixedStack.pop(); + +/** + * FuzzyMap. + */ +let fuzzymap = new FuzzyMap(o => o.title); +fuzzymap.set({title: 'Hello'}, 45); +let fuzzymapadd = new FuzzyMap(o => o.n); +fuzzymapadd.add({title: 'Hello', n: 45}); + +/** + * FuzzyMultiMap. + */ +let fuzzymultimap = new FuzzyMultiMap(o => o.title); +fuzzymultimap.set({title: 'Hello'}, 45); +let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); +fuzzymultimapadd.add({title: 'Hello', n: 45}); + +/** + * HashedArrayTree. + */ +let hashedArrayTree = new HashedArrayTree(Int8Array, 34); +hashedArrayTree.set(3, 4); + +/** + * Heap. + */ +let heap = new Heap((a, b) => +a - +b); +heap.push('hello'); +heap.pop(); + +let maxHeap = new Heap(); +maxHeap.push(45); + +/** + * InvertedIndex. + */ +let invertedIndex = new InvertedIndex(n => ['one', 'two']); +invertedIndex.add(45); + +/** + * LinkedList. + */ +let linkedlist = new LinkedList(); +linkedlist.push(true); +let linkedlistItem = linkedlist.shift(); + +/** + * LRUCache. + */ +let lrucache = new LRUCache(10); +lrucache.set('one', 34); +let lrucacheItem = lrucache.get('one'); + +/** + * LRUCacheWithDelete + */ +let lrucwd = new LRUCacheWithDelete(10); +lrucwd.set('one', 'uno'); +let lrucwdItem = lrucwd.get('one'); +lrucwdItem = lrucwd.remove('one'); +let lrucwdDead = lrucwd.remove('one', null); +let lrucwdWasRemoved = lrucwd.delete('one'); + +/** + * LRUMap. + */ +let lrumap = new LRUMap(10); +lrumap.set('one', 34); +let lrumapItem = lrumap.get('one'); + +/** + * LRUMapWithDelete + */ +let lrumwd = new LRUMapWithDelete(10); +lrumwd.set('one', 'uno'); +let lrumwdItem = lrumwd.get('one'); +lrumwdItem = lrumwd.remove('one'); +let lrumwdDead = lrumwd.remove('one', null); +let lrumwdWasRemoved = lrumwd.delete('one'); + +/** + * MultiSet. + */ +let multiset = new MultiSet(); +multiset.add(45); +multiset = MultiSet.from([1, 2, 3]); +multiset = MultiSet.from({'one': 1}); + +/** + * MultiMap. + */ +let multimap = new MultiMap(Set); +multimap.set(45, 'test'); +multimap.get(45).has('test'); +let stringMultimap = MultiMap.from({one: 1}); +stringMultimap.get('one').indexOf(1); +for (const _ of multimap) { } +for (const _ of multimap.keys()) { } +for (const _ of multimap.values()) { } +for (const _ of multimap.entries()) { } +for (const _ of multimap.containers()) { } +for (const _ of multimap.associations()) { } + +/** + * PassjoinIndex. + */ +const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); + +let passjoinResults = passjoinIndex.search('hello'); + +/** + * Queue. + */ +let queue = new Queue(); + +queue.enqueue(45); +let queueitem = queue.dequeue(); + +queue.enqueue(45); +queue.enqueue(34); + +queue = Queue.from([1, 2, 3]); +queue = Queue.from({0: 1}); + +let queueIterator = queue.values(); + +/** + * set. + */ +let setA = new Set([1, 2, 3]); +let setB = new Set([3, 4, 5]); +let unionOfSets = set.union(setA, setB); + +/** + * SparseSet. + */ +let sparseSet = new SparseSet(45); +sparseSet.add(3); + +/** + * Stack. + */ +let stack = new Stack(); + +stack.push(45); +let stackitem = stack.pop(); + +stack.push(45); +stack.push(34); + +stack = Stack.from([1, 2, 3]); +stack = Stack.from({0: 1}); + +let stackIterator = stack.values(); + +/** + * StaticDisjointSet. + */ +let disjointSet = new StaticDisjointSet(45); +disjointSet.union(3, 5); + +/** + * StaticIntervalTree. + */ +let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); + +/** + * SuffixArray. + */ +let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); + +/** + * SymSpell. + */ +let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); +let symspellMatches = symspell.search('three'); + +/** + * Trie. + */ +let trie = new Trie(); +trie.add('roman'); + +let trieMatches = trie.find('rom'); + +/** + * TrieMap. + */ +let trieMap = new TrieMap(); +trieMap.set('roman', 45); + +let trieMapMatches = trieMap.find('rom'); + +trieMap = TrieMap.from(new Map([['roman', 45]])); +trieMap = TrieMap.from({roman: 45}); + +let arrayTrieMap = new TrieMap(Array); +arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); + +/** + * Vector. + */ +let vector = new Vector(Uint32Array, 10); +vector.set(45, 2); + +let uint16vector = Uint16Vector.from([1, 2, 3]); +uint16vector.pop(); + +/** + * VPTree. + */ +let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/esm/.gitignore b/test/esm/.gitignore new file mode 100644 index 00000000..d8b83df9 --- /dev/null +++ b/test/esm/.gitignore @@ -0,0 +1 @@ +package-lock.json diff --git a/test/esm/import.mjs b/test/esm/import.mjs new file mode 100644 index 00000000..8be7fb6b --- /dev/null +++ b/test/esm/import.mjs @@ -0,0 +1,318 @@ +/** + * Mnemonist ESM Import Testing + * ======================== + */ +import { + BiMap, InverseMap, + BitSet, + BitVector, + BKTree, + BloomFilter, + CircularBuffer, + DefaultMap, + FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap, + FixedReverseHeap, + FixedStack, + FuzzyMap, + FuzzyMultiMap, + HashedArrayTree, + Heap, MaxHeap, + InvertedIndex, + LinkedList, + LRUCache, + LRUCacheWithDelete, + LRUMap, + LRUMapWithDelete, + MultiSet, + MultiMap, + PassjoinIndex, + Queue, + set, + SparseSet, + Stack, + StaticDisjointSet, + StaticIntervalTree, + SuffixArray, GeneralizedSuffixArray, + SymSpell, + Trie, + TrieMap, + Vector, Uint16Vector, + VPTree +} from 'mnemonist'; + +/** + * BiMap. + */ +let bimap = new BiMap(); +bimap.set('one', 1); +let inversemap = bimap.inverse; +inversemap.get(1); + +/** + * BitSet. + */ +let bitset = new BitSet(4); +bitset.set(3); + +/** + * BitVector. + */ +let bitvector = new BitVector({initialCapacity: 34}); +bitvector.set(3); + +/** + * BKTree. + */ +let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); +bktree.search(2, 'three'); + +/** + * BloomFilter. + */ +let bloomfilter = new BloomFilter(45); +bloomfilter.add('hello'); + +/** + * CircularBuffer. + */ +let circularbuffer = new CircularBuffer(Array, 4); +circularbuffer.push('test'); + +/** + * DefaultMap. + */ +let defaultMap = new DefaultMap(() => []); +defaultMap.get('one').push(1); + +/** + * FibonacciHeap. + */ +let fibonacciHeap = new FibonacciHeap(); +fibonacciHeap.push('hello'); +fibonacciHeap.pop(); + +/** + * FixedReverseHeap. + */ +let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); +fixedReverseHeap.push(34); + +/** + * FixedStack. + */ +let fixedStack = new FixedStack(Uint8Array, 4); +fixedStack.push(4); +fixedStack.pop(); + +/** + * FuzzyMap. + */ +let fuzzymap = new FuzzyMap(o => o.title); +fuzzymap.set({title: 'Hello'}, 45); +let fuzzymapadd = new FuzzyMap(o => o.n); +fuzzymapadd.add({title: 'Hello', n: 45}); + +/** + * FuzzyMultiMap. + */ +let fuzzymultimap = new FuzzyMultiMap(o => o.title); +fuzzymultimap.set({title: 'Hello'}, 45); +let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); +fuzzymultimapadd.add({title: 'Hello', n: 45}); + +/** + * HashedArrayTree. + */ +let hashedArrayTree = new HashedArrayTree(Int8Array, 34); +hashedArrayTree.set(3, 4); + +/** + * Heap. + */ +let heap = new Heap((a, b) => +a - +b); +heap.push('hello'); +heap.pop(); + +let maxHeap = new Heap(); +maxHeap.push(45); + +/** + * InvertedIndex. + */ +let invertedIndex = new InvertedIndex(n => ['one', 'two']); +invertedIndex.add(45); + +/** + * LinkedList. + */ +let linkedlist = new LinkedList(); +linkedlist.push(true); +let linkedlistItem = linkedlist.shift(); + +/** + * LRUCache. + */ +let lrucache = new LRUCache(10); +lrucache.set('one', 34); +let lrucacheItem = lrucache.get('one'); + +/** + * LRUCacheWithDelete + */ +let lrucwd = new LRUCacheWithDelete(10); +lrucwd.set('one', 'uno'); +let lrucwdItem = lrucwd.get('one'); +lrucwdItem = lrucwd.remove('one'); +let lrucwdDead = lrucwd.remove('one', null); +let lrucwdWasRemoved = lrucwd.delete('one'); + +/** + * LRUMap. + */ +let lrumap = new LRUMap(10); +lrumap.set('one', 34); +let lrumapItem = lrumap.get('one'); + +/** + * LRUMapWithDelete + */ +let lrumwd = new LRUMapWithDelete(10); +lrumwd.set('one', 'uno'); +let lrumwdItem = lrumwd.get('one'); +lrumwdItem = lrumwd.remove('one'); +let lrumwdDead = lrumwd.remove('one', null); +let lrumwdWasRemoved = lrumwd.delete('one'); + +/** + * MultiSet. + */ +let multiset = new MultiSet(); +multiset.add(45); +multiset = MultiSet.from([1, 2, 3]); +multiset = MultiSet.from({'one': 1}); + +/** + * MultiMap. + */ +let multimap = new MultiMap(Set); +multimap.set(45, 'test'); +multimap.get(45).has('test'); +let stringMultimap = MultiMap.from({one: 1}); +stringMultimap.get('one').indexOf(1); +for (const _ of multimap) { } +for (const _ of multimap.keys()) { } +for (const _ of multimap.values()) { } +for (const _ of multimap.entries()) { } +for (const _ of multimap.containers()) { } +for (const _ of multimap.associations()) { } + +/** + * PassjoinIndex. + */ +const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); + +let passjoinResults = passjoinIndex.search('hello'); + +/** + * Queue. + */ +let queue = new Queue(); + +queue.enqueue(45); +let queueitem = queue.dequeue(); + +queue.enqueue(45); +queue.enqueue(34); + +queue = Queue.from([1, 2, 3]); +queue = Queue.from({0: 1}); + +let queueIterator = queue.values(); + +/** + * set. + */ +let setA = new Set([1, 2, 3]); +let setB = new Set([3, 4, 5]); +let unionOfSets = set.union(setA, setB); + +/** + * SparseSet. + */ +let sparseSet = new SparseSet(45); +sparseSet.add(3); + +/** + * Stack. + */ +let stack = new Stack(); + +stack.push(45); +let stackitem = stack.pop(); + +stack.push(45); +stack.push(34); + +stack = Stack.from([1, 2, 3]); +stack = Stack.from({0: 1}); + +let stackIterator = stack.values(); + +/** + * StaticDisjointSet. + */ +let disjointSet = new StaticDisjointSet(45); +disjointSet.union(3, 5); + +/** + * StaticIntervalTree. + */ +let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); + +/** + * SuffixArray. + */ +let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); + +/** + * SymSpell. + */ +let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); +let symspellMatches = symspell.search('three'); + +/** + * Trie. + */ +let trie = new Trie(); +trie.add('roman'); + +let trieMatches = trie.find('rom'); + +/** + * TrieMap. + */ +let trieMap = new TrieMap(); +trieMap.set('roman', 45); + +let trieMapMatches = trieMap.find('rom'); + +trieMap = TrieMap.from(new Map([['roman', 45]])); +trieMap = TrieMap.from({roman: 45}); + +let arrayTrieMap = new TrieMap(Array); +arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); + +/** + * Vector. + */ +let vector = new Vector(Uint32Array, 10); +vector.set(45, 2); + +let uint16vector = Uint16Vector.from([1, 2, 3]); +uint16vector.pop(); + +/** + * VPTree. + */ +let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/esm/package.json b/test/esm/package.json new file mode 100644 index 00000000..abf50c58 --- /dev/null +++ b/test/esm/package.json @@ -0,0 +1,9 @@ +{ + "name": "", + "description": "", + "type": "module", + "version": "0.1.0", + "dependencies": { + "mnemonist": "file:../.." + } +} diff --git a/test/types.ts b/test/types.ts index bb9db9ea..08a42724 100644 --- a/test/types.ts +++ b/test/types.ts @@ -46,7 +46,6 @@ import { let bimap = new BiMap(); bimap.set('one', 1); let inversemap: InverseMap = bimap.inverse; - inversemap.get(1); /** From 3ca8235b94491971b2878fa9276daea338fbe57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 8 Jan 2024 22:41:30 +0100 Subject: [PATCH 06/35] test: make named require test works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmark/interval-tree/performance.js | 2 +- benchmark/misc/dynamic-arrays.js | 2 +- benchmark/misc/hashmap.js | 32 +++++++++++------------ experiments/critbit.js | 6 ++--- index.d.ts | 2 +- index.js | 15 +++++++++-- index.mjs | 2 +- package.json | 6 ++--- test/cjs/{require.js => named-require.js} | 8 +++--- test/esm/import.mjs | 8 +++--- test/types.ts | 6 +++-- vector.d.ts | 2 +- 12 files changed, 54 insertions(+), 37 deletions(-) rename test/cjs/{require.js => named-require.js} (97%) diff --git a/benchmark/interval-tree/performance.js b/benchmark/interval-tree/performance.js index 6f0e0c53..e6acb89f 100644 --- a/benchmark/interval-tree/performance.js +++ b/benchmark/interval-tree/performance.js @@ -22,7 +22,7 @@ console.log('Intervals:', SIZE); console.time('StaticIntervalTree.from'); var tree = StaticIntervalTree.from(INTERVALS); console.timeEnd('StaticIntervalTree.from'); -console.log('Tree height: ' + tree.height) +console.log('Tree height: ' + tree.height); p = random(0, MAX); diff --git a/benchmark/misc/dynamic-arrays.js b/benchmark/misc/dynamic-arrays.js index 5e554827..2c40263c 100644 --- a/benchmark/misc/dynamic-arrays.js +++ b/benchmark/misc/dynamic-arrays.js @@ -1,4 +1,4 @@ -var SIZE = 100000 +var SIZE = 100000; function Wrapper() { this.array = new Float64Array(SIZE); diff --git a/benchmark/misc/hashmap.js b/benchmark/misc/hashmap.js index fa2c0772..271dce58 100644 --- a/benchmark/misc/hashmap.js +++ b/benchmark/misc/hashmap.js @@ -55,21 +55,21 @@ function exponentialSearch(array, key) { return -1; } -function interpolationSearch(arrayToSearch, valueToSearch){ +function interpolationSearch(arrayToSearch, valueToSearch) { var length = arrayToSearch.length; var low = 0; - var high = length-1; + var high = length - 1; var position = -1; var delta = -1; - while(low <= high + while (low <= high && valueToSearch >= arrayToSearch[low] - && valueToSearch <= arrayToSearch[high]){ - delta = (valueToSearch-arrayToSearch[low])/(arrayToSearch[high]-arrayToSearch[low]); - position = low + Math.floor((high-low)*delta); - if (arrayToSearch[position] == valueToSearch){ + && valueToSearch <= arrayToSearch[high]) { + delta = (valueToSearch - arrayToSearch[low]) / (arrayToSearch[high] - arrayToSearch[low]); + position = low + Math.floor((high - low) * delta); + if (arrayToSearch[position] == valueToSearch) { return position; } - if (arrayToSearch[position] < valueToSearch){ + if (arrayToSearch[position] < valueToSearch) { low = position + 1; } else { high = position - 1; @@ -104,7 +104,7 @@ function optimized(array, value, lo, hi) { } return -1; -}; +} function better(array, key) { var mid = -1; @@ -123,7 +123,7 @@ function better(array, key) { else if (key > current) lo = mid + 1; else - return mid + return mid; } return -1; @@ -145,7 +145,7 @@ function PerfectMap(strings) { PerfectMap.prototype.set = function(key, value) { var index = binarySearch(this.hashes, fnv32a(key)); this.values[index] = value; -} +}; PerfectMap.prototype.get = function(key, value) { var index = binarySearch(this.hashes, fnv32a(key)); @@ -159,7 +159,7 @@ var map = new Map(); var sorted = words.slice().sort(); perfect.set('hello', 36); -console.log(perfect.get('hello')) +console.log(perfect.get('hello')); console.time('Perfect set'); for (var i = 0; i < words.length; i++) @@ -217,9 +217,9 @@ function hash(str) { 'use asm'; var h = 5381, - i = str.length; + i = str.length; - while(i) { + while (i) { h *= 33; h ^= str.charCodeAt(--i); } @@ -298,7 +298,7 @@ console.timeEnd('Get'); console.time('GetObject'); for (var w = 0, y = words.length; w < y; w++) - v = ob[words[w]] + v = ob[words[w]]; console.timeEnd('GetObject'); console.time('GetMap'); @@ -313,7 +313,7 @@ console.timeEnd('GetMap'); console.time('MissesObject'); for (var w = 0, y = words.length; w < y; w++) - v = ob[randomString(4, 10)] + v = ob[randomString(4, 10)]; console.timeEnd('MissesObject'); console.time('MissesMap'); diff --git a/experiments/critbit.js b/experiments/critbit.js index a5c57659..bee61f06 100644 --- a/experiments/critbit.js +++ b/experiments/critbit.js @@ -102,7 +102,7 @@ function criticalGt(a, b) { } function InternalNode(critical) { - this.critical = critical + this.critical = critical; this.left = null; this.right = null; } @@ -270,7 +270,7 @@ CritBitTree.prototype.delete = function(key) { var node = this.root, parent = null, - wentRightForParent = false + wentRightForParent = false; grandparent = null, wentRightForGranparent = false; @@ -358,7 +358,7 @@ function log(tree) { const title = printNode; - const children = node => (node instanceof ExternalNode ? null : [node.left , node.right]); + const children = node => (node instanceof ExternalNode ? null : [node.left, node.right]); console.log(asciitree(tree.root, title, children)); } diff --git a/index.d.ts b/index.d.ts index abaef492..57654a60 100644 --- a/index.d.ts +++ b/index.d.ts @@ -44,5 +44,5 @@ export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array'; export {default as SymSpell} from './symspell'; export {default as Trie} from './trie'; export {default as TrieMap} from './trie-map'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Array} from './vector'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector'; export {default as VPTree} from './vp-tree'; diff --git a/index.js b/index.js index 9b43b873..34b1a46d 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,8 @@ var Heap = require('./heap.js'), FibonacciHeap = require('./fibonacci-heap.js'), SuffixArray = require('./suffix-array.js'), - BiMap = require('./bi-map.js'); + BiMap = require('./bi-map.js'), + Vector = require('./vector.js'); module.exports = { BiMap: BiMap, @@ -55,6 +56,16 @@ module.exports = { SymSpell: require('./symspell.js'), Trie: require('./trie.js'), TrieMap: require('./trie-map.js'), - Vector: require('./vector.js'), + Vector: Vector, + Uint8Vector: Vector.Uint8Vector, + Uint8ClampedVector: Vector.Uint8ClampedVector, + Int8Vector: Vector.Int8Vector, + Uint16Vector: Vector.Uint16Vector, + Int16Vector: Vector.Int16Vector, + Uint32Vector: Vector.Uint32Vector, + Int32Vector: Vector.Int32Vector, + Float32Vector: Vector.Float32Vector, + Float64Vector: Vector.Float64Vector, + PointerVector: Vector.PointerVector, VPTree: require('./vp-tree.js') }; diff --git a/index.mjs b/index.mjs index 20ba210f..140d7443 100644 --- a/index.mjs +++ b/index.mjs @@ -44,5 +44,5 @@ export {default as SparseSet} from './sparse-set.js'; export {default as SymSpell} from './symspell.js'; export {default as Trie} from './trie.js'; export {default as TrieMap} from './trie-map.js'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Array} from './vector.js'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector.js'; export {default as VPTree} from './vp-tree.js'; diff --git a/package.json b/package.json index 685ba6b9..371eadfe 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "version": "0.39.7", "description": "Curated collection of data structures for the JavaScript/TypeScript.", "scripts": { - "lint": "eslint --cache ./*.js ./*.mjs ./utils ./test", - "lint:fix": "eslint --cache --fix ./*.js ./*.mjs ./utils ./test", + "lint": "eslint --cache --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", + "lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", "prepublishOnly": "npm run lint && npm test && npm run test:types", "test": "mocha", - "test:cjs": "cd test/cjs && npm i && node require.js", + "test:cjs": "cd test/cjs && npm i && node named-require.js", "test:esm": "cd test/esm && npm i && node import.mjs", "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" }, diff --git a/test/cjs/require.js b/test/cjs/named-require.js similarity index 97% rename from test/cjs/require.js rename to test/cjs/named-require.js index 3f47cb20..8e0f8e68 100644 --- a/test/cjs/require.js +++ b/test/cjs/named-require.js @@ -124,7 +124,8 @@ fuzzymultimapadd.add({title: 'Hello', n: 45}); * HashedArrayTree. */ let hashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.set(3, 4); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); /** * Heap. @@ -189,7 +190,7 @@ let lrumwdWasRemoved = lrumwd.delete('one'); let multiset = new MultiSet(); multiset.add(45); multiset = MultiSet.from([1, 2, 3]); -multiset = MultiSet.from({'one': 1}); +multiset = MultiSet.from({one: 1}); /** * MultiMap. @@ -307,7 +308,8 @@ arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); * Vector. */ let vector = new Vector(Uint32Array, 10); -vector.set(45, 2); +vector.push(1); +vector.set(0, 2); let uint16vector = Uint16Vector.from([1, 2, 3]); uint16vector.pop(); diff --git a/test/esm/import.mjs b/test/esm/import.mjs index 8be7fb6b..72c46529 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -124,7 +124,8 @@ fuzzymultimapadd.add({title: 'Hello', n: 45}); * HashedArrayTree. */ let hashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.set(3, 4); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); /** * Heap. @@ -189,7 +190,7 @@ let lrumwdWasRemoved = lrumwd.delete('one'); let multiset = new MultiSet(); multiset.add(45); multiset = MultiSet.from([1, 2, 3]); -multiset = MultiSet.from({'one': 1}); +multiset = MultiSet.from({one: 1}); /** * MultiMap. @@ -307,7 +308,8 @@ arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); * Vector. */ let vector = new Vector(Uint32Array, 10); -vector.set(45, 2); +vector.push(1); +vector.set(0, 2); let uint16vector = Uint16Vector.from([1, 2, 3]); uint16vector.pop(); diff --git a/test/types.ts b/test/types.ts index 08a42724..94c80cec 100644 --- a/test/types.ts +++ b/test/types.ts @@ -124,7 +124,8 @@ fuzzymultimapadd.add({title: 'Hello', n: 45}); * HashedArrayTree. */ let hashedArrayTree: HashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.set(3, 4); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); /** * Heap. @@ -308,7 +309,8 @@ arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); * Vector. */ let vector = new Vector(Uint32Array, 10); -vector.set(45, 2); +vector.push(1); +vector.set(0, 2); let uint16vector = Uint16Vector.from([1, 2, 3]); uint16vector.pop(); diff --git a/vector.d.ts b/vector.d.ts index 5ed513d7..64c1aa1f 100644 --- a/vector.d.ts +++ b/vector.d.ts @@ -78,4 +78,4 @@ export class Uint16Vector extends TypedVector {} export class Int32Vector extends TypedVector {} export class Uint32Vector extends TypedVector {} export class Float32Vector extends TypedVector {} -export class Float64Array extends TypedVector {} +export class Float64Vector extends TypedVector {} From 9103a180f541e57ddb25836aff81ffb3f283abe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 8 Jan 2024 22:51:28 +0100 Subject: [PATCH 07/35] build(ci): disable some eslint rules in import test files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/cjs/named-require.js | 2 ++ test/esm/import.mjs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js index 8e0f8e68..f33f45d8 100644 --- a/test/cjs/named-require.js +++ b/test/cjs/named-require.js @@ -1,3 +1,5 @@ +/* eslint-disable no-empty */ +/* eslint-disable no-unused-vars */ /** * Mnemonist ESM Import Testing * ======================== diff --git a/test/esm/import.mjs b/test/esm/import.mjs index 72c46529..8f0f4e9a 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -1,3 +1,5 @@ +/* eslint-disable no-empty */ +/* eslint-disable no-unused-vars */ /** * Mnemonist ESM Import Testing * ======================== From 7fc278e57bcc642ab4e19ec2d019ad953ea5115b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 00:34:33 +0100 Subject: [PATCH 08/35] test: make CommonJS import works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- fibonacci-heap.js | 2 + heap.js | 2 + index.js | 4 +- index.mjs | 4 +- package.json | 122 +++++++++++++- suffix-array.js | 1 + test/cjs/default-require.js | 321 ++++++++++++++++++++++++++++++++++++ test/cjs/named-require.js | 8 +- test/esm/import.mjs | 10 +- test/types.ts | 4 +- vector.js | 10 ++ 11 files changed, 471 insertions(+), 17 deletions(-) create mode 100644 test/cjs/default-require.js diff --git a/fibonacci-heap.js b/fibonacci-heap.js index f41334f8..c4c8cfcf 100644 --- a/fibonacci-heap.js +++ b/fibonacci-heap.js @@ -317,4 +317,6 @@ MaxFibonacciHeap.from = function(iterable, comparator) { */ FibonacciHeap.MinFibonacciHeap = FibonacciHeap; FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap; +exports.MinFibonacciHeap = FibonacciHeap; +exports.MaxFibonacciHeap = MaxFibonacciHeap; module.exports = FibonacciHeap; diff --git a/heap.js b/heap.js index 90eb971c..24bfa512 100644 --- a/heap.js +++ b/heap.js @@ -573,4 +573,6 @@ Heap.nlargest = nlargest; Heap.MinHeap = Heap; Heap.MaxHeap = MaxHeap; +exports.MinHeap = Heap; +exports.MaxHeap = MaxHeap; module.exports = Heap; diff --git a/index.js b/index.js index 34b1a46d..79940966 100644 --- a/index.js +++ b/index.js @@ -8,12 +8,10 @@ var Heap = require('./heap.js'), FibonacciHeap = require('./fibonacci-heap.js'), SuffixArray = require('./suffix-array.js'), - BiMap = require('./bi-map.js'), Vector = require('./vector.js'); module.exports = { - BiMap: BiMap, - InverseMap: BiMap.InverseMap, + BiMap: require('./bi-map.js'), BitSet: require('./bit-set.js'), BitVector: require('./bit-vector.js'), BloomFilter: require('./bloom-filter.js'), diff --git a/index.mjs b/index.mjs index 140d7443..388c2419 100644 --- a/index.mjs +++ b/index.mjs @@ -6,7 +6,7 @@ */ import * as set from './set.js'; -export {default as BiMap, InverseMap} from './bi-map.js'; +export {default as BiMap} from './bi-map.js'; export {default as BitSet} from './bit-set.js'; export {default as BitVector} from './bit-vector.js'; export {default as BloomFilter} from './bloom-filter.js'; @@ -44,5 +44,5 @@ export {default as SparseSet} from './sparse-set.js'; export {default as SymSpell} from './symspell.js'; export {default as Trie} from './trie.js'; export {default as TrieMap} from './trie-map.js'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector.js'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector.js'; export {default as VPTree} from './vp-tree.js'; diff --git a/package.json b/package.json index 371eadfe..8fbb685f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", "prepublishOnly": "npm run lint && npm test && npm run test:types", "test": "mocha", - "test:cjs": "cd test/cjs && npm i && node named-require.js", + "test:cjs": "cd test/cjs && npm i && node default-require.js && node named-require.js", "test:esm": "cd test/esm && npm i && node import.mjs", "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" }, @@ -19,6 +19,126 @@ "types": "./index.d.ts", "require": "./index.js", "import": "./index.mjs" + }, + "./bi-map": { + "require": "./bi-map.js" + }, + "./bit-set": { + "require": "./bit-set.js" + }, + "./bit-vector": { + "require": "./bit-vector.js" + }, + "./bk-tree": { + "require": "./bk-tree.js" + }, + "./bloom-filter": { + "require": "./bloom-filter.js" + }, + "./circular-buffer": { + "require": "./circular-buffer.js" + }, + "./default-map": { + "require": "./default-map.js" + }, + "./default-weak-map": { + "require": "./default-weak-map.js" + }, + "./fibonacci-heap": { + "require": "./fibonacci-heap.js" + }, + "./fixed-deque": { + "require": "./fixed-deque.js" + }, + "./fixed-reverse-heap": { + "require": "./fixed-reverse-heap.js" + }, + "./fixed-stack": { + "require": "./fixed-stack.js" + }, + "./fuzzy-map": { + "require": "./fuzzy-map.js" + }, + "./fuzzy-multi-map": { + "require": "./fuzzy-multi-map.js" + }, + "./hashed-array-tree": { + "require": "./hashed-array-tree.js" + }, + "./heap": { + "require": "./heap.js" + }, + "./inverted-index": { + "require": "./inverted-index.js" + }, + "./kd-tree": { + "require": "./kd-tree.js" + }, + "./linked-list": { + "require": "./linked-list.js" + }, + "./lru-cache-with-delete": { + "require": "./lru-cache-with-delete.js" + }, + "./lru-cache": { + "require": "./lru-cache.js" + }, + "./lru-map-with-delete": { + "require": "./lru-map-with-delete.js" + }, + "./lru-map": { + "require": "./lru-map.js" + }, + "./multi-map": { + "require": "./multi-map.js" + }, + "./multi-set": { + "require": "./multi-set.js" + }, + "./passjoin-index": { + "require": "./passjoin-index.js" + }, + "./queue": { + "require": "./queue.js" + }, + "./set": { + "require": "./set.js" + }, + "./sparse-map": { + "require": "./sparse-map.js" + }, + "./sparse-queue-set": { + "require": "./sparse-queue-set.js" + }, + "./sparse-set": { + "require": "./sparse-set.js" + }, + "./stack": { + "require": "./stack.js" + }, + "./static-disjoint-set": { + "require": "./static-disjoint-set.js" + }, + "./static-interval-tree": { + "require": "./static-interval-tree.js" + }, + "./suffix-array": { + "require": "./suffix-array.js" + }, + "./symspell": { + "require": "./symspell.js" + }, + "./trie-map": { + "require": "./trie-map.js" + }, + "./trie": { + "require": "./trie.js" + }, + "./vector": { + "require": "./vector.js" + }, + "./vp-tree": { + "require": "./vp-tree.js" } }, "files": [ diff --git a/suffix-array.js b/suffix-array.js index 61632d69..1d7cddf5 100644 --- a/suffix-array.js +++ b/suffix-array.js @@ -349,4 +349,5 @@ if (typeof Symbol !== 'undefined') * Exporting. */ SuffixArray.GeneralizedSuffixArray = GeneralizedSuffixArray; +exports.GeneralizedSuffixArray = GeneralizedSuffixArray; module.exports = SuffixArray; diff --git a/test/cjs/default-require.js b/test/cjs/default-require.js new file mode 100644 index 00000000..087afe9c --- /dev/null +++ b/test/cjs/default-require.js @@ -0,0 +1,321 @@ +/* eslint-disable no-empty */ +/* eslint-disable no-unused-vars */ +/** + * Mnemonist CommonJS Default Require Testing + * ======================== + */ +const BiMap = require('mnemonist/bi-map'); +const BitSet = require('mnemonist/bit-set'); +const BitVector = require('mnemonist/bit-vector'); +const BKTree = require('mnemonist/bk-tree'); +const BloomFilter = require('mnemonist/bloom-filter'); +const CircularBuffer = require('mnemonist/circular-buffer'); +const DefaultMap = require('mnemonist/default-map'); +const FibonacciHeap = require('mnemonist/fibonacci-heap'); +const FixedReverseHeap = require('mnemonist/fixed-reverse-heap'); +const FixedStack = require('mnemonist/fixed-stack'); +const FuzzyMap = require('mnemonist/fuzzy-map'); +const FuzzyMultiMap = require('mnemonist/fuzzy-multi-map'); +const HashedArrayTree = require('mnemonist/hashed-array-tree'); +const Heap = require('mnemonist/heap'); +const InvertedIndex = require('mnemonist/inverted-index'); +const LinkedList = require('mnemonist/linked-list'); +const LRUCache = require('mnemonist/lru-cache'); +const LRUCacheWithDelete = require('mnemonist/lru-cache-with-delete'); +const LRUMap = require('mnemonist/lru-map'); +const LRUMapWithDelete = require('mnemonist/lru-map-with-delete'); +const MultiMap = require('mnemonist/multi-map'); +const MultiSet = require('mnemonist/multi-set'); +const PassjoinIndex = require('mnemonist/passjoin-index'); +const Queue = require('mnemonist/queue'); +const set = require('mnemonist/set'); +const SparseSet = require('mnemonist/sparse-set'); +const Stack = require('mnemonist/stack'); +const StaticDisjointSet = require('mnemonist/static-disjoint-set'); +const StaticIntervalTree = require('mnemonist/static-interval-tree'); +const {GeneralizedSuffixArray} = require('mnemonist/suffix-array'); +const SymSpell = require('mnemonist/symspell'); +const Trie = require('mnemonist/trie'); +const TrieMap = require('mnemonist/trie-map'); +const Vector = require('mnemonist/vector'); +const {Uint16Vector} = require('mnemonist/vector'); +const VPTree = require('mnemonist/vp-tree'); + +/** + * BiMap. + */ +let bimap = new BiMap(); +bimap.set('one', 1); +let inversemap = bimap.inverse; +inversemap.get(1); + +/** + * BitSet. + */ +let bitset = new BitSet(4); +bitset.set(3); + +/** + * BitVector. + */ +let bitvector = new BitVector({initialCapacity: 34}); +bitvector.set(3); + +/** + * BKTree. + */ +let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); +bktree.search(2, 'three'); + +/** + * BloomFilter. + */ +let bloomfilter = new BloomFilter(45); +bloomfilter.add('hello'); + +/** + * CircularBuffer. + */ +let circularbuffer = new CircularBuffer(Array, 4); +circularbuffer.push('test'); + +/** + * DefaultMap. + */ +let defaultMap = new DefaultMap(() => []); +defaultMap.get('one').push(1); + +/** + * FibonacciHeap. + */ +let fibonacciHeap = new FibonacciHeap(); +fibonacciHeap.push('hello'); +fibonacciHeap.pop(); + +/** + * FixedReverseHeap. + */ +let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); +fixedReverseHeap.push(34); + +/** + * FixedStack. + */ +let fixedStack = new FixedStack(Uint8Array, 4); +fixedStack.push(4); +fixedStack.pop(); + +/** + * FuzzyMap. + */ +let fuzzymap = new FuzzyMap(o => o.title); +fuzzymap.set({title: 'Hello'}, 45); +let fuzzymapadd = new FuzzyMap(o => o.n); +fuzzymapadd.add({title: 'Hello', n: 45}); + +/** + * FuzzyMultiMap. + */ +let fuzzymultimap = new FuzzyMultiMap(o => o.title); +fuzzymultimap.set({title: 'Hello'}, 45); +let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); +fuzzymultimapadd.add({title: 'Hello', n: 45}); + +/** + * HashedArrayTree. + */ +let hashedArrayTree = new HashedArrayTree(Int8Array, 34); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); + +/** + * Heap. + */ +let heap = new Heap((a, b) => +a - +b); +heap.push('hello'); +heap.pop(); + +let maxHeap = new Heap(); +maxHeap.push(45); + +/** + * InvertedIndex. + */ +let invertedIndex = new InvertedIndex(n => ['one', 'two']); +invertedIndex.add(45); + +/** + * LinkedList. + */ +let linkedlist = new LinkedList(); +linkedlist.push(true); +let linkedlistItem = linkedlist.shift(); + +/** + * LRUCache. + */ +let lrucache = new LRUCache(10); +lrucache.set('one', 34); +let lrucacheItem = lrucache.get('one'); + +/** + * LRUCacheWithDelete + */ +let lrucwd = new LRUCacheWithDelete(10); +lrucwd.set('one', 'uno'); +let lrucwdItem = lrucwd.get('one'); +lrucwdItem = lrucwd.remove('one'); +let lrucwdDead = lrucwd.remove('one', null); +let lrucwdWasRemoved = lrucwd.delete('one'); + +/** + * LRUMap. + */ +let lrumap = new LRUMap(10); +lrumap.set('one', 34); +let lrumapItem = lrumap.get('one'); + +/** + * LRUMapWithDelete + */ +let lrumwd = new LRUMapWithDelete(10); +lrumwd.set('one', 'uno'); +let lrumwdItem = lrumwd.get('one'); +lrumwdItem = lrumwd.remove('one'); +let lrumwdDead = lrumwd.remove('one', null); +let lrumwdWasRemoved = lrumwd.delete('one'); + +/** + * MultiSet. + */ +let multiset = new MultiSet(); +multiset.add(45); +multiset = MultiSet.from([1, 2, 3]); +multiset = MultiSet.from({one: 1}); + +/** + * MultiMap. + */ +let multimap = new MultiMap(Set); +multimap.set(45, 'test'); +multimap.get(45).has('test'); +let stringMultimap = MultiMap.from({one: 1}); +stringMultimap.get('one').indexOf(1); +for (const _ of multimap) { } +for (const _ of multimap.keys()) { } +for (const _ of multimap.values()) { } +for (const _ of multimap.entries()) { } +for (const _ of multimap.containers()) { } +for (const _ of multimap.associations()) { } + +/** + * PassjoinIndex. + */ +const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); + +let passjoinResults = passjoinIndex.search('hello'); + +/** + * Queue. + */ +let queue = new Queue(); + +queue.enqueue(45); +let queueitem = queue.dequeue(); + +queue.enqueue(45); +queue.enqueue(34); + +queue = Queue.from([1, 2, 3]); +queue = Queue.from({0: 1}); + +let queueIterator = queue.values(); + +/** + * set. + */ +let setA = new Set([1, 2, 3]); +let setB = new Set([3, 4, 5]); +let unionOfSets = set.union(setA, setB); + +/** + * SparseSet. + */ +let sparseSet = new SparseSet(45); +sparseSet.add(3); + +/** + * Stack. + */ +let stack = new Stack(); + +stack.push(45); +let stackitem = stack.pop(); + +stack.push(45); +stack.push(34); + +stack = Stack.from([1, 2, 3]); +stack = Stack.from({0: 1}); + +let stackIterator = stack.values(); + +/** + * StaticDisjointSet. + */ +let disjointSet = new StaticDisjointSet(45); +disjointSet.union(3, 5); + +/** + * StaticIntervalTree. + */ +let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); + +/** + * SuffixArray. + */ +let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); + +/** + * SymSpell. + */ +let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); +let symspellMatches = symspell.search('three'); + +/** + * Trie. + */ +let trie = new Trie(); +trie.add('roman'); + +let trieMatches = trie.find('rom'); + +/** + * TrieMap. + */ +let trieMap = new TrieMap(); +trieMap.set('roman', 45); + +let trieMapMatches = trieMap.find('rom'); + +trieMap = TrieMap.from(new Map([['roman', 45]])); +trieMap = TrieMap.from({roman: 45}); + +let arrayTrieMap = new TrieMap(Array); +arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); + +/** + * Vector. + */ +let vector = new Vector(Uint32Array, 10); +vector.push(1); +vector.set(0, 2); + +let uint16vector = Uint16Vector.from([1, 2, 3]); +uint16vector.pop(); + +/** + * VPTree. + */ +let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js index f33f45d8..8877cd1e 100644 --- a/test/cjs/named-require.js +++ b/test/cjs/named-require.js @@ -1,18 +1,18 @@ /* eslint-disable no-empty */ /* eslint-disable no-unused-vars */ /** - * Mnemonist ESM Import Testing + * Mnemonist CommonJS Named Require Testing * ======================== */ const { - BiMap, InverseMap, + BiMap, BitSet, BitVector, BKTree, BloomFilter, CircularBuffer, DefaultMap, - FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap, + FibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, @@ -34,7 +34,7 @@ const { Stack, StaticDisjointSet, StaticIntervalTree, - SuffixArray, GeneralizedSuffixArray, + GeneralizedSuffixArray, SymSpell, Trie, TrieMap, diff --git a/test/esm/import.mjs b/test/esm/import.mjs index 8f0f4e9a..6cc9a42f 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -1,24 +1,24 @@ /* eslint-disable no-empty */ /* eslint-disable no-unused-vars */ /** - * Mnemonist ESM Import Testing + * Mnemonist ESM Named Import Testing * ======================== */ import { - BiMap, InverseMap, + BiMap, BitSet, BitVector, BKTree, BloomFilter, CircularBuffer, DefaultMap, - FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap, + FibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, FuzzyMultiMap, HashedArrayTree, - Heap, MaxHeap, + Heap, InvertedIndex, LinkedList, LRUCache, @@ -34,7 +34,7 @@ import { Stack, StaticDisjointSet, StaticIntervalTree, - SuffixArray, GeneralizedSuffixArray, + GeneralizedSuffixArray, SymSpell, Trie, TrieMap, diff --git a/test/types.ts b/test/types.ts index 94c80cec..e8cbd91e 100644 --- a/test/types.ts +++ b/test/types.ts @@ -87,7 +87,7 @@ defaultMap.get('one').push(1); /** * FibonacciHeap. */ -let fibonacciHeap: FibonacciHeap = new FibonacciHeap(); +let fibonacciHeap: FibonacciHeap | MinFibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); @@ -274,7 +274,7 @@ let intervalTree: StaticIntervalTree = StaticIntervalTree.from([[0, 1] /** * SuffixArray. */ -let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let generalizedSuffixArray: GeneralizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); let suffixArrayLCS: string = generalizedSuffixArray.longestCommonSubsequence() as string; /** diff --git a/vector.js b/vector.js index 467bf20f..388c4a01 100644 --- a/vector.js +++ b/vector.js @@ -370,4 +370,14 @@ Vector.Float32Vector = subClass(Float32Array); Vector.Float64Vector = subClass(Float64Array); Vector.PointerVector = subClass(pointerArrayFactory); +exports.Int8Vector = Vector.Int8Vector; +exports.Uint8Vector = Vector.Uint8Vector; +exports.Uint8ClampedVector = Vector.Uint8ClampedVector; +exports.Int16Vector = Vector.Int16Vector; +exports.Uint16Vector = Vector.Uint16Vector; +exports.Int32Vector = Vector.Int32Vector; +exports.Uint32Vector = Vector.Uint32Vector; +exports.Float32Vector = Vector.Float32Vector; +exports.Float64Vector = Vector.Float64Vector; +exports.PointerVector = Vector.PointerVector; module.exports = Vector; From 78a942cb8a970b7fd6247af05bcaaa0a1f625c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 00:43:46 +0100 Subject: [PATCH 09/35] refactor: code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/cjs/default-require.js | 2 +- test/cjs/named-require.js | 8 ++++++-- test/esm/import.mjs | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/cjs/default-require.js b/test/cjs/default-require.js index 087afe9c..b66a6cc3 100644 --- a/test/cjs/default-require.js +++ b/test/cjs/default-require.js @@ -2,7 +2,7 @@ /* eslint-disable no-unused-vars */ /** * Mnemonist CommonJS Default Require Testing - * ======================== + * =========================================== */ const BiMap = require('mnemonist/bi-map'); const BitSet = require('mnemonist/bit-set'); diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js index 8877cd1e..1dea07d6 100644 --- a/test/cjs/named-require.js +++ b/test/cjs/named-require.js @@ -2,7 +2,7 @@ /* eslint-disable no-unused-vars */ /** * Mnemonist CommonJS Named Require Testing - * ======================== + * ========================================= */ const { BiMap, @@ -13,12 +13,13 @@ const { CircularBuffer, DefaultMap, FibonacciHeap, + MinFibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, FuzzyMultiMap, HashedArrayTree, - Heap, MaxHeap, + Heap, InvertedIndex, LinkedList, LRUCache, @@ -92,6 +93,9 @@ defaultMap.get('one').push(1); let fibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); +let minFibonacciHeap = new MinFibonacciHeap(); +minFibonacciHeap.push('hello'); +minFibonacciHeap.pop(); /** * FixedReverseHeap. diff --git a/test/esm/import.mjs b/test/esm/import.mjs index 6cc9a42f..b3ad01ea 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -2,7 +2,7 @@ /* eslint-disable no-unused-vars */ /** * Mnemonist ESM Named Import Testing - * ======================== + * =================================== */ import { BiMap, @@ -13,6 +13,7 @@ import { CircularBuffer, DefaultMap, FibonacciHeap, + MinFibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, @@ -92,6 +93,9 @@ defaultMap.get('one').push(1); let fibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); +let minFibonacciHeap = new MinFibonacciHeap(); +minFibonacciHeap.push('hello'); +minFibonacciHeap.pop(); /** * FixedReverseHeap. From 815e0bbe5249cbc1acb16e10840f88483e4e1fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 00:55:59 +0100 Subject: [PATCH 10/35] test: add module import tests to CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d0db6e51..124a45e1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,4 +32,6 @@ jobs: npm i npm run lint npm test + npm run test:cjs + npm run test:esm npm run test:types diff --git a/package.json b/package.json index 8fbb685f..c7ab79ee 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "lint": "eslint --cache --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", "lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", - "prepublishOnly": "npm run lint && npm test && npm run test:types", + "prepublishOnly": "npm run lint && npm test && npm run test:cjs && npm run test:esm && npm run test:types", "test": "mocha", "test:cjs": "cd test/cjs && npm i && node default-require.js && node named-require.js", "test:esm": "cd test/esm && npm i && node import.mjs", From 837ae2282bf76f9c3519dee0f9eb076611a82229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 01:03:43 +0100 Subject: [PATCH 11/35] refactor: code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.js | 2 +- index.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 79940966..5eadce71 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ /** * Mnemonist Library Endpoint (CommonJS) - * ===================================== + * ====================================== * * Exporting every data structure through a unified endpoint. Consumers * of this library should prefer the modular access though. diff --git a/index.mjs b/index.mjs index 388c2419..5fa86968 100644 --- a/index.mjs +++ b/index.mjs @@ -1,6 +1,6 @@ /** * Mnemonist Library Endpoint (ESM) - * ================================ + * ================================= * * Exporting every data structure through a unified endpoint. */ From 76179e816b45b60b3de38daf66574e99ab56221e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 01:19:14 +0100 Subject: [PATCH 12/35] build(ci): remove non LTS node release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 124a45e1..20b5a8e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,11 +10,10 @@ jobs: # npm will not run under 10.x or earlier and so they cannot be tested node-version: - 12.x - - 13.x - 14.x - - 15.x - 16.x - 18.x + - 20.x - latest runs-on: ubuntu-latest From fbdaaa2c2c30f05d5a653033dfca659a97afd142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 01:40:39 +0100 Subject: [PATCH 13/35] refactor: cleanup exports in package.json by using wildcards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 124 +++------------------------------------------------ 1 file changed, 6 insertions(+), 118 deletions(-) diff --git a/package.json b/package.json index c7ab79ee..99612972 100644 --- a/package.json +++ b/package.json @@ -20,125 +20,13 @@ "require": "./index.js", "import": "./index.mjs" }, - "./bi-map": { - "require": "./bi-map.js" + "./*": { + "types": "./*.d.ts", + "require": "./*.js" }, - "./bit-set": { - "require": "./bit-set.js" - }, - "./bit-vector": { - "require": "./bit-vector.js" - }, - "./bk-tree": { - "require": "./bk-tree.js" - }, - "./bloom-filter": { - "require": "./bloom-filter.js" - }, - "./circular-buffer": { - "require": "./circular-buffer.js" - }, - "./default-map": { - "require": "./default-map.js" - }, - "./default-weak-map": { - "require": "./default-weak-map.js" - }, - "./fibonacci-heap": { - "require": "./fibonacci-heap.js" - }, - "./fixed-deque": { - "require": "./fixed-deque.js" - }, - "./fixed-reverse-heap": { - "require": "./fixed-reverse-heap.js" - }, - "./fixed-stack": { - "require": "./fixed-stack.js" - }, - "./fuzzy-map": { - "require": "./fuzzy-map.js" - }, - "./fuzzy-multi-map": { - "require": "./fuzzy-multi-map.js" - }, - "./hashed-array-tree": { - "require": "./hashed-array-tree.js" - }, - "./heap": { - "require": "./heap.js" - }, - "./inverted-index": { - "require": "./inverted-index.js" - }, - "./kd-tree": { - "require": "./kd-tree.js" - }, - "./linked-list": { - "require": "./linked-list.js" - }, - "./lru-cache-with-delete": { - "require": "./lru-cache-with-delete.js" - }, - "./lru-cache": { - "require": "./lru-cache.js" - }, - "./lru-map-with-delete": { - "require": "./lru-map-with-delete.js" - }, - "./lru-map": { - "require": "./lru-map.js" - }, - "./multi-map": { - "require": "./multi-map.js" - }, - "./multi-set": { - "require": "./multi-set.js" - }, - "./passjoin-index": { - "require": "./passjoin-index.js" - }, - "./queue": { - "require": "./queue.js" - }, - "./set": { - "require": "./set.js" - }, - "./sparse-map": { - "require": "./sparse-map.js" - }, - "./sparse-queue-set": { - "require": "./sparse-queue-set.js" - }, - "./sparse-set": { - "require": "./sparse-set.js" - }, - "./stack": { - "require": "./stack.js" - }, - "./static-disjoint-set": { - "require": "./static-disjoint-set.js" - }, - "./static-interval-tree": { - "require": "./static-interval-tree.js" - }, - "./suffix-array": { - "require": "./suffix-array.js" - }, - "./symspell": { - "require": "./symspell.js" - }, - "./trie-map": { - "require": "./trie-map.js" - }, - "./trie": { - "require": "./trie.js" - }, - "./vector": { - "require": "./vector.js" - }, - "./vp-tree": { - "require": "./vp-tree.js" + "./*.js": { + "types": "./*.d.ts", + "require": "./*.js" } }, "files": [ From e69fbe45e436cbbf285f25f19692f5f9097f7612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 12:58:36 +0100 Subject: [PATCH 14/35] fix: add missing constructor to InverseMap type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- bi-map.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bi-map.d.ts b/bi-map.d.ts index a25246a2..6bc974c0 100644 --- a/bi-map.d.ts +++ b/bi-map.d.ts @@ -8,6 +8,9 @@ export class InverseMap implements Iterable<[K, V]> { size: number; inverse: BiMap; + // Constructor + constructor(original: BiMap); + // Methods clear(): void; set(key: K, value: V): this; From d4ecdb986833cc3b888314d260fd9c105cab4b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 15:24:32 +0100 Subject: [PATCH 15/35] test: improve a bit Heap coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/cjs/default-require.js | 3 ++- test/cjs/named-require.js | 4 ++-- test/esm/import.mjs | 4 ++-- test/types.ts | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/cjs/default-require.js b/test/cjs/default-require.js index b66a6cc3..2df61319 100644 --- a/test/cjs/default-require.js +++ b/test/cjs/default-require.js @@ -18,6 +18,7 @@ const FuzzyMap = require('mnemonist/fuzzy-map'); const FuzzyMultiMap = require('mnemonist/fuzzy-multi-map'); const HashedArrayTree = require('mnemonist/hashed-array-tree'); const Heap = require('mnemonist/heap'); +const {MaxHeap} = require('mnemonist/heap'); const InvertedIndex = require('mnemonist/inverted-index'); const LinkedList = require('mnemonist/linked-list'); const LRUCache = require('mnemonist/lru-cache'); @@ -135,7 +136,7 @@ let heap = new Heap((a, b) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap = new Heap(); +let maxHeap = new MaxHeap(); maxHeap.push(45); /** diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js index 1dea07d6..3781a524 100644 --- a/test/cjs/named-require.js +++ b/test/cjs/named-require.js @@ -19,7 +19,7 @@ const { FuzzyMap, FuzzyMultiMap, HashedArrayTree, - Heap, + Heap, MaxHeap, InvertedIndex, LinkedList, LRUCache, @@ -140,7 +140,7 @@ let heap = new Heap((a, b) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap = new Heap(); +let maxHeap = new MaxHeap(); maxHeap.push(45); /** diff --git a/test/esm/import.mjs b/test/esm/import.mjs index b3ad01ea..b1bd2fbb 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -19,7 +19,7 @@ import { FuzzyMap, FuzzyMultiMap, HashedArrayTree, - Heap, + Heap, MaxHeap, InvertedIndex, LinkedList, LRUCache, @@ -140,7 +140,7 @@ let heap = new Heap((a, b) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap = new Heap(); +let maxHeap = new MaxHeap(); maxHeap.push(45); /** diff --git a/test/types.ts b/test/types.ts index e8cbd91e..ca5ee36c 100644 --- a/test/types.ts +++ b/test/types.ts @@ -130,11 +130,11 @@ hashedArrayTree.set(0, 4); /** * Heap. */ -let heap: Heap = new Heap((a: string, b: string) => +a - +b); +let heap: Heap | MaxHeap = new Heap((a: string, b: string) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap: MaxHeap = new Heap(); +let maxHeap: MaxHeap = new MaxHeap(); maxHeap.push(45); /** From 4f8d31d8ccdbcb58604984032441c9736151d5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 9 Jan 2024 15:34:12 +0100 Subject: [PATCH 16/35] refactor: import cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/cjs/default-require.js | 4 ++++ test/cjs/named-require.js | 3 +-- test/esm/import.mjs | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/cjs/default-require.js b/test/cjs/default-require.js index 2df61319..4baf86a3 100644 --- a/test/cjs/default-require.js +++ b/test/cjs/default-require.js @@ -12,6 +12,7 @@ const BloomFilter = require('mnemonist/bloom-filter'); const CircularBuffer = require('mnemonist/circular-buffer'); const DefaultMap = require('mnemonist/default-map'); const FibonacciHeap = require('mnemonist/fibonacci-heap'); +const {MinFibonacciHeap} = require('mnemonist/fibonacci-heap'); const FixedReverseHeap = require('mnemonist/fixed-reverse-heap'); const FixedStack = require('mnemonist/fixed-stack'); const FuzzyMap = require('mnemonist/fuzzy-map'); @@ -92,6 +93,9 @@ defaultMap.get('one').push(1); let fibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); +let minFibonacciHeap = new MinFibonacciHeap(); +minFibonacciHeap.push('hello'); +minFibonacciHeap.pop(); /** * FixedReverseHeap. diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js index 3781a524..09498e7a 100644 --- a/test/cjs/named-require.js +++ b/test/cjs/named-require.js @@ -12,8 +12,7 @@ const { BloomFilter, CircularBuffer, DefaultMap, - FibonacciHeap, - MinFibonacciHeap, + FibonacciHeap, MinFibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, diff --git a/test/esm/import.mjs b/test/esm/import.mjs index b1bd2fbb..95318f7c 100644 --- a/test/esm/import.mjs +++ b/test/esm/import.mjs @@ -12,8 +12,7 @@ import { BloomFilter, CircularBuffer, DefaultMap, - FibonacciHeap, - MinFibonacciHeap, + FibonacciHeap, MinFibonacciHeap, FixedReverseHeap, FixedStack, FuzzyMap, From d3e9f6b21fd0ab4e7fd9edbd19f716f2f83e87d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 10 Jan 2024 17:51:15 +0100 Subject: [PATCH 17/35] fix: use named CJS exports to improve tree shaking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.js | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 5eadce71..ff250dae 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,6 @@ * Exporting every data structure through a unified endpoint. Consumers * of this library should prefer the modular access though. */ -var Heap = require('./heap.js'), - FibonacciHeap = require('./fibonacci-heap.js'), - SuffixArray = require('./suffix-array.js'), - Vector = require('./vector.js'); - module.exports = { BiMap: require('./bi-map.js'), BitSet: require('./bit-set.js'), @@ -21,16 +16,16 @@ module.exports = { DefaultWeakMap: require('./default-weak-map.js'), FixedDeque: require('./fixed-deque.js'), StaticDisjointSet: require('./static-disjoint-set.js'), - FibonacciHeap: FibonacciHeap, - MinFibonacciHeap: FibonacciHeap.MinFibonacciHeap, - MaxFibonacciHeap: FibonacciHeap.MaxFibonacciHeap, + FibonacciHeap: require('./fibonacci-heap.js'), + MinFibonacciHeap: require('./fibonacci-heap.js').MinFibonacciHeap, + MaxFibonacciHeap: require('./fibonacci-heap.js').MaxFibonacciHeap, FixedReverseHeap: require('./fixed-reverse-heap.js'), FuzzyMap: require('./fuzzy-map.js'), FuzzyMultiMap: require('./fuzzy-multi-map.js'), HashedArrayTree: require('./hashed-array-tree.js'), - Heap: Heap, - MinHeap: Heap.MinHeap, - MaxHeap: Heap.MaxHeap, + Heap: require('./heap.js'), + MinHeap: require('./heap.js').MinHeap, + MaxHeap: require('./heap.js').MaxHeap, StaticIntervalTree: require('./static-interval-tree.js'), InvertedIndex: require('./inverted-index.js'), KDTree: require('./kd-tree.js'), @@ -45,8 +40,8 @@ module.exports = { Queue: require('./queue.js'), FixedStack: require('./fixed-stack.js'), Stack: require('./stack.js'), - SuffixArray: SuffixArray, - GeneralizedSuffixArray: SuffixArray.GeneralizedSuffixArray, + SuffixArray: require('./suffix-array.js'), + GeneralizedSuffixArray: require('./suffix-array.js').GeneralizedSuffixArray, set: require('./set.js'), SparseQueueSet: require('./sparse-queue-set.js'), SparseMap: require('./sparse-map.js'), @@ -54,16 +49,16 @@ module.exports = { SymSpell: require('./symspell.js'), Trie: require('./trie.js'), TrieMap: require('./trie-map.js'), - Vector: Vector, - Uint8Vector: Vector.Uint8Vector, - Uint8ClampedVector: Vector.Uint8ClampedVector, - Int8Vector: Vector.Int8Vector, - Uint16Vector: Vector.Uint16Vector, - Int16Vector: Vector.Int16Vector, - Uint32Vector: Vector.Uint32Vector, - Int32Vector: Vector.Int32Vector, - Float32Vector: Vector.Float32Vector, - Float64Vector: Vector.Float64Vector, - PointerVector: Vector.PointerVector, + Vector: require('./vector.js'), + Uint8Vector: require('./vector.js').Uint8Vector, + Uint8ClampedVector: require('./vector.js').Uint8ClampedVector, + Int8Vector: require('./vector.js').Int8Vector, + Uint16Vector: require('./vector.js').Uint16Vector, + Int16Vector: require('./vector.js').Int16Vector, + Uint32Vector: require('./vector.js').Uint32Vector, + Int32Vector: require('./vector.js').Int32Vector, + Float32Vector: require('./vector.js').Float32Vector, + Float64Vector: require('./vector.js').Float64Vector, + PointerVector: require('./vector.js').PointerVector, VPTree: require('./vp-tree.js') }; From c178c41c016f536346635fe3b94b2a54f1efbcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 10 Jan 2024 17:56:01 +0100 Subject: [PATCH 18/35] refactor: consistent coding style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- vector.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector.d.ts b/vector.d.ts index a6c1c6a3..64c1aa1f 100644 --- a/vector.d.ts +++ b/vector.d.ts @@ -2,7 +2,7 @@ * Mnemonist Vector Typings * ========================= */ -import { IArrayLikeConstructor } from './utils/types'; +import {IArrayLikeConstructor} from './utils/types'; type VectorOptions = { initialLength?: number; From 5c8a49f9a75c1965c94c73a27e2c528d764a2545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 13:02:59 +0100 Subject: [PATCH 19/35] refactor: cleanup named exports mixed usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- fibonacci-heap.js | 3 +-- heap.js | 2 -- index.js | 43 ++++++++++++++++++++++++------------------- index.mjs | 27 +++++++++++++++++++++++---- suffix-array.js | 2 +- vector.js | 10 ---------- 6 files changed, 49 insertions(+), 38 deletions(-) diff --git a/fibonacci-heap.js b/fibonacci-heap.js index c4c8cfcf..012151f8 100644 --- a/fibonacci-heap.js +++ b/fibonacci-heap.js @@ -317,6 +317,5 @@ MaxFibonacciHeap.from = function(iterable, comparator) { */ FibonacciHeap.MinFibonacciHeap = FibonacciHeap; FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap; -exports.MinFibonacciHeap = FibonacciHeap; -exports.MaxFibonacciHeap = MaxFibonacciHeap; + module.exports = FibonacciHeap; diff --git a/heap.js b/heap.js index 24bfa512..90eb971c 100644 --- a/heap.js +++ b/heap.js @@ -573,6 +573,4 @@ Heap.nlargest = nlargest; Heap.MinHeap = Heap; Heap.MaxHeap = MaxHeap; -exports.MinHeap = Heap; -exports.MaxHeap = MaxHeap; module.exports = Heap; diff --git a/index.js b/index.js index ff250dae..2f24045f 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,11 @@ * Exporting every data structure through a unified endpoint. Consumers * of this library should prefer the modular access though. */ +var Heap = require('./heap.js'), + FibonacciHeap = require('./fibonacci-heap.js'), + SuffixArray = require('./suffix-array.js'), + Vector = require('./vector.js'); + module.exports = { BiMap: require('./bi-map.js'), BitSet: require('./bit-set.js'), @@ -16,16 +21,16 @@ module.exports = { DefaultWeakMap: require('./default-weak-map.js'), FixedDeque: require('./fixed-deque.js'), StaticDisjointSet: require('./static-disjoint-set.js'), - FibonacciHeap: require('./fibonacci-heap.js'), - MinFibonacciHeap: require('./fibonacci-heap.js').MinFibonacciHeap, - MaxFibonacciHeap: require('./fibonacci-heap.js').MaxFibonacciHeap, + FibonacciHeap: FibonacciHeap, + MinFibonacciHeap: FibonacciHeap.MinFibonacciHeap, + MaxFibonacciHeap: FibonacciHeap.MaxFibonacciHeap, FixedReverseHeap: require('./fixed-reverse-heap.js'), FuzzyMap: require('./fuzzy-map.js'), FuzzyMultiMap: require('./fuzzy-multi-map.js'), HashedArrayTree: require('./hashed-array-tree.js'), - Heap: require('./heap.js'), - MinHeap: require('./heap.js').MinHeap, - MaxHeap: require('./heap.js').MaxHeap, + Heap: Heap, + MinHeap: Heap.MinHeap, + MaxHeap: Heap.MaxHeap, StaticIntervalTree: require('./static-interval-tree.js'), InvertedIndex: require('./inverted-index.js'), KDTree: require('./kd-tree.js'), @@ -40,8 +45,8 @@ module.exports = { Queue: require('./queue.js'), FixedStack: require('./fixed-stack.js'), Stack: require('./stack.js'), - SuffixArray: require('./suffix-array.js'), - GeneralizedSuffixArray: require('./suffix-array.js').GeneralizedSuffixArray, + SuffixArray: SuffixArray, + GeneralizedSuffixArray: SuffixArray.GeneralizedSuffixArray, set: require('./set.js'), SparseQueueSet: require('./sparse-queue-set.js'), SparseMap: require('./sparse-map.js'), @@ -49,16 +54,16 @@ module.exports = { SymSpell: require('./symspell.js'), Trie: require('./trie.js'), TrieMap: require('./trie-map.js'), - Vector: require('./vector.js'), - Uint8Vector: require('./vector.js').Uint8Vector, - Uint8ClampedVector: require('./vector.js').Uint8ClampedVector, - Int8Vector: require('./vector.js').Int8Vector, - Uint16Vector: require('./vector.js').Uint16Vector, - Int16Vector: require('./vector.js').Int16Vector, - Uint32Vector: require('./vector.js').Uint32Vector, - Int32Vector: require('./vector.js').Int32Vector, - Float32Vector: require('./vector.js').Float32Vector, - Float64Vector: require('./vector.js').Float64Vector, - PointerVector: require('./vector.js').PointerVector, + Vector: Vector, + Uint8Vector: Vector.Uint8Vector, + Uint8ClampedVector: Vector.Uint8ClampedVector, + Int8Vector: Vector.Int8Vector, + Uint16Vector: Vector.Uint16Vector, + Int16Vector: Vector.Int16Vector, + Uint32Vector: Vector.Uint32Vector, + Int32Vector: Vector.Int32Vector, + Float32Vector: Vector.Float32Vector, + Float64Vector: Vector.Float64Vector, + PointerVector: Vector.PointerVector, VPTree: require('./vp-tree.js') }; diff --git a/index.mjs b/index.mjs index 5fa86968..5febfcfd 100644 --- a/index.mjs +++ b/index.mjs @@ -5,6 +5,25 @@ * Exporting every data structure through a unified endpoint. */ import * as set from './set.js'; +import {default as FibonacciHeap} from './fibonacci-heap.js'; +const MinFibonacciHeap = FibonacciHeap.MinFibonacciHeap; +const MaxFibonacciHeap = FibonacciHeap.MaxFibonacciHeap; +import {default as Heap} from './heap.js'; +const MinHeap = Heap.MinHeap; +const MaxHeap = Heap.MaxHeap; +import {default as SuffixArray} from './suffix-array.js'; +const GeneralizedSuffixArray = SuffixArray.GeneralizedSuffixArray; +import {default as Vector} from './vector.js'; +const Uint8Vector = Vector.Uint8Vector; +const Uint8ClampedVector = Vector.Uint8ClampedVector; +const Int8Vector = Vector.Int8Vector; +const Uint16Vector = Vector.Uint16Vector; +const Int16Vector = Vector.Int16Vector; +const Uint32Vector = Vector.Uint32Vector; +const Int32Vector = Vector.Int32Vector; +const Float32Vector = Vector.Float32Vector; +const Float64Vector = Vector.Float64Vector; +const PointerVector = Vector.PointerVector; export {default as BiMap} from './bi-map.js'; export {default as BitSet} from './bit-set.js'; @@ -16,12 +35,12 @@ export {default as DefaultMap} from './default-map.js'; export {default as DefaultWeakMap} from './default-weak-map.js'; export {default as FixedDeque} from './fixed-deque.js'; export {default as StaticDisjointSet} from './static-disjoint-set.js'; -export {default as FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap} from './fibonacci-heap.js'; +export {FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap}; export {default as FixedReverseHeap} from './fixed-reverse-heap.js'; export {default as FuzzyMap} from './fuzzy-map.js'; export {default as FuzzyMultiMap} from './fuzzy-multi-map.js'; export {default as HashedArrayTree} from './hashed-array-tree.js'; -export {default as Heap, MinHeap, MaxHeap} from './heap.js'; +export {Heap, MinHeap, MaxHeap}; export {default as StaticIntervalTree} from './static-interval-tree.js'; export {default as InvertedIndex} from './inverted-index.js'; export {default as KDTree} from './kd-tree.js'; @@ -36,7 +55,7 @@ export {default as PassjoinIndex} from './passjoin-index.js'; export {default as Queue} from './queue.js'; export {default as FixedStack} from './fixed-stack.js'; export {default as Stack} from './stack.js'; -export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array.js'; +export {SuffixArray, GeneralizedSuffixArray}; export {set}; export {default as SparseQueueSet} from './sparse-queue-set.js'; export {default as SparseMap} from './sparse-map.js'; @@ -44,5 +63,5 @@ export {default as SparseSet} from './sparse-set.js'; export {default as SymSpell} from './symspell.js'; export {default as Trie} from './trie.js'; export {default as TrieMap} from './trie-map.js'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector.js'; +export {Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector}; export {default as VPTree} from './vp-tree.js'; diff --git a/suffix-array.js b/suffix-array.js index 1d7cddf5..abda47ee 100644 --- a/suffix-array.js +++ b/suffix-array.js @@ -349,5 +349,5 @@ if (typeof Symbol !== 'undefined') * Exporting. */ SuffixArray.GeneralizedSuffixArray = GeneralizedSuffixArray; -exports.GeneralizedSuffixArray = GeneralizedSuffixArray; + module.exports = SuffixArray; diff --git a/vector.js b/vector.js index 388c4a01..467bf20f 100644 --- a/vector.js +++ b/vector.js @@ -370,14 +370,4 @@ Vector.Float32Vector = subClass(Float32Array); Vector.Float64Vector = subClass(Float64Array); Vector.PointerVector = subClass(pointerArrayFactory); -exports.Int8Vector = Vector.Int8Vector; -exports.Uint8Vector = Vector.Uint8Vector; -exports.Uint8ClampedVector = Vector.Uint8ClampedVector; -exports.Int16Vector = Vector.Int16Vector; -exports.Uint16Vector = Vector.Uint16Vector; -exports.Int32Vector = Vector.Int32Vector; -exports.Uint32Vector = Vector.Uint32Vector; -exports.Float32Vector = Vector.Float32Vector; -exports.Float64Vector = Vector.Float64Vector; -exports.PointerVector = Vector.PointerVector; module.exports = Vector; From 4a7d98ed6e2a0f50587015b7f47403588fb0ca62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 13:19:30 +0100 Subject: [PATCH 20/35] test: cleanup default require test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/cjs/default-require.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/cjs/default-require.js b/test/cjs/default-require.js index 4baf86a3..473f0401 100644 --- a/test/cjs/default-require.js +++ b/test/cjs/default-require.js @@ -12,14 +12,12 @@ const BloomFilter = require('mnemonist/bloom-filter'); const CircularBuffer = require('mnemonist/circular-buffer'); const DefaultMap = require('mnemonist/default-map'); const FibonacciHeap = require('mnemonist/fibonacci-heap'); -const {MinFibonacciHeap} = require('mnemonist/fibonacci-heap'); const FixedReverseHeap = require('mnemonist/fixed-reverse-heap'); const FixedStack = require('mnemonist/fixed-stack'); const FuzzyMap = require('mnemonist/fuzzy-map'); const FuzzyMultiMap = require('mnemonist/fuzzy-multi-map'); const HashedArrayTree = require('mnemonist/hashed-array-tree'); const Heap = require('mnemonist/heap'); -const {MaxHeap} = require('mnemonist/heap'); const InvertedIndex = require('mnemonist/inverted-index'); const LinkedList = require('mnemonist/linked-list'); const LRUCache = require('mnemonist/lru-cache'); @@ -35,12 +33,11 @@ const SparseSet = require('mnemonist/sparse-set'); const Stack = require('mnemonist/stack'); const StaticDisjointSet = require('mnemonist/static-disjoint-set'); const StaticIntervalTree = require('mnemonist/static-interval-tree'); -const {GeneralizedSuffixArray} = require('mnemonist/suffix-array'); +const SuffixArray = require('mnemonist/suffix-array'); const SymSpell = require('mnemonist/symspell'); const Trie = require('mnemonist/trie'); const TrieMap = require('mnemonist/trie-map'); const Vector = require('mnemonist/vector'); -const {Uint16Vector} = require('mnemonist/vector'); const VPTree = require('mnemonist/vp-tree'); /** @@ -93,7 +90,7 @@ defaultMap.get('one').push(1); let fibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); -let minFibonacciHeap = new MinFibonacciHeap(); +let minFibonacciHeap = new FibonacciHeap.MinFibonacciHeap(); minFibonacciHeap.push('hello'); minFibonacciHeap.pop(); @@ -140,7 +137,7 @@ let heap = new Heap((a, b) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap = new MaxHeap(); +let maxHeap = new Heap.MaxHeap(); maxHeap.push(45); /** @@ -279,7 +276,7 @@ let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); /** * SuffixArray. */ -let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let generalizedSuffixArray = new SuffixArray.GeneralizedSuffixArray(['test', 'hello']); let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); /** @@ -317,7 +314,7 @@ let vector = new Vector(Uint32Array, 10); vector.push(1); vector.set(0, 2); -let uint16vector = Uint16Vector.from([1, 2, 3]); +let uint16vector = Vector.Uint16Vector.from([1, 2, 3]); uint16vector.pop(); /** From b6a96d9f0bb24bf2db6913ff99c1ed984fb4722d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 17:02:35 +0100 Subject: [PATCH 21/35] refactor: indentation cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2f24045f..5eadce71 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,9 @@ * of this library should prefer the modular access though. */ var Heap = require('./heap.js'), - FibonacciHeap = require('./fibonacci-heap.js'), - SuffixArray = require('./suffix-array.js'), - Vector = require('./vector.js'); + FibonacciHeap = require('./fibonacci-heap.js'), + SuffixArray = require('./suffix-array.js'), + Vector = require('./vector.js'); module.exports = { BiMap: require('./bi-map.js'), From 95da86469782fb0af09bb994b217ac6c20b9ff05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:05:57 +0100 Subject: [PATCH 22/35] test: consodidate exports testing code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #218 Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 4 +- package.json | 6 +- test/cjs/named-require.js | 325 ------------------ test/cjs/package.json | 8 - test/esm/.gitignore | 1 - test/esm/import.mjs | 325 ------------------ test/esm/package.json | 9 - test/{cjs => exports}/.gitignore | 1 + .../exports-default-test.cjs} | 7 +- .../exports-named-test.ts} | 10 +- test/exports/package.json | 18 + 11 files changed, 35 insertions(+), 679 deletions(-) delete mode 100644 test/cjs/named-require.js delete mode 100644 test/cjs/package.json delete mode 100644 test/esm/.gitignore delete mode 100644 test/esm/import.mjs delete mode 100644 test/esm/package.json rename test/{cjs => exports}/.gitignore (75%) rename test/{cjs/default-require.js => exports/exports-default-test.cjs} (97%) rename test/{types.ts => exports/exports-named-test.ts} (96%) create mode 100644 test/exports/package.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 20b5a8e9..bea192e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,6 +31,4 @@ jobs: npm i npm run lint npm test - npm run test:cjs - npm run test:esm - npm run test:types + npm run test:exports diff --git a/package.json b/package.json index 99612972..c1fd1420 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,9 @@ "scripts": { "lint": "eslint --cache --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", "lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", - "prepublishOnly": "npm run lint && npm test && npm run test:cjs && npm run test:esm && npm run test:types", + "prepublishOnly": "npm run lint && npm test && npm run test:exports", "test": "mocha", - "test:cjs": "cd test/cjs && npm i && node default-require.js && node named-require.js", - "test:esm": "cd test/esm && npm i && node import.mjs", - "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" + "test:exports": "cd test/exports && npm i && npm run test" }, "main": "./index.js", "module": "./index.mjs", diff --git a/test/cjs/named-require.js b/test/cjs/named-require.js deleted file mode 100644 index 09498e7a..00000000 --- a/test/cjs/named-require.js +++ /dev/null @@ -1,325 +0,0 @@ -/* eslint-disable no-empty */ -/* eslint-disable no-unused-vars */ -/** - * Mnemonist CommonJS Named Require Testing - * ========================================= - */ -const { - BiMap, - BitSet, - BitVector, - BKTree, - BloomFilter, - CircularBuffer, - DefaultMap, - FibonacciHeap, MinFibonacciHeap, - FixedReverseHeap, - FixedStack, - FuzzyMap, - FuzzyMultiMap, - HashedArrayTree, - Heap, MaxHeap, - InvertedIndex, - LinkedList, - LRUCache, - LRUCacheWithDelete, - LRUMap, - LRUMapWithDelete, - MultiSet, - MultiMap, - PassjoinIndex, - Queue, - set, - SparseSet, - Stack, - StaticDisjointSet, - StaticIntervalTree, - GeneralizedSuffixArray, - SymSpell, - Trie, - TrieMap, - Vector, Uint16Vector, - VPTree -} = require('mnemonist'); - -/** - * BiMap. - */ -let bimap = new BiMap(); -bimap.set('one', 1); -let inversemap = bimap.inverse; -inversemap.get(1); - -/** - * BitSet. - */ -let bitset = new BitSet(4); -bitset.set(3); - -/** - * BitVector. - */ -let bitvector = new BitVector({initialCapacity: 34}); -bitvector.set(3); - -/** - * BKTree. - */ -let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); -bktree.search(2, 'three'); - -/** - * BloomFilter. - */ -let bloomfilter = new BloomFilter(45); -bloomfilter.add('hello'); - -/** - * CircularBuffer. - */ -let circularbuffer = new CircularBuffer(Array, 4); -circularbuffer.push('test'); - -/** - * DefaultMap. - */ -let defaultMap = new DefaultMap(() => []); -defaultMap.get('one').push(1); - -/** - * FibonacciHeap. - */ -let fibonacciHeap = new FibonacciHeap(); -fibonacciHeap.push('hello'); -fibonacciHeap.pop(); -let minFibonacciHeap = new MinFibonacciHeap(); -minFibonacciHeap.push('hello'); -minFibonacciHeap.pop(); - -/** - * FixedReverseHeap. - */ -let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); -fixedReverseHeap.push(34); - -/** - * FixedStack. - */ -let fixedStack = new FixedStack(Uint8Array, 4); -fixedStack.push(4); -fixedStack.pop(); - -/** - * FuzzyMap. - */ -let fuzzymap = new FuzzyMap(o => o.title); -fuzzymap.set({title: 'Hello'}, 45); -let fuzzymapadd = new FuzzyMap(o => o.n); -fuzzymapadd.add({title: 'Hello', n: 45}); - -/** - * FuzzyMultiMap. - */ -let fuzzymultimap = new FuzzyMultiMap(o => o.title); -fuzzymultimap.set({title: 'Hello'}, 45); -let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); -fuzzymultimapadd.add({title: 'Hello', n: 45}); - -/** - * HashedArrayTree. - */ -let hashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.push(1); -hashedArrayTree.set(0, 4); - -/** - * Heap. - */ -let heap = new Heap((a, b) => +a - +b); -heap.push('hello'); -heap.pop(); - -let maxHeap = new MaxHeap(); -maxHeap.push(45); - -/** - * InvertedIndex. - */ -let invertedIndex = new InvertedIndex(n => ['one', 'two']); -invertedIndex.add(45); - -/** - * LinkedList. - */ -let linkedlist = new LinkedList(); -linkedlist.push(true); -let linkedlistItem = linkedlist.shift(); - -/** - * LRUCache. - */ -let lrucache = new LRUCache(10); -lrucache.set('one', 34); -let lrucacheItem = lrucache.get('one'); - -/** - * LRUCacheWithDelete - */ -let lrucwd = new LRUCacheWithDelete(10); -lrucwd.set('one', 'uno'); -let lrucwdItem = lrucwd.get('one'); -lrucwdItem = lrucwd.remove('one'); -let lrucwdDead = lrucwd.remove('one', null); -let lrucwdWasRemoved = lrucwd.delete('one'); - -/** - * LRUMap. - */ -let lrumap = new LRUMap(10); -lrumap.set('one', 34); -let lrumapItem = lrumap.get('one'); - -/** - * LRUMapWithDelete - */ -let lrumwd = new LRUMapWithDelete(10); -lrumwd.set('one', 'uno'); -let lrumwdItem = lrumwd.get('one'); -lrumwdItem = lrumwd.remove('one'); -let lrumwdDead = lrumwd.remove('one', null); -let lrumwdWasRemoved = lrumwd.delete('one'); - -/** - * MultiSet. - */ -let multiset = new MultiSet(); -multiset.add(45); -multiset = MultiSet.from([1, 2, 3]); -multiset = MultiSet.from({one: 1}); - -/** - * MultiMap. - */ -let multimap = new MultiMap(Set); -multimap.set(45, 'test'); -multimap.get(45).has('test'); -let stringMultimap = MultiMap.from({one: 1}); -stringMultimap.get('one').indexOf(1); -for (const _ of multimap) { } -for (const _ of multimap.keys()) { } -for (const _ of multimap.values()) { } -for (const _ of multimap.entries()) { } -for (const _ of multimap.containers()) { } -for (const _ of multimap.associations()) { } - -/** - * PassjoinIndex. - */ -const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); - -let passjoinResults = passjoinIndex.search('hello'); - -/** - * Queue. - */ -let queue = new Queue(); - -queue.enqueue(45); -let queueitem = queue.dequeue(); - -queue.enqueue(45); -queue.enqueue(34); - -queue = Queue.from([1, 2, 3]); -queue = Queue.from({0: 1}); - -let queueIterator = queue.values(); - -/** - * set. - */ -let setA = new Set([1, 2, 3]); -let setB = new Set([3, 4, 5]); -let unionOfSets = set.union(setA, setB); - -/** - * SparseSet. - */ -let sparseSet = new SparseSet(45); -sparseSet.add(3); - -/** - * Stack. - */ -let stack = new Stack(); - -stack.push(45); -let stackitem = stack.pop(); - -stack.push(45); -stack.push(34); - -stack = Stack.from([1, 2, 3]); -stack = Stack.from({0: 1}); - -let stackIterator = stack.values(); - -/** - * StaticDisjointSet. - */ -let disjointSet = new StaticDisjointSet(45); -disjointSet.union(3, 5); - -/** - * StaticIntervalTree. - */ -let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); - -/** - * SuffixArray. - */ -let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); -let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); - -/** - * SymSpell. - */ -let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); -let symspellMatches = symspell.search('three'); - -/** - * Trie. - */ -let trie = new Trie(); -trie.add('roman'); - -let trieMatches = trie.find('rom'); - -/** - * TrieMap. - */ -let trieMap = new TrieMap(); -trieMap.set('roman', 45); - -let trieMapMatches = trieMap.find('rom'); - -trieMap = TrieMap.from(new Map([['roman', 45]])); -trieMap = TrieMap.from({roman: 45}); - -let arrayTrieMap = new TrieMap(Array); -arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); - -/** - * Vector. - */ -let vector = new Vector(Uint32Array, 10); -vector.push(1); -vector.set(0, 2); - -let uint16vector = Uint16Vector.from([1, 2, 3]); -uint16vector.pop(); - -/** - * VPTree. - */ -let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/cjs/package.json b/test/cjs/package.json deleted file mode 100644 index 5241c165..00000000 --- a/test/cjs/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "", - "description": "", - "version": "0.1.0", - "dependencies": { - "mnemonist": "file:../.." - } -} diff --git a/test/esm/.gitignore b/test/esm/.gitignore deleted file mode 100644 index d8b83df9..00000000 --- a/test/esm/.gitignore +++ /dev/null @@ -1 +0,0 @@ -package-lock.json diff --git a/test/esm/import.mjs b/test/esm/import.mjs deleted file mode 100644 index 95318f7c..00000000 --- a/test/esm/import.mjs +++ /dev/null @@ -1,325 +0,0 @@ -/* eslint-disable no-empty */ -/* eslint-disable no-unused-vars */ -/** - * Mnemonist ESM Named Import Testing - * =================================== - */ -import { - BiMap, - BitSet, - BitVector, - BKTree, - BloomFilter, - CircularBuffer, - DefaultMap, - FibonacciHeap, MinFibonacciHeap, - FixedReverseHeap, - FixedStack, - FuzzyMap, - FuzzyMultiMap, - HashedArrayTree, - Heap, MaxHeap, - InvertedIndex, - LinkedList, - LRUCache, - LRUCacheWithDelete, - LRUMap, - LRUMapWithDelete, - MultiSet, - MultiMap, - PassjoinIndex, - Queue, - set, - SparseSet, - Stack, - StaticDisjointSet, - StaticIntervalTree, - GeneralizedSuffixArray, - SymSpell, - Trie, - TrieMap, - Vector, Uint16Vector, - VPTree -} from 'mnemonist'; - -/** - * BiMap. - */ -let bimap = new BiMap(); -bimap.set('one', 1); -let inversemap = bimap.inverse; -inversemap.get(1); - -/** - * BitSet. - */ -let bitset = new BitSet(4); -bitset.set(3); - -/** - * BitVector. - */ -let bitvector = new BitVector({initialCapacity: 34}); -bitvector.set(3); - -/** - * BKTree. - */ -let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); -bktree.search(2, 'three'); - -/** - * BloomFilter. - */ -let bloomfilter = new BloomFilter(45); -bloomfilter.add('hello'); - -/** - * CircularBuffer. - */ -let circularbuffer = new CircularBuffer(Array, 4); -circularbuffer.push('test'); - -/** - * DefaultMap. - */ -let defaultMap = new DefaultMap(() => []); -defaultMap.get('one').push(1); - -/** - * FibonacciHeap. - */ -let fibonacciHeap = new FibonacciHeap(); -fibonacciHeap.push('hello'); -fibonacciHeap.pop(); -let minFibonacciHeap = new MinFibonacciHeap(); -minFibonacciHeap.push('hello'); -minFibonacciHeap.pop(); - -/** - * FixedReverseHeap. - */ -let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); -fixedReverseHeap.push(34); - -/** - * FixedStack. - */ -let fixedStack = new FixedStack(Uint8Array, 4); -fixedStack.push(4); -fixedStack.pop(); - -/** - * FuzzyMap. - */ -let fuzzymap = new FuzzyMap(o => o.title); -fuzzymap.set({title: 'Hello'}, 45); -let fuzzymapadd = new FuzzyMap(o => o.n); -fuzzymapadd.add({title: 'Hello', n: 45}); - -/** - * FuzzyMultiMap. - */ -let fuzzymultimap = new FuzzyMultiMap(o => o.title); -fuzzymultimap.set({title: 'Hello'}, 45); -let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); -fuzzymultimapadd.add({title: 'Hello', n: 45}); - -/** - * HashedArrayTree. - */ -let hashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.push(1); -hashedArrayTree.set(0, 4); - -/** - * Heap. - */ -let heap = new Heap((a, b) => +a - +b); -heap.push('hello'); -heap.pop(); - -let maxHeap = new MaxHeap(); -maxHeap.push(45); - -/** - * InvertedIndex. - */ -let invertedIndex = new InvertedIndex(n => ['one', 'two']); -invertedIndex.add(45); - -/** - * LinkedList. - */ -let linkedlist = new LinkedList(); -linkedlist.push(true); -let linkedlistItem = linkedlist.shift(); - -/** - * LRUCache. - */ -let lrucache = new LRUCache(10); -lrucache.set('one', 34); -let lrucacheItem = lrucache.get('one'); - -/** - * LRUCacheWithDelete - */ -let lrucwd = new LRUCacheWithDelete(10); -lrucwd.set('one', 'uno'); -let lrucwdItem = lrucwd.get('one'); -lrucwdItem = lrucwd.remove('one'); -let lrucwdDead = lrucwd.remove('one', null); -let lrucwdWasRemoved = lrucwd.delete('one'); - -/** - * LRUMap. - */ -let lrumap = new LRUMap(10); -lrumap.set('one', 34); -let lrumapItem = lrumap.get('one'); - -/** - * LRUMapWithDelete - */ -let lrumwd = new LRUMapWithDelete(10); -lrumwd.set('one', 'uno'); -let lrumwdItem = lrumwd.get('one'); -lrumwdItem = lrumwd.remove('one'); -let lrumwdDead = lrumwd.remove('one', null); -let lrumwdWasRemoved = lrumwd.delete('one'); - -/** - * MultiSet. - */ -let multiset = new MultiSet(); -multiset.add(45); -multiset = MultiSet.from([1, 2, 3]); -multiset = MultiSet.from({one: 1}); - -/** - * MultiMap. - */ -let multimap = new MultiMap(Set); -multimap.set(45, 'test'); -multimap.get(45).has('test'); -let stringMultimap = MultiMap.from({one: 1}); -stringMultimap.get('one').indexOf(1); -for (const _ of multimap) { } -for (const _ of multimap.keys()) { } -for (const _ of multimap.values()) { } -for (const _ of multimap.entries()) { } -for (const _ of multimap.containers()) { } -for (const _ of multimap.associations()) { } - -/** - * PassjoinIndex. - */ -const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); - -let passjoinResults = passjoinIndex.search('hello'); - -/** - * Queue. - */ -let queue = new Queue(); - -queue.enqueue(45); -let queueitem = queue.dequeue(); - -queue.enqueue(45); -queue.enqueue(34); - -queue = Queue.from([1, 2, 3]); -queue = Queue.from({0: 1}); - -let queueIterator = queue.values(); - -/** - * set. - */ -let setA = new Set([1, 2, 3]); -let setB = new Set([3, 4, 5]); -let unionOfSets = set.union(setA, setB); - -/** - * SparseSet. - */ -let sparseSet = new SparseSet(45); -sparseSet.add(3); - -/** - * Stack. - */ -let stack = new Stack(); - -stack.push(45); -let stackitem = stack.pop(); - -stack.push(45); -stack.push(34); - -stack = Stack.from([1, 2, 3]); -stack = Stack.from({0: 1}); - -let stackIterator = stack.values(); - -/** - * StaticDisjointSet. - */ -let disjointSet = new StaticDisjointSet(45); -disjointSet.union(3, 5); - -/** - * StaticIntervalTree. - */ -let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); - -/** - * SuffixArray. - */ -let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); -let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); - -/** - * SymSpell. - */ -let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); -let symspellMatches = symspell.search('three'); - -/** - * Trie. - */ -let trie = new Trie(); -trie.add('roman'); - -let trieMatches = trie.find('rom'); - -/** - * TrieMap. - */ -let trieMap = new TrieMap(); -trieMap.set('roman', 45); - -let trieMapMatches = trieMap.find('rom'); - -trieMap = TrieMap.from(new Map([['roman', 45]])); -trieMap = TrieMap.from({roman: 45}); - -let arrayTrieMap = new TrieMap(Array); -arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); - -/** - * Vector. - */ -let vector = new Vector(Uint32Array, 10); -vector.push(1); -vector.set(0, 2); - -let uint16vector = Uint16Vector.from([1, 2, 3]); -uint16vector.pop(); - -/** - * VPTree. - */ -let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/esm/package.json b/test/esm/package.json deleted file mode 100644 index abf50c58..00000000 --- a/test/esm/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "", - "description": "", - "type": "module", - "version": "0.1.0", - "dependencies": { - "mnemonist": "file:../.." - } -} diff --git a/test/cjs/.gitignore b/test/exports/.gitignore similarity index 75% rename from test/cjs/.gitignore rename to test/exports/.gitignore index d8b83df9..cdc33a5a 100644 --- a/test/cjs/.gitignore +++ b/test/exports/.gitignore @@ -1 +1,2 @@ package-lock.json +dist/ diff --git a/test/cjs/default-require.js b/test/exports/exports-default-test.cjs similarity index 97% rename from test/cjs/default-require.js rename to test/exports/exports-default-test.cjs index 473f0401..f4d42470 100644 --- a/test/cjs/default-require.js +++ b/test/exports/exports-default-test.cjs @@ -1,7 +1,7 @@ /* eslint-disable no-empty */ /* eslint-disable no-unused-vars */ /** - * Mnemonist CommonJS Default Require Testing + * Mnemonist CommonJS Default Exports Testing * =========================================== */ const BiMap = require('mnemonist/bi-map'); @@ -93,6 +93,10 @@ fibonacciHeap.pop(); let minFibonacciHeap = new FibonacciHeap.MinFibonacciHeap(); minFibonacciHeap.push('hello'); minFibonacciHeap.pop(); +let maxFibonacciHeap = new FibonacciHeap.MaxFibonacciHeap(); +maxFibonacciHeap.push('hello'); +maxFibonacciHeap.pop(); + /** * FixedReverseHeap. @@ -276,6 +280,7 @@ let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); /** * SuffixArray. */ +let suffixArray = new SuffixArray('test'); let generalizedSuffixArray = new SuffixArray.GeneralizedSuffixArray(['test', 'hello']); let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); diff --git a/test/types.ts b/test/exports/exports-named-test.ts similarity index 96% rename from test/types.ts rename to test/exports/exports-named-test.ts index ca5ee36c..1ffd6462 100644 --- a/test/types.ts +++ b/test/exports/exports-named-test.ts @@ -1,6 +1,6 @@ /** - * Mnemonist Types Testing - * ======================== + * Mnemonist Exports Testing + * ========================== */ import { BiMap, InverseMap, @@ -38,7 +38,7 @@ import { TrieMap, Vector, Uint16Vector, VPTree -} from '../index'; +} from 'mnemonist'; /** * BiMap. @@ -90,6 +90,9 @@ defaultMap.get('one').push(1); let fibonacciHeap: FibonacciHeap | MinFibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); +let maxFibonacciHeap: MaxFibonacciHeap = new MaxFibonacciHeap(); +maxFibonacciHeap.push('hello'); +maxFibonacciHeap.pop(); /** * FixedReverseHeap. @@ -274,6 +277,7 @@ let intervalTree: StaticIntervalTree = StaticIntervalTree.from([[0, 1] /** * SuffixArray. */ +let suffixArray: SuffixArray = new SuffixArray('test'); let generalizedSuffixArray: GeneralizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); let suffixArrayLCS: string = generalizedSuffixArray.longestCommonSubsequence() as string; diff --git a/test/exports/package.json b/test/exports/package.json new file mode 100644 index 00000000..6f7413ca --- /dev/null +++ b/test/exports/package.json @@ -0,0 +1,18 @@ +{ + "name": "", + "description": "", + "type": "module", + "version": "0.1.0", + "scripts": { + "build:cjs": "tsc --target es2022 --module commonjs --noImplicitAny --noImplicitReturns --outDir dist/cjs exports-named-test.ts && mv dist/cjs/exports-named-test.js dist/cjs/exports-named-test.cjs", + "build:esm": "tsc --target es2022 --module node16 --noImplicitAny --noImplicitReturns --outDir dist/esm exports-named-test.ts", + "build": "npm run build:cjs && npm run build:esm", + "test": "npm run build && node dist/cjs/exports-named-test.cjs && node dist/esm/exports-named-test.js && node exports-default-test.cjs" + }, + "dependencies": { + "mnemonist": "file:../.." + }, + "devDependencies": { + "typescript": "^5.3.3" + } +} From 89bd465e510729ee44437cf336536e7468dc0931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:12:16 +0100 Subject: [PATCH 23/35] build(deps-dev): remove unneeded typescript dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 59 +++++++++++++++++------------------------------ package.json | 5 ++-- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1713880c..fb714dff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", "asciitree": "^1.0.2", - "damerau-levenshtein": "^1.0.7", + "damerau-levenshtein": "^1.0.8", "eslint": "^8.2.0", "leven": "^3.1.0", "lodash": "^4.17.21", @@ -22,8 +22,7 @@ "mocha": "^9.1.3", "pandemonium": "^2.0.0", "seedrandom": "^3.0.5", - "static-kdtree": "^1.0.2", - "typescript": "^4.5.2" + "static-kdtree": "^1.0.2" } }, "node_modules/@eslint/eslintrc": { @@ -191,7 +190,7 @@ "node_modules/bit-twiddle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", - "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=", + "integrity": "sha512-B9UhK0DKFZhoTFcfvAzhqsjStvGJp9vYWf3+6SNTtdSQnvIgfkHbgHrg/e4+TH71N2GDu8tpmCVoyfrL1d7ntA==", "dev": true }, "node_modules/brace-expansion": { @@ -351,9 +350,9 @@ } }, "node_modules/damerau-levenshtein": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.7.tgz", - "integrity": "sha512-VvdQIPGdWP0SqFXghj79Wf/5LArmreyMsGLa6FG6iC4t3j7j5s71TrwWmT/4akbDQIqjfACkLZmjXhA7g2oUZw==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", + "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, "node_modules/debug": { @@ -578,12 +577,15 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz", - "integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, "node_modules/espree": { @@ -899,7 +901,7 @@ "node_modules/inorder-tree-layout/node_modules/bit-twiddle": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-0.0.2.tgz", - "integrity": "sha1-wurruVKjuUrMFASX4c3NLxoz9Y4=", + "integrity": "sha512-76iFAOrkcuw5UPA30Pt32XaytMHXz/04JembgIwsQAp7ImHYSWNq1shBbrlWf6CUvh1+amQ81LI8hNhqQgsBEw==", "dev": true }, "node_modules/iota-array": { @@ -1674,19 +1676,6 @@ "dup": "^1.0.0" } }, - "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, "node_modules/uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", @@ -1970,7 +1959,7 @@ "bit-twiddle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", - "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=", + "integrity": "sha512-B9UhK0DKFZhoTFcfvAzhqsjStvGJp9vYWf3+6SNTtdSQnvIgfkHbgHrg/e4+TH71N2GDu8tpmCVoyfrL1d7ntA==", "dev": true }, "brace-expansion": { @@ -2100,9 +2089,9 @@ } }, "damerau-levenshtein": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.7.tgz", - "integrity": "sha512-VvdQIPGdWP0SqFXghj79Wf/5LArmreyMsGLa6FG6iC4t3j7j5s71TrwWmT/4akbDQIqjfACkLZmjXhA7g2oUZw==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", + "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, "debug": { @@ -2266,9 +2255,9 @@ } }, "eslint-visitor-keys": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz", - "integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true }, "espree": { @@ -2505,7 +2494,7 @@ "bit-twiddle": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-0.0.2.tgz", - "integrity": "sha1-wurruVKjuUrMFASX4c3NLxoz9Y4=", + "integrity": "sha512-76iFAOrkcuw5UPA30Pt32XaytMHXz/04JembgIwsQAp7ImHYSWNq1shBbrlWf6CUvh1+amQ81LI8hNhqQgsBEw==", "dev": true } } @@ -3081,12 +3070,6 @@ "dup": "^1.0.0" } }, - "typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true - }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", diff --git a/package.json b/package.json index c1fd1420..d9e3a272 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", "asciitree": "^1.0.2", - "damerau-levenshtein": "^1.0.7", + "damerau-levenshtein": "^1.0.8", "eslint": "^8.2.0", "leven": "^3.1.0", "lodash": "^4.17.21", @@ -103,8 +103,7 @@ "mocha": "^9.1.3", "pandemonium": "^2.0.0", "seedrandom": "^3.0.5", - "static-kdtree": "^1.0.2", - "typescript": "^4.5.2" + "static-kdtree": "^1.0.2" }, "eslintConfig": { "extends": "@yomguithereal/eslint-config", From 019592a9cc186af98a5471e82ba69d2f061d8ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:21:48 +0100 Subject: [PATCH 24/35] build(ci): avoid exports testing on node 12.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bea192e8..91666383 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,10 +19,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} @@ -31,4 +31,5 @@ jobs: npm i npm run lint npm test - npm run test:exports + # Typescript does not work with Node 12.x + [[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports From c0c8f82aeecb835140483f8330a2cf321f88cbc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:26:21 +0100 Subject: [PATCH 25/35] build(ci): avoid error > 0 with node 12.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 91666383..42bb306b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,4 +32,4 @@ jobs: npm run lint npm test # Typescript does not work with Node 12.x - [[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports + [[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports || true From aba2f6b64386e054b61e79cbfe91aee94d214fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:30:41 +0100 Subject: [PATCH 26/35] refactor: trivial code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 42bb306b..ff78870e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,5 +31,5 @@ jobs: npm i npm run lint npm test - # Typescript does not work with Node 12.x + # Typescript does not work with node 12.x [[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports || true From 3c9eac4ab03eb1b4e1a4d8f9a27817bdbbcdbedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:36:22 +0100 Subject: [PATCH 27/35] docs: refine code comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/exports/exports-named-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/exports/exports-named-test.ts b/test/exports/exports-named-test.ts index 1ffd6462..e50a4fa4 100644 --- a/test/exports/exports-named-test.ts +++ b/test/exports/exports-named-test.ts @@ -1,6 +1,6 @@ /** - * Mnemonist Exports Testing - * ========================== + * Mnemonist Types and Named Exports Testing + * ========================================== */ import { BiMap, InverseMap, From 616b3ae1abfe2cb5337eef4322c667534d184b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 19:42:44 +0100 Subject: [PATCH 28/35] build: refine eslint ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index 588f0767..3401c82b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -test/*.ts +test/exports/dist/ From 51a4b552f25b8d511c7f9f5743607209c2fa0ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 23:01:06 +0100 Subject: [PATCH 29/35] docs: add changelog entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 488bc9f1..6aa17343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog -## 0.39.8 (provisional) +## Unreleased +* Adding ESM named exports support (@jerome-benoit). +* Fixing `Set` operations CommonJS named export collision with `Set` (@jerome-benoit). +* Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit). * Fixing `Float64Vector` TS exports (@atombrenner). ## 0.39.7 From 724fa26c3b6b9bb531d218bdd578d4d03531aaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 23:11:10 +0100 Subject: [PATCH 30/35] docs: refine changelog entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aa17343..cc2d46c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased * Adding ESM named exports support (@jerome-benoit). -* Fixing `Set` operations CommonJS named export collision with `Set` (@jerome-benoit). +* Fixing `Set` operations CommonJS named export collision by renaming it to ``set` (@jerome-benoit). * Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit). * Fixing `Float64Vector` TS exports (@atombrenner). From 199f2d9ba40f46234bfda9cc004aca4b6ead2cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 23:11:33 +0100 Subject: [PATCH 31/35] docs: fix typo in changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc2d46c0..e93b5cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased * Adding ESM named exports support (@jerome-benoit). -* Fixing `Set` operations CommonJS named export collision by renaming it to ``set` (@jerome-benoit). +* Fixing `Set` operations CommonJS named export collision by renaming it to `set` (@jerome-benoit). * Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit). * Fixing `Float64Vector` TS exports (@atombrenner). From 0715851589300a09abe4910c1fcf358d3b45d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 15 Jan 2024 23:20:27 +0100 Subject: [PATCH 32/35] build(deps): bump obliterator to latest patch version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index fb714dff..8796c6ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.39.7", "license": "MIT", "dependencies": { - "obliterator": "^2.0.1" + "obliterator": "^2.0.4" }, "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", @@ -1268,9 +1268,9 @@ } }, "node_modules/obliterator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.1.tgz", - "integrity": "sha512-XnkiCrrBcIZQitJPAI36mrrpEUvatbte8hLcTcQwKA1v9NkCKasSi+UAguLsLDs/out7MoRzAlmz7VXvY6ph6w==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz", + "integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==" }, "node_modules/once": { "version": "1.4.0", @@ -2781,9 +2781,9 @@ "dev": true }, "obliterator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.1.tgz", - "integrity": "sha512-XnkiCrrBcIZQitJPAI36mrrpEUvatbte8hLcTcQwKA1v9NkCKasSi+UAguLsLDs/out7MoRzAlmz7VXvY6ph6w==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz", + "integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==" }, "once": { "version": "1.4.0", diff --git a/package.json b/package.json index d9e3a272..61ee7b86 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ }, "homepage": "https://github.com/yomguithereal/mnemonist#readme", "dependencies": { - "obliterator": "^2.0.1" + "obliterator": "^2.0.4" }, "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", From e492dea2a715205b1ce77a3fb0ec0586d4f3e648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 16 Jan 2024 15:12:36 +0100 Subject: [PATCH 33/35] test: add missing node types for exports test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/exports/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/exports/package.json b/test/exports/package.json index 6f7413ca..102b29e0 100644 --- a/test/exports/package.json +++ b/test/exports/package.json @@ -13,6 +13,7 @@ "mnemonist": "file:../.." }, "devDependencies": { + "@types/node": "^20.11.4", "typescript": "^5.3.3" } } From fbdc82235d072c0bf73393ba173a7b6ad559459d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 16 Jan 2024 15:23:14 +0100 Subject: [PATCH 34/35] test: add package-lock.json for strict test exports version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- test/exports/.gitignore | 1 - test/exports/package-lock.json | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/exports/package-lock.json diff --git a/test/exports/.gitignore b/test/exports/.gitignore index cdc33a5a..849ddff3 100644 --- a/test/exports/.gitignore +++ b/test/exports/.gitignore @@ -1,2 +1 @@ -package-lock.json dist/ diff --git a/test/exports/package-lock.json b/test/exports/package-lock.json new file mode 100644 index 00000000..7f581a89 --- /dev/null +++ b/test/exports/package-lock.json @@ -0,0 +1,71 @@ +{ + "name": "exports", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "version": "0.1.0", + "dependencies": { + "mnemonist": "file:../.." + }, + "devDependencies": { + "@types/node": "^20.11.4", + "typescript": "^5.3.3" + } + }, + "../..": { + "name": "mnemonist", + "version": "0.39.7", + "license": "MIT", + "dependencies": { + "obliterator": "^2.0.4" + }, + "devDependencies": { + "@yomguithereal/eslint-config": "^4.4.0", + "asciitree": "^1.0.2", + "damerau-levenshtein": "^1.0.8", + "eslint": "^8.2.0", + "leven": "^3.1.0", + "lodash": "^4.17.21", + "matcha": "^0.7.0", + "mocha": "^9.1.3", + "pandemonium": "^2.0.0", + "seedrandom": "^3.0.5", + "static-kdtree": "^1.0.2" + } + }, + "node_modules/@types/node": { + "version": "20.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.4.tgz", + "integrity": "sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/mnemonist": { + "resolved": "../..", + "link": true + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + } + } +} From 6a2010e75442cf19d63563ec9bea2ffc955edce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 16 Jan 2024 15:51:30 +0100 Subject: [PATCH 35/35] fix: add missing PointerVector TS export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 1 + index.d.ts | 2 +- vector.d.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e93b5cf1..10cc7f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Adding ESM named exports support (@jerome-benoit). * Fixing `Set` operations CommonJS named export collision by renaming it to `set` (@jerome-benoit). * Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit). +* Fixing missing `PointerVector` TS exports (@jerome-benoit). * Fixing `Float64Vector` TS exports (@atombrenner). ## 0.39.7 diff --git a/index.d.ts b/index.d.ts index 57654a60..075fefc1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -44,5 +44,5 @@ export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array'; export {default as SymSpell} from './symspell'; export {default as Trie} from './trie'; export {default as TrieMap} from './trie-map'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector'; export {default as VPTree} from './vp-tree'; diff --git a/vector.d.ts b/vector.d.ts index 64c1aa1f..1a56e276 100644 --- a/vector.d.ts +++ b/vector.d.ts @@ -79,3 +79,4 @@ export class Int32Vector extends TypedVector {} export class Uint32Vector extends TypedVector {} export class Float32Vector extends TypedVector {} export class Float64Vector extends TypedVector {} +export class PointerVector extends TypedVector {}