@ac-kit/data 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +75 -0
- package/dist/bit/bit-set.d.ts +84 -0
- package/dist/bit/bit-set.d.ts.map +1 -0
- package/dist/bit/bit-set.js +206 -0
- package/dist/bit/bit-set.js.map +1 -0
- package/dist/bit/bit-vector.d.ts +69 -0
- package/dist/bit/bit-vector.d.ts.map +1 -0
- package/dist/bit/bit-vector.js +172 -0
- package/dist/bit/bit-vector.js.map +1 -0
- package/dist/cache/_lru-store.d.ts +37 -0
- package/dist/cache/_lru-store.d.ts.map +1 -0
- package/dist/cache/_lru-store.js +137 -0
- package/dist/cache/_lru-store.js.map +1 -0
- package/dist/cache/lru-cache.d.ts +90 -0
- package/dist/cache/lru-cache.d.ts.map +1 -0
- package/dist/cache/lru-cache.js +143 -0
- package/dist/cache/lru-cache.js.map +1 -0
- package/dist/cache/lru-map.d.ts +72 -0
- package/dist/cache/lru-map.d.ts.map +1 -0
- package/dist/cache/lru-map.js +100 -0
- package/dist/cache/lru-map.js.map +1 -0
- package/dist/collection/_bounded.d.ts +27 -0
- package/dist/collection/_bounded.d.ts.map +1 -0
- package/dist/collection/_bounded.js +48 -0
- package/dist/collection/_bounded.js.map +1 -0
- package/dist/collection/_capacity-semaphore.d.ts +31 -0
- package/dist/collection/_capacity-semaphore.d.ts.map +1 -0
- package/dist/collection/_capacity-semaphore.js +94 -0
- package/dist/collection/_capacity-semaphore.js.map +1 -0
- package/dist/collection/iasync-collection.d.ts +16 -0
- package/dist/collection/iasync-collection.d.ts.map +1 -0
- package/dist/collection/iasync-collection.js +13 -0
- package/dist/collection/iasync-collection.js.map +1 -0
- package/dist/collection/iasync-searchable.d.ts +9 -0
- package/dist/collection/iasync-searchable.d.ts.map +1 -0
- package/dist/collection/iasync-searchable.js +2 -0
- package/dist/collection/iasync-searchable.js.map +1 -0
- package/dist/collection/ibounded.d.ts +36 -0
- package/dist/collection/ibounded.d.ts.map +1 -0
- package/dist/collection/ibounded.js +8 -0
- package/dist/collection/ibounded.js.map +1 -0
- package/dist/collection/icollection.d.ts +24 -0
- package/dist/collection/icollection.d.ts.map +1 -0
- package/dist/collection/icollection.js +2 -0
- package/dist/collection/icollection.js.map +1 -0
- package/dist/collection/ilossy.d.ts +20 -0
- package/dist/collection/ilossy.d.ts.map +1 -0
- package/dist/collection/ilossy.js +2 -0
- package/dist/collection/ilossy.js.map +1 -0
- package/dist/collection/ireplacing.d.ts +25 -0
- package/dist/collection/ireplacing.d.ts.map +1 -0
- package/dist/collection/ireplacing.js +2 -0
- package/dist/collection/ireplacing.js.map +1 -0
- package/dist/collection/isearchable.d.ts +36 -0
- package/dist/collection/isearchable.d.ts.map +1 -0
- package/dist/collection/isearchable.js +2 -0
- package/dist/collection/isearchable.js.map +1 -0
- package/dist/cursor/ibidirectional-cursor-sequence.d.ts +30 -0
- package/dist/cursor/ibidirectional-cursor-sequence.d.ts.map +1 -0
- package/dist/cursor/ibidirectional-cursor-sequence.js +2 -0
- package/dist/cursor/ibidirectional-cursor-sequence.js.map +1 -0
- package/dist/cursor/ibidirectional-cursor.d.ts +13 -0
- package/dist/cursor/ibidirectional-cursor.d.ts.map +1 -0
- package/dist/cursor/ibidirectional-cursor.js +2 -0
- package/dist/cursor/ibidirectional-cursor.js.map +1 -0
- package/dist/cursor/icursor-sequence.d.ts +48 -0
- package/dist/cursor/icursor-sequence.d.ts.map +1 -0
- package/dist/cursor/icursor-sequence.js +2 -0
- package/dist/cursor/icursor-sequence.js.map +1 -0
- package/dist/cursor/icursor.d.ts +27 -0
- package/dist/cursor/icursor.d.ts.map +1 -0
- package/dist/cursor/icursor.js +2 -0
- package/dist/cursor/icursor.js.map +1 -0
- package/dist/cursor/index-cursor-sequence.d.ts +57 -0
- package/dist/cursor/index-cursor-sequence.d.ts.map +1 -0
- package/dist/cursor/index-cursor-sequence.js +181 -0
- package/dist/cursor/index-cursor-sequence.js.map +1 -0
- package/dist/cursor/irandom-access-cursor.d.ts +16 -0
- package/dist/cursor/irandom-access-cursor.d.ts.map +1 -0
- package/dist/cursor/irandom-access-cursor.js +2 -0
- package/dist/cursor/irandom-access-cursor.js.map +1 -0
- package/dist/deque/blocking-deque.d.ts +36 -0
- package/dist/deque/blocking-deque.d.ts.map +1 -0
- package/dist/deque/blocking-deque.js +101 -0
- package/dist/deque/blocking-deque.js.map +1 -0
- package/dist/deque/bounded-deque.d.ts +58 -0
- package/dist/deque/bounded-deque.d.ts.map +1 -0
- package/dist/deque/bounded-deque.js +103 -0
- package/dist/deque/bounded-deque.js.map +1 -0
- package/dist/deque/deque.d.ts +35 -0
- package/dist/deque/deque.d.ts.map +1 -0
- package/dist/deque/deque.js +62 -0
- package/dist/deque/deque.js.map +1 -0
- package/dist/deque/iasync-deque.d.ts +19 -0
- package/dist/deque/iasync-deque.d.ts.map +1 -0
- package/dist/deque/iasync-deque.js +2 -0
- package/dist/deque/iasync-deque.js.map +1 -0
- package/dist/deque/iasync-lossy-deque.d.ts +11 -0
- package/dist/deque/iasync-lossy-deque.d.ts.map +1 -0
- package/dist/deque/iasync-lossy-deque.js +2 -0
- package/dist/deque/iasync-lossy-deque.js.map +1 -0
- package/dist/deque/ideque-storage.d.ts +6 -0
- package/dist/deque/ideque-storage.d.ts.map +1 -0
- package/dist/deque/ideque-storage.js +2 -0
- package/dist/deque/ideque-storage.js.map +1 -0
- package/dist/deque/ideque.d.ts +72 -0
- package/dist/deque/ideque.d.ts.map +1 -0
- package/dist/deque/ideque.js +2 -0
- package/dist/deque/ideque.js.map +1 -0
- package/dist/deque/ilossy-deque.d.ts +42 -0
- package/dist/deque/ilossy-deque.d.ts.map +1 -0
- package/dist/deque/ilossy-deque.js +2 -0
- package/dist/deque/ilossy-deque.js.map +1 -0
- package/dist/deque/iwaitable-deque.d.ts +42 -0
- package/dist/deque/iwaitable-deque.d.ts.map +1 -0
- package/dist/deque/iwaitable-deque.js +2 -0
- package/dist/deque/iwaitable-deque.js.map +1 -0
- package/dist/disjoint-set/iasync-disjoint-set.d.ts +11 -0
- package/dist/disjoint-set/iasync-disjoint-set.d.ts.map +1 -0
- package/dist/disjoint-set/iasync-disjoint-set.js +2 -0
- package/dist/disjoint-set/iasync-disjoint-set.js.map +1 -0
- package/dist/disjoint-set/idisjoint-set.d.ts +11 -0
- package/dist/disjoint-set/idisjoint-set.d.ts.map +1 -0
- package/dist/disjoint-set/idisjoint-set.js +2 -0
- package/dist/disjoint-set/idisjoint-set.js.map +1 -0
- package/dist/disjoint-set/static-disjoint-set.d.ts +67 -0
- package/dist/disjoint-set/static-disjoint-set.d.ts.map +1 -0
- package/dist/disjoint-set/static-disjoint-set.js +146 -0
- package/dist/disjoint-set/static-disjoint-set.js.map +1 -0
- package/dist/fuzzy/fuzzy-map.d.ts +62 -0
- package/dist/fuzzy/fuzzy-map.d.ts.map +1 -0
- package/dist/fuzzy/fuzzy-map.js +91 -0
- package/dist/fuzzy/fuzzy-map.js.map +1 -0
- package/dist/fuzzy/fuzzy-multi-map.d.ts +62 -0
- package/dist/fuzzy/fuzzy-multi-map.d.ts.map +1 -0
- package/dist/fuzzy/fuzzy-multi-map.js +143 -0
- package/dist/fuzzy/fuzzy-multi-map.js.map +1 -0
- package/dist/graph/directed-graph.d.ts +78 -0
- package/dist/graph/directed-graph.d.ts.map +1 -0
- package/dist/graph/directed-graph.js +165 -0
- package/dist/graph/directed-graph.js.map +1 -0
- package/dist/graph/graph.d.ts +73 -0
- package/dist/graph/graph.d.ts.map +1 -0
- package/dist/graph/graph.js +145 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/iasync-directed-graph.d.ts +10 -0
- package/dist/graph/iasync-directed-graph.d.ts.map +1 -0
- package/dist/graph/iasync-directed-graph.js +2 -0
- package/dist/graph/iasync-directed-graph.js.map +1 -0
- package/dist/graph/iasync-graph.d.ts +19 -0
- package/dist/graph/iasync-graph.d.ts.map +1 -0
- package/dist/graph/iasync-graph.js +2 -0
- package/dist/graph/iasync-graph.js.map +1 -0
- package/dist/graph/idirected-graph.d.ts +10 -0
- package/dist/graph/idirected-graph.d.ts.map +1 -0
- package/dist/graph/idirected-graph.js +2 -0
- package/dist/graph/idirected-graph.js.map +1 -0
- package/dist/graph/igraph.d.ts +25 -0
- package/dist/graph/igraph.d.ts.map +1 -0
- package/dist/graph/igraph.js +2 -0
- package/dist/graph/igraph.js.map +1 -0
- package/dist/heap/_array-heap.d.ts +12 -0
- package/dist/heap/_array-heap.d.ts.map +1 -0
- package/dist/heap/_array-heap.js +74 -0
- package/dist/heap/_array-heap.js.map +1 -0
- package/dist/heap/binary-heap.d.ts +29 -0
- package/dist/heap/binary-heap.d.ts.map +1 -0
- package/dist/heap/binary-heap.js +83 -0
- package/dist/heap/binary-heap.js.map +1 -0
- package/dist/heap/blocking-binary-heap.d.ts +34 -0
- package/dist/heap/blocking-binary-heap.d.ts.map +1 -0
- package/dist/heap/blocking-binary-heap.js +84 -0
- package/dist/heap/blocking-binary-heap.js.map +1 -0
- package/dist/heap/bounded-binary-heap.d.ts +42 -0
- package/dist/heap/bounded-binary-heap.d.ts.map +1 -0
- package/dist/heap/bounded-binary-heap.js +71 -0
- package/dist/heap/bounded-binary-heap.js.map +1 -0
- package/dist/heap/iasync-heap.d.ts +19 -0
- package/dist/heap/iasync-heap.d.ts.map +1 -0
- package/dist/heap/iasync-heap.js +2 -0
- package/dist/heap/iasync-heap.js.map +1 -0
- package/dist/heap/iasync-lossy-heap.d.ts +9 -0
- package/dist/heap/iasync-lossy-heap.d.ts.map +1 -0
- package/dist/heap/iasync-lossy-heap.js +2 -0
- package/dist/heap/iasync-lossy-heap.js.map +1 -0
- package/dist/heap/iheap-storage.d.ts +5 -0
- package/dist/heap/iheap-storage.d.ts.map +1 -0
- package/dist/heap/iheap-storage.js +2 -0
- package/dist/heap/iheap-storage.js.map +1 -0
- package/dist/heap/iheap.d.ts +51 -0
- package/dist/heap/iheap.d.ts.map +1 -0
- package/dist/heap/iheap.js +2 -0
- package/dist/heap/iheap.js.map +1 -0
- package/dist/heap/ilossy-heap.d.ts +28 -0
- package/dist/heap/ilossy-heap.d.ts.map +1 -0
- package/dist/heap/ilossy-heap.js +2 -0
- package/dist/heap/ilossy-heap.js.map +1 -0
- package/dist/heap/iwaitable-heap.d.ts +27 -0
- package/dist/heap/iwaitable-heap.d.ts.map +1 -0
- package/dist/heap/iwaitable-heap.js +2 -0
- package/dist/heap/iwaitable-heap.js.map +1 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/interval/iasync-interval-index.d.ts +8 -0
- package/dist/interval/iasync-interval-index.d.ts.map +1 -0
- package/dist/interval/iasync-interval-index.js +2 -0
- package/dist/interval/iasync-interval-index.js.map +1 -0
- package/dist/interval/iinterval-index.d.ts +8 -0
- package/dist/interval/iinterval-index.d.ts.map +1 -0
- package/dist/interval/iinterval-index.js +2 -0
- package/dist/interval/iinterval-index.js.map +1 -0
- package/dist/interval/static-interval-tree.d.ts +65 -0
- package/dist/interval/static-interval-tree.d.ts.map +1 -0
- package/dist/interval/static-interval-tree.js +170 -0
- package/dist/interval/static-interval-tree.js.map +1 -0
- package/dist/list/_bounded-list.d.ts +14 -0
- package/dist/list/_bounded-list.d.ts.map +1 -0
- package/dist/list/_bounded-list.js +23 -0
- package/dist/list/_bounded-list.js.map +1 -0
- package/dist/list/array-list.d.ts +56 -0
- package/dist/list/array-list.d.ts.map +1 -0
- package/dist/list/array-list.js +198 -0
- package/dist/list/array-list.js.map +1 -0
- package/dist/list/blocking-array-list.d.ts +55 -0
- package/dist/list/blocking-array-list.d.ts.map +1 -0
- package/dist/list/blocking-array-list.js +190 -0
- package/dist/list/blocking-array-list.js.map +1 -0
- package/dist/list/blocking-circular-array-list.d.ts +61 -0
- package/dist/list/blocking-circular-array-list.d.ts.map +1 -0
- package/dist/list/blocking-circular-array-list.js +211 -0
- package/dist/list/blocking-circular-array-list.js.map +1 -0
- package/dist/list/blocking-doubly-linked-list.d.ts +59 -0
- package/dist/list/blocking-doubly-linked-list.d.ts.map +1 -0
- package/dist/list/blocking-doubly-linked-list.js +211 -0
- package/dist/list/blocking-doubly-linked-list.js.map +1 -0
- package/dist/list/blocking-linked-list.d.ts +50 -0
- package/dist/list/blocking-linked-list.d.ts.map +1 -0
- package/dist/list/blocking-linked-list.js +172 -0
- package/dist/list/blocking-linked-list.js.map +1 -0
- package/dist/list/bounded-array-list.d.ts +47 -0
- package/dist/list/bounded-array-list.d.ts.map +1 -0
- package/dist/list/bounded-array-list.js +108 -0
- package/dist/list/bounded-array-list.js.map +1 -0
- package/dist/list/bounded-circular-array-list.d.ts +54 -0
- package/dist/list/bounded-circular-array-list.d.ts.map +1 -0
- package/dist/list/bounded-circular-array-list.js +123 -0
- package/dist/list/bounded-circular-array-list.js.map +1 -0
- package/dist/list/bounded-doubly-linked-list.d.ts +52 -0
- package/dist/list/bounded-doubly-linked-list.d.ts.map +1 -0
- package/dist/list/bounded-doubly-linked-list.js +123 -0
- package/dist/list/bounded-doubly-linked-list.js.map +1 -0
- package/dist/list/bounded-linked-list.d.ts +42 -0
- package/dist/list/bounded-linked-list.d.ts.map +1 -0
- package/dist/list/bounded-linked-list.js +97 -0
- package/dist/list/bounded-linked-list.js.map +1 -0
- package/dist/list/circular-array-list.d.ts +77 -0
- package/dist/list/circular-array-list.d.ts.map +1 -0
- package/dist/list/circular-array-list.js +322 -0
- package/dist/list/circular-array-list.js.map +1 -0
- package/dist/list/doubly-linked-list.d.ts +113 -0
- package/dist/list/doubly-linked-list.d.ts.map +1 -0
- package/dist/list/doubly-linked-list.js +453 -0
- package/dist/list/doubly-linked-list.js.map +1 -0
- package/dist/list/iasync-list.d.ts +17 -0
- package/dist/list/iasync-list.d.ts.map +1 -0
- package/dist/list/iasync-list.js +2 -0
- package/dist/list/iasync-list.js.map +1 -0
- package/dist/list/ilist-storage.d.ts +9 -0
- package/dist/list/ilist-storage.d.ts.map +1 -0
- package/dist/list/ilist-storage.js +2 -0
- package/dist/list/ilist-storage.js.map +1 -0
- package/dist/list/ilist.d.ts +118 -0
- package/dist/list/ilist.d.ts.map +1 -0
- package/dist/list/ilist.js +8 -0
- package/dist/list/ilist.js.map +1 -0
- package/dist/list/iwaitable-list.d.ts +47 -0
- package/dist/list/iwaitable-list.d.ts.map +1 -0
- package/dist/list/iwaitable-list.js +2 -0
- package/dist/list/iwaitable-list.js.map +1 -0
- package/dist/list/linked-list.d.ts +102 -0
- package/dist/list/linked-list.d.ts.map +1 -0
- package/dist/list/linked-list.js +377 -0
- package/dist/list/linked-list.js.map +1 -0
- package/dist/map/iasync-map.d.ts +13 -0
- package/dist/map/iasync-map.d.ts.map +1 -0
- package/dist/map/iasync-map.js +2 -0
- package/dist/map/iasync-map.js.map +1 -0
- package/dist/map/iasync-replacing-map.d.ts +8 -0
- package/dist/map/iasync-replacing-map.d.ts.map +1 -0
- package/dist/map/iasync-replacing-map.js +2 -0
- package/dist/map/iasync-replacing-map.js.map +1 -0
- package/dist/map/iasync-sorted-map.d.ts +12 -0
- package/dist/map/iasync-sorted-map.d.ts.map +1 -0
- package/dist/map/iasync-sorted-map.js +2 -0
- package/dist/map/iasync-sorted-map.js.map +1 -0
- package/dist/map/imap.d.ts +20 -0
- package/dist/map/imap.d.ts.map +1 -0
- package/dist/map/imap.js +2 -0
- package/dist/map/imap.js.map +1 -0
- package/dist/map/ireplacing-map.d.ts +19 -0
- package/dist/map/ireplacing-map.d.ts.map +1 -0
- package/dist/map/ireplacing-map.js +2 -0
- package/dist/map/ireplacing-map.js.map +1 -0
- package/dist/map/isorted-map.d.ts +23 -0
- package/dist/map/isorted-map.d.ts.map +1 -0
- package/dist/map/isorted-map.js +2 -0
- package/dist/map/isorted-map.js.map +1 -0
- package/dist/multimap/iasync-multimap.d.ts +16 -0
- package/dist/multimap/iasync-multimap.d.ts.map +1 -0
- package/dist/multimap/iasync-multimap.js +2 -0
- package/dist/multimap/iasync-multimap.js.map +1 -0
- package/dist/multimap/imultimap.d.ts +28 -0
- package/dist/multimap/imultimap.d.ts.map +1 -0
- package/dist/multimap/imultimap.js +2 -0
- package/dist/multimap/imultimap.js.map +1 -0
- package/dist/multimap/inverted-index.d.ts +90 -0
- package/dist/multimap/inverted-index.d.ts.map +1 -0
- package/dist/multimap/inverted-index.js +234 -0
- package/dist/multimap/inverted-index.js.map +1 -0
- package/dist/multimap/multi-map.d.ts +63 -0
- package/dist/multimap/multi-map.d.ts.map +1 -0
- package/dist/multimap/multi-map.js +146 -0
- package/dist/multimap/multi-map.js.map +1 -0
- package/dist/multiset/iasync-multiset.d.ts +13 -0
- package/dist/multiset/iasync-multiset.d.ts.map +1 -0
- package/dist/multiset/iasync-multiset.js +2 -0
- package/dist/multiset/iasync-multiset.js.map +1 -0
- package/dist/multiset/imultiset.d.ts +22 -0
- package/dist/multiset/imultiset.d.ts.map +1 -0
- package/dist/multiset/imultiset.js +2 -0
- package/dist/multiset/imultiset.js.map +1 -0
- package/dist/multiset/multi-set.d.ts +66 -0
- package/dist/multiset/multi-set.d.ts.map +1 -0
- package/dist/multiset/multi-set.js +124 -0
- package/dist/multiset/multi-set.js.map +1 -0
- package/dist/ordered-range/iasync-ordered-range.d.ts +15 -0
- package/dist/ordered-range/iasync-ordered-range.d.ts.map +1 -0
- package/dist/ordered-range/iasync-ordered-range.js +2 -0
- package/dist/ordered-range/iasync-ordered-range.js.map +1 -0
- package/dist/ordered-range/iordered-range.d.ts +28 -0
- package/dist/ordered-range/iordered-range.d.ts.map +1 -0
- package/dist/ordered-range/iordered-range.js +2 -0
- package/dist/ordered-range/iordered-range.js.map +1 -0
- package/dist/priority-queue/blocking-priority-queue.d.ts +37 -0
- package/dist/priority-queue/blocking-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/blocking-priority-queue.js +87 -0
- package/dist/priority-queue/blocking-priority-queue.js.map +1 -0
- package/dist/priority-queue/bounded-priority-queue.d.ts +45 -0
- package/dist/priority-queue/bounded-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/bounded-priority-queue.js +71 -0
- package/dist/priority-queue/bounded-priority-queue.js.map +1 -0
- package/dist/priority-queue/iasync-lossy-priority-queue.d.ts +9 -0
- package/dist/priority-queue/iasync-lossy-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/iasync-lossy-priority-queue.js +2 -0
- package/dist/priority-queue/iasync-lossy-priority-queue.js.map +1 -0
- package/dist/priority-queue/iasync-priority-queue.d.ts +21 -0
- package/dist/priority-queue/iasync-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/iasync-priority-queue.js +2 -0
- package/dist/priority-queue/iasync-priority-queue.js.map +1 -0
- package/dist/priority-queue/ilossy-priority-queue.d.ts +29 -0
- package/dist/priority-queue/ilossy-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/ilossy-priority-queue.js +2 -0
- package/dist/priority-queue/ilossy-priority-queue.js.map +1 -0
- package/dist/priority-queue/ipriority-queue.d.ts +71 -0
- package/dist/priority-queue/ipriority-queue.d.ts.map +1 -0
- package/dist/priority-queue/ipriority-queue.js +2 -0
- package/dist/priority-queue/ipriority-queue.js.map +1 -0
- package/dist/priority-queue/iwaitable-priority-queue.d.ts +27 -0
- package/dist/priority-queue/iwaitable-priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/iwaitable-priority-queue.js +2 -0
- package/dist/priority-queue/iwaitable-priority-queue.js.map +1 -0
- package/dist/priority-queue/priority-queue.d.ts +49 -0
- package/dist/priority-queue/priority-queue.d.ts.map +1 -0
- package/dist/priority-queue/priority-queue.js +134 -0
- package/dist/priority-queue/priority-queue.js.map +1 -0
- package/dist/probabilistic/bloom-filter.d.ts +92 -0
- package/dist/probabilistic/bloom-filter.d.ts.map +1 -0
- package/dist/probabilistic/bloom-filter.js +156 -0
- package/dist/probabilistic/bloom-filter.js.map +1 -0
- package/dist/probabilistic/count-min-sketch.d.ts +76 -0
- package/dist/probabilistic/count-min-sketch.d.ts.map +1 -0
- package/dist/probabilistic/count-min-sketch.js +119 -0
- package/dist/probabilistic/count-min-sketch.js.map +1 -0
- package/dist/probabilistic/cuckoo-filter.d.ts +106 -0
- package/dist/probabilistic/cuckoo-filter.d.ts.map +1 -0
- package/dist/probabilistic/cuckoo-filter.js +214 -0
- package/dist/probabilistic/cuckoo-filter.js.map +1 -0
- package/dist/probabilistic/hash32.d.ts +28 -0
- package/dist/probabilistic/hash32.d.ts.map +1 -0
- package/dist/probabilistic/hash32.js +2 -0
- package/dist/probabilistic/hash32.js.map +1 -0
- package/dist/probabilistic/hyper-log-log.d.ts +74 -0
- package/dist/probabilistic/hyper-log-log.d.ts.map +1 -0
- package/dist/probabilistic/hyper-log-log.js +134 -0
- package/dist/probabilistic/hyper-log-log.js.map +1 -0
- package/dist/probabilistic/top-k.d.ts +62 -0
- package/dist/probabilistic/top-k.d.ts.map +1 -0
- package/dist/probabilistic/top-k.js +104 -0
- package/dist/probabilistic/top-k.js.map +1 -0
- package/dist/queue/blocking-queue.d.ts +32 -0
- package/dist/queue/blocking-queue.d.ts.map +1 -0
- package/dist/queue/blocking-queue.js +70 -0
- package/dist/queue/blocking-queue.js.map +1 -0
- package/dist/queue/bounded-queue.d.ts +47 -0
- package/dist/queue/bounded-queue.d.ts.map +1 -0
- package/dist/queue/bounded-queue.js +64 -0
- package/dist/queue/bounded-queue.js.map +1 -0
- package/dist/queue/iasync-lossy-queue.d.ts +15 -0
- package/dist/queue/iasync-lossy-queue.d.ts.map +1 -0
- package/dist/queue/iasync-lossy-queue.js +2 -0
- package/dist/queue/iasync-lossy-queue.js.map +1 -0
- package/dist/queue/iasync-queue.d.ts +17 -0
- package/dist/queue/iasync-queue.d.ts.map +1 -0
- package/dist/queue/iasync-queue.js +2 -0
- package/dist/queue/iasync-queue.js.map +1 -0
- package/dist/queue/ilossy-queue.d.ts +28 -0
- package/dist/queue/ilossy-queue.d.ts.map +1 -0
- package/dist/queue/ilossy-queue.js +2 -0
- package/dist/queue/ilossy-queue.js.map +1 -0
- package/dist/queue/iqueue-storage.d.ts +5 -0
- package/dist/queue/iqueue-storage.d.ts.map +1 -0
- package/dist/queue/iqueue-storage.js +2 -0
- package/dist/queue/iqueue-storage.js.map +1 -0
- package/dist/queue/iqueue.d.ts +41 -0
- package/dist/queue/iqueue.d.ts.map +1 -0
- package/dist/queue/iqueue.js +2 -0
- package/dist/queue/iqueue.js.map +1 -0
- package/dist/queue/iwaitable-queue.d.ts +27 -0
- package/dist/queue/iwaitable-queue.d.ts.map +1 -0
- package/dist/queue/iwaitable-queue.js +2 -0
- package/dist/queue/iwaitable-queue.js.map +1 -0
- package/dist/queue/lossy-queue.d.ts +33 -0
- package/dist/queue/lossy-queue.d.ts.map +1 -0
- package/dist/queue/lossy-queue.js +75 -0
- package/dist/queue/lossy-queue.js.map +1 -0
- package/dist/queue/queue.d.ts +27 -0
- package/dist/queue/queue.d.ts.map +1 -0
- package/dist/queue/queue.js +43 -0
- package/dist/queue/queue.js.map +1 -0
- package/dist/set/enhanced-set.d.ts +68 -0
- package/dist/set/enhanced-set.d.ts.map +1 -0
- package/dist/set/enhanced-set.js +169 -0
- package/dist/set/enhanced-set.js.map +1 -0
- package/dist/set/iasync-replacing-set.d.ts +8 -0
- package/dist/set/iasync-replacing-set.d.ts.map +1 -0
- package/dist/set/iasync-replacing-set.js +2 -0
- package/dist/set/iasync-replacing-set.js.map +1 -0
- package/dist/set/iasync-set.d.ts +16 -0
- package/dist/set/iasync-set.d.ts.map +1 -0
- package/dist/set/iasync-set.js +2 -0
- package/dist/set/iasync-set.js.map +1 -0
- package/dist/set/iasync-sorted-set.d.ts +7 -0
- package/dist/set/iasync-sorted-set.d.ts.map +1 -0
- package/dist/set/iasync-sorted-set.js +2 -0
- package/dist/set/iasync-sorted-set.js.map +1 -0
- package/dist/set/ireplacing-set.d.ts +24 -0
- package/dist/set/ireplacing-set.d.ts.map +1 -0
- package/dist/set/ireplacing-set.js +2 -0
- package/dist/set/ireplacing-set.js.map +1 -0
- package/dist/set/iset.d.ts +30 -0
- package/dist/set/iset.d.ts.map +1 -0
- package/dist/set/iset.js +2 -0
- package/dist/set/iset.js.map +1 -0
- package/dist/set/isorted-set.d.ts +7 -0
- package/dist/set/isorted-set.d.ts.map +1 -0
- package/dist/set/isorted-set.js +2 -0
- package/dist/set/isorted-set.js.map +1 -0
- package/dist/similarity/iasync-similarity-index.d.ts +8 -0
- package/dist/similarity/iasync-similarity-index.d.ts.map +1 -0
- package/dist/similarity/iasync-similarity-index.js +2 -0
- package/dist/similarity/iasync-similarity-index.js.map +1 -0
- package/dist/similarity/isimilarity-index.d.ts +8 -0
- package/dist/similarity/isimilarity-index.d.ts.map +1 -0
- package/dist/similarity/isimilarity-index.js +2 -0
- package/dist/similarity/isimilarity-index.js.map +1 -0
- package/dist/similarity/vp-tree.d.ts +71 -0
- package/dist/similarity/vp-tree.d.ts.map +1 -0
- package/dist/similarity/vp-tree.js +172 -0
- package/dist/similarity/vp-tree.js.map +1 -0
- package/dist/stack/blocking-stack.d.ts +30 -0
- package/dist/stack/blocking-stack.d.ts.map +1 -0
- package/dist/stack/blocking-stack.js +68 -0
- package/dist/stack/blocking-stack.js.map +1 -0
- package/dist/stack/bounded-stack.d.ts +38 -0
- package/dist/stack/bounded-stack.d.ts.map +1 -0
- package/dist/stack/bounded-stack.js +55 -0
- package/dist/stack/bounded-stack.js.map +1 -0
- package/dist/stack/iasync-lossy-stack.d.ts +9 -0
- package/dist/stack/iasync-lossy-stack.d.ts.map +1 -0
- package/dist/stack/iasync-lossy-stack.js +2 -0
- package/dist/stack/iasync-lossy-stack.js.map +1 -0
- package/dist/stack/iasync-stack.d.ts +15 -0
- package/dist/stack/iasync-stack.d.ts.map +1 -0
- package/dist/stack/iasync-stack.js +2 -0
- package/dist/stack/iasync-stack.js.map +1 -0
- package/dist/stack/ilossy-stack.d.ts +28 -0
- package/dist/stack/ilossy-stack.d.ts.map +1 -0
- package/dist/stack/ilossy-stack.js +2 -0
- package/dist/stack/ilossy-stack.js.map +1 -0
- package/dist/stack/istack-storage.d.ts +5 -0
- package/dist/stack/istack-storage.d.ts.map +1 -0
- package/dist/stack/istack-storage.js +2 -0
- package/dist/stack/istack-storage.js.map +1 -0
- package/dist/stack/istack.d.ts +41 -0
- package/dist/stack/istack.d.ts.map +1 -0
- package/dist/stack/istack.js +2 -0
- package/dist/stack/istack.js.map +1 -0
- package/dist/stack/iwaitable-stack.d.ts +26 -0
- package/dist/stack/iwaitable-stack.d.ts.map +1 -0
- package/dist/stack/iwaitable-stack.js +2 -0
- package/dist/stack/iwaitable-stack.js.map +1 -0
- package/dist/stack/stack.d.ts +26 -0
- package/dist/stack/stack.d.ts.map +1 -0
- package/dist/stack/stack.js +42 -0
- package/dist/stack/stack.js.map +1 -0
- package/dist/storage/iindexed-storage.d.ts +8 -0
- package/dist/storage/iindexed-storage.d.ts.map +1 -0
- package/dist/storage/iindexed-storage.js +2 -0
- package/dist/storage/iindexed-storage.js.map +1 -0
- package/dist/storage/ipop-back-storage.d.ts +8 -0
- package/dist/storage/ipop-back-storage.d.ts.map +1 -0
- package/dist/storage/ipop-back-storage.js +2 -0
- package/dist/storage/ipop-back-storage.js.map +1 -0
- package/dist/storage/ipop-front-storage.d.ts +8 -0
- package/dist/storage/ipop-front-storage.d.ts.map +1 -0
- package/dist/storage/ipop-front-storage.js +2 -0
- package/dist/storage/ipop-front-storage.js.map +1 -0
- package/dist/storage/ipush-back-storage.d.ts +7 -0
- package/dist/storage/ipush-back-storage.d.ts.map +1 -0
- package/dist/storage/ipush-back-storage.js +2 -0
- package/dist/storage/ipush-back-storage.js.map +1 -0
- package/dist/storage/ipush-front-storage.d.ts +7 -0
- package/dist/storage/ipush-front-storage.d.ts.map +1 -0
- package/dist/storage/ipush-front-storage.js +2 -0
- package/dist/storage/ipush-front-storage.js.map +1 -0
- package/dist/storage/istorage.d.ts +13 -0
- package/dist/storage/istorage.d.ts.map +1 -0
- package/dist/storage/istorage.js +2 -0
- package/dist/storage/istorage.js.map +1 -0
- package/dist/storage/ring-vector.d.ts +59 -0
- package/dist/storage/ring-vector.d.ts.map +1 -0
- package/dist/storage/ring-vector.js +192 -0
- package/dist/storage/ring-vector.js.map +1 -0
- package/dist/storage/segmented-ring-vector.d.ts +42 -0
- package/dist/storage/segmented-ring-vector.d.ts.map +1 -0
- package/dist/storage/segmented-ring-vector.js +142 -0
- package/dist/storage/segmented-ring-vector.js.map +1 -0
- package/dist/storage/typed-vector.d.ts +67 -0
- package/dist/storage/typed-vector.d.ts.map +1 -0
- package/dist/storage/typed-vector.js +123 -0
- package/dist/storage/typed-vector.js.map +1 -0
- package/dist/substring/generalized-suffix-array.d.ts +43 -0
- package/dist/substring/generalized-suffix-array.d.ts.map +1 -0
- package/dist/substring/generalized-suffix-array.js +100 -0
- package/dist/substring/generalized-suffix-array.js.map +1 -0
- package/dist/substring/iasync-substring-index.d.ts +6 -0
- package/dist/substring/iasync-substring-index.d.ts.map +1 -0
- package/dist/substring/iasync-substring-index.js +2 -0
- package/dist/substring/iasync-substring-index.js.map +1 -0
- package/dist/substring/isubstring-index.d.ts +6 -0
- package/dist/substring/isubstring-index.d.ts.map +1 -0
- package/dist/substring/isubstring-index.js +2 -0
- package/dist/substring/isubstring-index.js.map +1 -0
- package/dist/substring/suffix-array.d.ts +45 -0
- package/dist/substring/suffix-array.d.ts.map +1 -0
- package/dist/substring/suffix-array.js +164 -0
- package/dist/substring/suffix-array.js.map +1 -0
- package/dist/tree/avl-tree.d.ts +43 -0
- package/dist/tree/avl-tree.d.ts.map +1 -0
- package/dist/tree/avl-tree.js +98 -0
- package/dist/tree/avl-tree.js.map +1 -0
- package/dist/tree/binary-search-tree.d.ts +94 -0
- package/dist/tree/binary-search-tree.d.ts.map +1 -0
- package/dist/tree/binary-search-tree.js +303 -0
- package/dist/tree/binary-search-tree.js.map +1 -0
- package/dist/tree/iavl-tree-node.d.ts +6 -0
- package/dist/tree/iavl-tree-node.d.ts.map +1 -0
- package/dist/tree/iavl-tree-node.js +2 -0
- package/dist/tree/iavl-tree-node.js.map +1 -0
- package/dist/tree/isearch-tree.d.ts +14 -0
- package/dist/tree/isearch-tree.d.ts.map +1 -0
- package/dist/tree/isearch-tree.js +2 -0
- package/dist/tree/isearch-tree.js.map +1 -0
- package/dist/trie/iasync-trie.d.ts +9 -0
- package/dist/trie/iasync-trie.d.ts.map +1 -0
- package/dist/trie/iasync-trie.js +2 -0
- package/dist/trie/iasync-trie.js.map +1 -0
- package/dist/trie/itrie.d.ts +9 -0
- package/dist/trie/itrie.d.ts.map +1 -0
- package/dist/trie/itrie.js +2 -0
- package/dist/trie/itrie.js.map +1 -0
- package/dist/trie/trie.d.ts +93 -0
- package/dist/trie/trie.d.ts.map +1 -0
- package/dist/trie/trie.js +190 -0
- package/dist/trie/trie.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom-filter.d.ts","sourceRoot":"","sources":["../../src/probabilistic/bloom-filter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IACnC,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAEhB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,KAAK,CAAK;IAElB,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YACC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,EACjC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAoC9B;IAED;;;OAGG;IACH,KAAK,IAAI,MAAM,CAEd;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,yDAAyD;IACzD,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAmBjB;IAED,qCAAqC;IACrC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAI/B;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAapB;IAED;;;;;;OAMG;IACH,0BAA0B,IAAI,MAAM,CAQnC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAiBjC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAK;CAGb"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { popCount32 } from "@ac-kit/core";
|
|
2
|
+
const BITS_PER_WORD = 32;
|
|
3
|
+
const WORD_SHIFT = 5;
|
|
4
|
+
const WORD_MASK = BITS_PER_WORD - 1;
|
|
5
|
+
/**
|
|
6
|
+
* Approximate set membership in a fraction of the space an exact set needs.
|
|
7
|
+
*
|
|
8
|
+
* `has` has **no false negatives and does have false positives**: "no" is
|
|
9
|
+
* certain, "yes" means "probably". That asymmetry is the whole point — it makes
|
|
10
|
+
* a Bloom filter a safe front door for an expensive exact lookup, never a
|
|
11
|
+
* replacement for one.
|
|
12
|
+
*
|
|
13
|
+
* There is no `delete`: clearing a bit would clear it for every other item that
|
|
14
|
+
* happens to hash onto it, turning "no false negatives" into a lie. Use
|
|
15
|
+
* `CuckooFilter` when deletion is needed.
|
|
16
|
+
*
|
|
17
|
+
* Sizing follows the standard derivation from `expectedItems` (n) and
|
|
18
|
+
* `falsePositiveRate` (p): `m = ceil(-n·ln p / (ln 2)²)` bits and `k =
|
|
19
|
+
* round((m/n)·ln 2)` hashes, which is the k that minimises p for that m.
|
|
20
|
+
* Exceeding `expectedItems` does not break the filter, it just raises the real
|
|
21
|
+
* false-positive rate above the one asked for — `estimatedFalsePositiveRate()`
|
|
22
|
+
* reports where it actually stands.
|
|
23
|
+
*
|
|
24
|
+
* The `k` hashes come from two calls to the caller's `hash` combined as `h1 +
|
|
25
|
+
* i·h2` (Kirsch–Mitzenmacher), which is proven to cost nothing in accuracy
|
|
26
|
+
* versus `k` independent hashes.
|
|
27
|
+
*
|
|
28
|
+
* Time complexity: O(k) for `add` and `has`, independent of how many items are
|
|
29
|
+
* held. Space: `m` bits regardless of item size.
|
|
30
|
+
*
|
|
31
|
+
* @template T The item type.
|
|
32
|
+
*/
|
|
33
|
+
export class BloomFilter {
|
|
34
|
+
words;
|
|
35
|
+
hash;
|
|
36
|
+
added = 0;
|
|
37
|
+
/** Bits in the filter. */
|
|
38
|
+
bitCount;
|
|
39
|
+
/** Hashes per operation. */
|
|
40
|
+
hashCount;
|
|
41
|
+
constructor(iterable, options) {
|
|
42
|
+
const { expectedItems } = options;
|
|
43
|
+
const falsePositiveRate = options.falsePositiveRate ?? 0.01;
|
|
44
|
+
if (!Number.isInteger(expectedItems) || expectedItems < 1) {
|
|
45
|
+
throw new RangeError(`Expected items must be a positive integer, got ${expectedItems}`);
|
|
46
|
+
}
|
|
47
|
+
if (!Number.isFinite(falsePositiveRate) ||
|
|
48
|
+
falsePositiveRate <= 0 ||
|
|
49
|
+
falsePositiveRate >= 1) {
|
|
50
|
+
throw new RangeError(`False-positive rate must be in (0, 1), got ${falsePositiveRate}`);
|
|
51
|
+
}
|
|
52
|
+
this.hash = options.hash;
|
|
53
|
+
this.bitCount = Math.max(BITS_PER_WORD, Math.ceil((-expectedItems * Math.log(falsePositiveRate)) / Math.LN2 ** 2));
|
|
54
|
+
this.hashCount = Math.max(1, Math.round((this.bitCount / expectedItems) * Math.LN2));
|
|
55
|
+
this.words = new Uint32Array((this.bitCount + WORD_MASK) >>> WORD_SHIFT);
|
|
56
|
+
if (iterable) {
|
|
57
|
+
this.addAll(iterable);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* How many times `add` was called with an item not already certainly present.
|
|
62
|
+
* An estimate of the set's size, not an exact count.
|
|
63
|
+
*/
|
|
64
|
+
count() {
|
|
65
|
+
return this.added;
|
|
66
|
+
}
|
|
67
|
+
clear() {
|
|
68
|
+
this.words.fill(0);
|
|
69
|
+
this.added = 0;
|
|
70
|
+
}
|
|
71
|
+
/** O(k), with exactly two hash calls regardless of k. */
|
|
72
|
+
add(item) {
|
|
73
|
+
const first = this.hash(item, 0) >>> 0;
|
|
74
|
+
const second = this.hash(item, 1) >>> 0;
|
|
75
|
+
let novel = false;
|
|
76
|
+
for (let index = 0; index < this.hashCount; index++) {
|
|
77
|
+
const bit = this.bitAt(first, second, index);
|
|
78
|
+
const wordIndex = bit >>> WORD_SHIFT;
|
|
79
|
+
const mask = 1 << (bit & WORD_MASK);
|
|
80
|
+
if ((this.words[wordIndex] & mask) === 0) {
|
|
81
|
+
this.words[wordIndex] |= mask;
|
|
82
|
+
novel = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (novel) {
|
|
86
|
+
this.added++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** O(m·k) in the number of items. */
|
|
90
|
+
addAll(items) {
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
this.add(item);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* O(k), with exactly two hash calls regardless of k.
|
|
97
|
+
*
|
|
98
|
+
* @returns `false` means the item is **definitely** absent. `true` means it
|
|
99
|
+
* is probably present — see `estimatedFalsePositiveRate`.
|
|
100
|
+
*/
|
|
101
|
+
has(item) {
|
|
102
|
+
const first = this.hash(item, 0) >>> 0;
|
|
103
|
+
const second = this.hash(item, 1) >>> 0;
|
|
104
|
+
for (let index = 0; index < this.hashCount; index++) {
|
|
105
|
+
const bit = this.bitAt(first, second, index);
|
|
106
|
+
if ((this.words[bit >>> WORD_SHIFT] & (1 << (bit & WORD_MASK))) === 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The false-positive probability at the filter's current fill, from the
|
|
114
|
+
* fraction of bits actually set: `(setBits / bitCount) ^ hashCount`.
|
|
115
|
+
*
|
|
116
|
+
* Measured rather than assumed, so it stays honest after more items were
|
|
117
|
+
* added than the filter was sized for. O(bitCount / 32).
|
|
118
|
+
*/
|
|
119
|
+
estimatedFalsePositiveRate() {
|
|
120
|
+
let setBits = 0;
|
|
121
|
+
for (let index = 0; index < this.words.length; index++) {
|
|
122
|
+
setBits += popCount32(this.words[index]);
|
|
123
|
+
}
|
|
124
|
+
return (setBits / this.bitCount) ** this.hashCount;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Folds `other` into this filter, so it holds the union of both item sets.
|
|
128
|
+
*
|
|
129
|
+
* Merging is exact — the union of two Bloom filters is the Bloom filter of
|
|
130
|
+
* the union — which is what makes these usable across partitions.
|
|
131
|
+
*
|
|
132
|
+
* @throws {RangeError} If the two filters were not sized identically. Bitwise
|
|
133
|
+
* union is only meaningful between filters with the same geometry.
|
|
134
|
+
*/
|
|
135
|
+
merge(other) {
|
|
136
|
+
if (other.bitCount !== this.bitCount ||
|
|
137
|
+
other.hashCount !== this.hashCount) {
|
|
138
|
+
throw new RangeError("Cannot merge Bloom filters with different bit or hash counts");
|
|
139
|
+
}
|
|
140
|
+
for (let index = 0; index < this.words.length; index++) {
|
|
141
|
+
this.words[index] |= other.words[index];
|
|
142
|
+
}
|
|
143
|
+
// Neither side knows the overlap, so this can only over-count; it is an
|
|
144
|
+
// estimate either way.
|
|
145
|
+
this.added += other.added;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Kirsch-Mitzenmacher: two hashes generate k indices with no measurable loss
|
|
149
|
+
* against k independent ones. Both are hoisted by the callers, so a k-hash
|
|
150
|
+
* filter still costs two calls to the caller's `hash`, not 2k.
|
|
151
|
+
*/
|
|
152
|
+
bitAt(first, second, index) {
|
|
153
|
+
return ((first + Math.imul(index, second)) >>> 0) % this.bitCount;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=bloom-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bloom-filter.js","sourceRoot":"","sources":["../../src/probabilistic/bloom-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiB1C,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,SAAS,GAAG,aAAa,GAAG,CAAC,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,WAAW;IACN,KAAK,CAAc;IACnB,IAAI,CAAY;IACzB,KAAK,GAAG,CAAC,CAAC;IAElB,0BAA0B;IACjB,QAAQ,CAAS;IAC1B,4BAA4B;IACnB,SAAS,CAAS;IAE3B,YACC,QAAiC,EACjC,OAA8B;QAE9B,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;QAClC,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,IAAI,IAAI,CAAC;QAE5D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,UAAU,CACnB,kDAAkD,aAAa,EAAE,CACjE,CAAC;QACH,CAAC;QAED,IACC,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YACnC,iBAAiB,IAAI,CAAC;YACtB,iBAAiB,IAAI,CAAC,EACrB,CAAC;YACF,MAAM,IAAI,UAAU,CACnB,8CAA8C,iBAAiB,EAAE,CACjE,CAAC;QACH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
import type { Hash32 } from "./hash32.js";
|
|
2
|
+
export type CountMinSketchOptions<T> = {
|
|
3
|
+
/** See {@link Hash32}: required, and why it cannot be defaulted. */
|
|
4
|
+
hash: Hash32<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Tolerated over-estimate, as a fraction of the total count added. Defaults
|
|
7
|
+
* to `0.001`. Width is `ceil(e / epsilon)`, so halving this doubles memory.
|
|
8
|
+
*/
|
|
9
|
+
epsilon?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Probability that an estimate exceeds the `epsilon` bound. Defaults to
|
|
12
|
+
* `0.001`. Depth is `ceil(ln(1 / delta))`.
|
|
13
|
+
*/
|
|
14
|
+
delta?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Approximate frequency counting: how many times was this item seen?
|
|
18
|
+
*
|
|
19
|
+
* A `Map<T, number>` answers exactly and costs O(distinct); this answers with a
|
|
20
|
+
* bounded over-estimate in `width × depth` counters, fixed regardless of how
|
|
21
|
+
* many distinct items pass through. That is what makes it usable on a stream
|
|
22
|
+
* whose alphabet does not fit in memory.
|
|
23
|
+
*
|
|
24
|
+
* **Estimates never under-count.** Every row's counter for an item includes
|
|
25
|
+
* that item's true count plus whatever collided with it, so the minimum across
|
|
26
|
+
* rows is an upper bound. With the default sizing, the over-estimate exceeds
|
|
27
|
+
* `epsilon × total` with probability at most `delta`.
|
|
28
|
+
*
|
|
29
|
+
* There is no way to remove an item or to enumerate what was counted — the
|
|
30
|
+
* items themselves are never stored.
|
|
31
|
+
*
|
|
32
|
+
* Time complexity: O(depth) for `add` and `estimate`, independent of the
|
|
33
|
+
* stream's length. Space: `width × depth` 32-bit counters.
|
|
34
|
+
*
|
|
35
|
+
* @template T The item type.
|
|
36
|
+
*/
|
|
37
|
+
export declare class CountMinSketch<T> {
|
|
38
|
+
private readonly counters;
|
|
39
|
+
private readonly hash;
|
|
40
|
+
/** Counters per row. */
|
|
41
|
+
readonly width: number;
|
|
42
|
+
/** Rows, i.e. independent hashes. */
|
|
43
|
+
readonly depth: number;
|
|
44
|
+
/** The total of every count added, exact. */
|
|
45
|
+
private total_;
|
|
46
|
+
constructor(options: CountMinSketchOptions<T>);
|
|
47
|
+
/** The sum of every count added. Exact, unlike a per-item estimate. */
|
|
48
|
+
total(): number;
|
|
49
|
+
clear(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Records `times` occurrences of `item`. O(depth).
|
|
52
|
+
*
|
|
53
|
+
* @throws {RangeError} If `times` is negative or not an integer.
|
|
54
|
+
*/
|
|
55
|
+
add(item: T, times?: number): void;
|
|
56
|
+
/** O(m·depth) in the number of items. */
|
|
57
|
+
addAll(items: Iterable<T>, times?: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* The estimated number of times `item` was added. O(depth).
|
|
60
|
+
*
|
|
61
|
+
* Never below the true count; above it by at most `epsilon × total()` with
|
|
62
|
+
* probability `1 - delta`.
|
|
63
|
+
*/
|
|
64
|
+
estimate(item: T): number;
|
|
65
|
+
/**
|
|
66
|
+
* Folds `other` in, so this sketch covers both streams.
|
|
67
|
+
*
|
|
68
|
+
* Merging is exact — counters add element-wise — which is what lets
|
|
69
|
+
* partitions be counted independently.
|
|
70
|
+
*
|
|
71
|
+
* @throws {RangeError} If the two were not sized identically.
|
|
72
|
+
*/
|
|
73
|
+
merge(other: CountMinSketch<T>): void;
|
|
74
|
+
private slot;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=count-min-sketch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count-min-sketch.d.ts","sourceRoot":"","sources":["../../src/probabilistic/count-min-sketch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI;IACtC,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAc,CAAC,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IAEjC,wBAAwB;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAK;IAEnB,YAAY,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAgB5C;IAED,uEAAuE;IACvE,KAAK,IAAI,MAAM,CAEd;IAED,KAAK,IAAI,IAAI,CAGZ;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,SAAI,GAAG,IAAI,CAmB5B;IAED,yCAAyC;IACzC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,SAAI,GAAG,IAAI,CAI1C;IAED;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAexB;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAYpC;IAED,OAAO,CAAC,IAAI;CAMZ"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approximate frequency counting: how many times was this item seen?
|
|
3
|
+
*
|
|
4
|
+
* A `Map<T, number>` answers exactly and costs O(distinct); this answers with a
|
|
5
|
+
* bounded over-estimate in `width × depth` counters, fixed regardless of how
|
|
6
|
+
* many distinct items pass through. That is what makes it usable on a stream
|
|
7
|
+
* whose alphabet does not fit in memory.
|
|
8
|
+
*
|
|
9
|
+
* **Estimates never under-count.** Every row's counter for an item includes
|
|
10
|
+
* that item's true count plus whatever collided with it, so the minimum across
|
|
11
|
+
* rows is an upper bound. With the default sizing, the over-estimate exceeds
|
|
12
|
+
* `epsilon × total` with probability at most `delta`.
|
|
13
|
+
*
|
|
14
|
+
* There is no way to remove an item or to enumerate what was counted — the
|
|
15
|
+
* items themselves are never stored.
|
|
16
|
+
*
|
|
17
|
+
* Time complexity: O(depth) for `add` and `estimate`, independent of the
|
|
18
|
+
* stream's length. Space: `width × depth` 32-bit counters.
|
|
19
|
+
*
|
|
20
|
+
* @template T The item type.
|
|
21
|
+
*/
|
|
22
|
+
export class CountMinSketch {
|
|
23
|
+
counters;
|
|
24
|
+
hash;
|
|
25
|
+
/** Counters per row. */
|
|
26
|
+
width;
|
|
27
|
+
/** Rows, i.e. independent hashes. */
|
|
28
|
+
depth;
|
|
29
|
+
/** The total of every count added, exact. */
|
|
30
|
+
total_ = 0;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
const epsilon = options.epsilon ?? 0.001;
|
|
33
|
+
const delta = options.delta ?? 0.001;
|
|
34
|
+
if (!Number.isFinite(epsilon) || epsilon <= 0 || epsilon >= 1) {
|
|
35
|
+
throw new RangeError(`Epsilon must be in (0, 1), got ${epsilon}`);
|
|
36
|
+
}
|
|
37
|
+
if (!Number.isFinite(delta) || delta <= 0 || delta >= 1) {
|
|
38
|
+
throw new RangeError(`Delta must be in (0, 1), got ${delta}`);
|
|
39
|
+
}
|
|
40
|
+
this.hash = options.hash;
|
|
41
|
+
this.width = Math.ceil(Math.E / epsilon);
|
|
42
|
+
this.depth = Math.max(1, Math.ceil(Math.log(1 / delta)));
|
|
43
|
+
this.counters = new Uint32Array(this.width * this.depth);
|
|
44
|
+
}
|
|
45
|
+
/** The sum of every count added. Exact, unlike a per-item estimate. */
|
|
46
|
+
total() {
|
|
47
|
+
return this.total_;
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
this.counters.fill(0);
|
|
51
|
+
this.total_ = 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Records `times` occurrences of `item`. O(depth).
|
|
55
|
+
*
|
|
56
|
+
* @throws {RangeError} If `times` is negative or not an integer.
|
|
57
|
+
*/
|
|
58
|
+
add(item, times = 1) {
|
|
59
|
+
if (!Number.isInteger(times) || times < 0) {
|
|
60
|
+
throw new RangeError(`Occurrence count must be a non-negative integer, got ${times}`);
|
|
61
|
+
}
|
|
62
|
+
if (times === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const first = this.hash(item, 0) >>> 0;
|
|
66
|
+
const second = this.hash(item, 1) >>> 0;
|
|
67
|
+
for (let row = 0; row < this.depth; row++) {
|
|
68
|
+
this.counters[this.slot(first, second, row)] += times;
|
|
69
|
+
}
|
|
70
|
+
this.total_ += times;
|
|
71
|
+
}
|
|
72
|
+
/** O(m·depth) in the number of items. */
|
|
73
|
+
addAll(items, times = 1) {
|
|
74
|
+
for (const item of items) {
|
|
75
|
+
this.add(item, times);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The estimated number of times `item` was added. O(depth).
|
|
80
|
+
*
|
|
81
|
+
* Never below the true count; above it by at most `epsilon × total()` with
|
|
82
|
+
* probability `1 - delta`.
|
|
83
|
+
*/
|
|
84
|
+
estimate(item) {
|
|
85
|
+
const first = this.hash(item, 0) >>> 0;
|
|
86
|
+
const second = this.hash(item, 1) >>> 0;
|
|
87
|
+
let smallest = Number.POSITIVE_INFINITY;
|
|
88
|
+
for (let row = 0; row < this.depth; row++) {
|
|
89
|
+
const counter = this.counters[this.slot(first, second, row)];
|
|
90
|
+
if (counter < smallest) {
|
|
91
|
+
smallest = counter;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return smallest === Number.POSITIVE_INFINITY ? 0 : smallest;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Folds `other` in, so this sketch covers both streams.
|
|
98
|
+
*
|
|
99
|
+
* Merging is exact — counters add element-wise — which is what lets
|
|
100
|
+
* partitions be counted independently.
|
|
101
|
+
*
|
|
102
|
+
* @throws {RangeError} If the two were not sized identically.
|
|
103
|
+
*/
|
|
104
|
+
merge(other) {
|
|
105
|
+
if (other.width !== this.width || other.depth !== this.depth) {
|
|
106
|
+
throw new RangeError("Cannot merge Count-Min sketches with different dimensions");
|
|
107
|
+
}
|
|
108
|
+
for (let index = 0; index < this.counters.length; index++) {
|
|
109
|
+
this.counters[index] += other.counters[index];
|
|
110
|
+
}
|
|
111
|
+
this.total_ += other.total_;
|
|
112
|
+
}
|
|
113
|
+
slot(first, second, row) {
|
|
114
|
+
// Kirsch-Mitzenmacher again: two hashes, `depth` independent-enough rows.
|
|
115
|
+
const column = ((first + Math.imul(row, second)) >>> 0) % this.width;
|
|
116
|
+
return row * this.width + column;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=count-min-sketch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count-min-sketch.js","sourceRoot":"","sources":["../../src/probabilistic/count-min-sketch.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,cAAc;IACT,QAAQ,CAAc;IACtB,IAAI,CAAY;IAEjC,wBAAwB;IACf,KAAK,CAAS;IACvB,qCAAqC;IAC5B,KAAK,CAAS;IAEvB,6CAA6C;IACrC,MAAM,GAAG,CAAC,CAAC;IAEnB,YAAY,OAAiC;QAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QAErC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,UAAU,CAAC,kCAAkC,OAAO,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,M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OAOG;IACH,KAAK,CAAC,KAAwB;QAC7B,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9D,MAAM,IAAI,UAAU,CACnB,2DAA2D,CAC3D,CAAC;QACH,CAAC;QAED,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3D,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAE,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;IAEO,IAAI,CAAC,KAAa,EAAE,MAAc,EAAE,GAAW;QACtD,0EAA0E;QAC1E,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QAErE,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;IAClC,CAAC;CACD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Hash32 } from "./hash32.js";
|
|
2
|
+
export type CuckooFilterOptions<T> = {
|
|
3
|
+
/** See {@link Hash32}: required, and why it cannot be defaulted. */
|
|
4
|
+
hash: Hash32<T>;
|
|
5
|
+
/** How many items the filter is sized for. */
|
|
6
|
+
expectedItems: number;
|
|
7
|
+
/**
|
|
8
|
+
* Fingerprints per bucket. Defaults to `4`, the value the literature finds
|
|
9
|
+
* best for load factors around 95%. Must be between 1 and 8.
|
|
10
|
+
*/
|
|
11
|
+
bucketSize?: number;
|
|
12
|
+
/**
|
|
13
|
+
* How many evictions an insert attempts before declaring the filter full.
|
|
14
|
+
* Defaults to `500`.
|
|
15
|
+
*/
|
|
16
|
+
maxKicks?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Approximate set membership **with deletion**, the thing a Bloom filter cannot
|
|
20
|
+
* do.
|
|
21
|
+
*
|
|
22
|
+
* Stores a short fingerprint of each item in one of two candidate buckets. The
|
|
23
|
+
* second bucket is derived from the first by XOR with the fingerprint's hash,
|
|
24
|
+
* which is what makes the relation symmetric: from either bucket the other can
|
|
25
|
+
* be computed without the item, so a fingerprint can be relocated during
|
|
26
|
+
* insertion and found again during lookup.
|
|
27
|
+
*
|
|
28
|
+
* Deleting removes one copy of a fingerprint. **Only delete items actually
|
|
29
|
+
* inserted**: removing a fingerprint that a different item happens to share
|
|
30
|
+
* would introduce a false negative, which this structure otherwise never has.
|
|
31
|
+
*
|
|
32
|
+
* `add` can fail. When both candidate buckets are full, it evicts and relocates
|
|
33
|
+
* up to `maxKicks` times; past that the filter is too loaded and `add` returns
|
|
34
|
+
* `false`. A failed insert is **rolled back**, so the filter still holds
|
|
35
|
+
* exactly what it held before — no previously inserted item is ever displaced
|
|
36
|
+
* into nothing.
|
|
37
|
+
*
|
|
38
|
+
* Time complexity: O(1) for `has` and `delete` — exactly two bucket probes.
|
|
39
|
+
* `add` is O(1) amortised, degrading as the load factor approaches capacity.
|
|
40
|
+
*
|
|
41
|
+
* @template T The item type.
|
|
42
|
+
*/
|
|
43
|
+
export declare class CuckooFilter<T> {
|
|
44
|
+
private readonly fingerprints;
|
|
45
|
+
private readonly hash;
|
|
46
|
+
private readonly bucketCount;
|
|
47
|
+
private readonly maxKicks;
|
|
48
|
+
/** Fingerprints per bucket. */
|
|
49
|
+
readonly bucketSize: number;
|
|
50
|
+
private size;
|
|
51
|
+
/** Deterministic eviction choice, so a failure reproduces. */
|
|
52
|
+
private evictionSeed;
|
|
53
|
+
constructor(iterable: Iterable<T> | undefined, options: CuckooFilterOptions<T>);
|
|
54
|
+
/** How many fingerprints are stored. */
|
|
55
|
+
count(): number;
|
|
56
|
+
/** The fraction of slots in use. */
|
|
57
|
+
loadFactor(): number;
|
|
58
|
+
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* O(1) amortised.
|
|
61
|
+
*
|
|
62
|
+
* @returns `false` if the filter was too full to place the item, after
|
|
63
|
+
* `maxKicks` relocations. The filter is rolled back to exactly its prior
|
|
64
|
+
* contents, so nothing inserted earlier is lost.
|
|
65
|
+
*/
|
|
66
|
+
add(item: T): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @returns How many items were added. A shortfall means the filter filled up
|
|
69
|
+
* — see `add`.
|
|
70
|
+
*/
|
|
71
|
+
addAll(items: Iterable<T>): number;
|
|
72
|
+
/**
|
|
73
|
+
* O(1), two bucket probes.
|
|
74
|
+
*
|
|
75
|
+
* @returns `false` means the item is **definitely** absent, provided only
|
|
76
|
+
* inserted items were ever deleted. `true` means probably present.
|
|
77
|
+
*/
|
|
78
|
+
has(item: T): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Removes one copy of the item's fingerprint. O(1).
|
|
81
|
+
*
|
|
82
|
+
* @returns `true` if a matching fingerprint was removed. Deleting an item
|
|
83
|
+
* never inserted can remove a colliding item's fingerprint instead, which
|
|
84
|
+
* is the one way this filter can produce a false negative.
|
|
85
|
+
*/
|
|
86
|
+
delete(item: T): boolean;
|
|
87
|
+
/** A non-zero byte: zero is reserved for "empty slot". */
|
|
88
|
+
private fingerprintOf;
|
|
89
|
+
private bucketOf;
|
|
90
|
+
/**
|
|
91
|
+
* The partner of `bucket` for this fingerprint.
|
|
92
|
+
*
|
|
93
|
+
* Must be an involution — applying it twice returns the original — or a
|
|
94
|
+
* relocated fingerprint becomes unfindable. That is why `bucketCount` is a
|
|
95
|
+
* power of two and the hash is **masked** rather than reduced modulo: XOR is
|
|
96
|
+
* self-inverse within a fixed bit width, but `(b ^ h) % n` is not, because
|
|
97
|
+
* the reduction discards the high bits the second XOR would need.
|
|
98
|
+
*/
|
|
99
|
+
private alternateBucket;
|
|
100
|
+
private placeIn;
|
|
101
|
+
private bucketHolds;
|
|
102
|
+
private removeFrom;
|
|
103
|
+
/** Xorshift32, so eviction is spread but reproducible. */
|
|
104
|
+
private nextEvictionSlot;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=cuckoo-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cuckoo-filter.d.ts","sourceRoot":"","sources":["../../src/probabilistic/cuckoo-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;IACpC,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAChB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAKF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,YAAY,CAAC,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAa;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,OAAO,CAAC,IAAI,CAAK;IACjB,8DAA8D;IAC9D,OAAO,CAAC,YAAY,CAAc;IAElC,YACC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,EACjC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,EA8B/B;IAED,wCAAwC;IACxC,KAAK,IAAI,MAAM,CAEd;IAED,oCAAoC;IACpC,UAAU,IAAI,MAAM,CAEnB;IAED,KAAK,IAAI,IAAI,CAG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