@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,37 @@
|
|
|
1
|
+
export declare class LruStore<K, V> {
|
|
2
|
+
readonly capacity: number;
|
|
3
|
+
private readonly nodes;
|
|
4
|
+
/** Most recently used. */
|
|
5
|
+
private head;
|
|
6
|
+
/** Least recently used — the eviction victim. */
|
|
7
|
+
private tail;
|
|
8
|
+
constructor(capacity: number);
|
|
9
|
+
count(): number;
|
|
10
|
+
clear(): void;
|
|
11
|
+
/** O(1). Does not count as a use. */
|
|
12
|
+
has(key: K): boolean;
|
|
13
|
+
/** O(1). Does not count as a use, so it cannot change the eviction order. */
|
|
14
|
+
peek(key: K): V | undefined;
|
|
15
|
+
/** The entry `set` would evict next, or `undefined` when empty. O(1). */
|
|
16
|
+
leastRecent(): readonly [K, V] | undefined;
|
|
17
|
+
/** O(1). Counts as a use: the entry becomes the most recently used. */
|
|
18
|
+
get(key: K): V | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* O(1). Counts as a use.
|
|
21
|
+
*
|
|
22
|
+
* @returns The evicted entry, or `undefined` if nothing was evicted.
|
|
23
|
+
* Overwriting an existing key never evicts.
|
|
24
|
+
*/
|
|
25
|
+
set(key: K, value: V): readonly [K, V] | undefined;
|
|
26
|
+
/** O(1) — no tombstone, no compaction. See the note on this module. */
|
|
27
|
+
delete(key: K): boolean;
|
|
28
|
+
/** Most recently used first. */
|
|
29
|
+
entries(): IterableIterator<readonly [K, V]>;
|
|
30
|
+
/** Most recently used first. */
|
|
31
|
+
keys(): IterableIterator<K>;
|
|
32
|
+
/** Most recently used first. */
|
|
33
|
+
values(): IterableIterator<V>;
|
|
34
|
+
private touch;
|
|
35
|
+
private unlink;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=_lru-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lru-store.d.ts","sourceRoot":"","sources":["../../src/cache/_lru-store.ts"],"names":[],"mappings":"AA8BA,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IAQb,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAPrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IAErD,0BAA0B;IAC1B,OAAO,CAAC,IAAI,CAA8B;IAC1C,iDAAiD;IACjD,OAAO,CAAC,IAAI,CAA8B;IAE1C,YAAqB,QAAQ,EAAE,MAAM,EAMpC;IAED,KAAK,IAAI,MAAM,CAEd;IAED,KAAK,IAAI,IAAI,CAIZ;IAED,qCAAqC;IACrC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAEnB;IAED,6EAA6E;IAC7E,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAE1B;IAED,yEAAyE;IACzE,WAAW,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAIzC;IAED,uEAAuE;IACvE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAUzB;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAqCjD;IAED,uEAAuE;IACvE,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAWtB;IAED,gCAAgC;IAC/B,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAI5C;IAED,gCAAgC;IAC/B,IAAI,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAI3B;IAED,gCAAgC;IAC/B,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAI7B;IAED,OAAO,CAAC,KAAK;IAkBb,OAAO,CAAC,MAAM;CAgBd"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export class LruStore {
|
|
2
|
+
capacity;
|
|
3
|
+
nodes = new Map();
|
|
4
|
+
/** Most recently used. */
|
|
5
|
+
head = null;
|
|
6
|
+
/** Least recently used — the eviction victim. */
|
|
7
|
+
tail = null;
|
|
8
|
+
constructor(capacity) {
|
|
9
|
+
this.capacity = capacity;
|
|
10
|
+
if (!Number.isInteger(capacity) || capacity < 0) {
|
|
11
|
+
throw new RangeError(`Capacity must be a non-negative integer, got ${capacity}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
count() {
|
|
15
|
+
return this.nodes.size;
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.nodes.clear();
|
|
19
|
+
this.head = null;
|
|
20
|
+
this.tail = null;
|
|
21
|
+
}
|
|
22
|
+
/** O(1). Does not count as a use. */
|
|
23
|
+
has(key) {
|
|
24
|
+
return this.nodes.has(key);
|
|
25
|
+
}
|
|
26
|
+
/** O(1). Does not count as a use, so it cannot change the eviction order. */
|
|
27
|
+
peek(key) {
|
|
28
|
+
return this.nodes.get(key)?.value;
|
|
29
|
+
}
|
|
30
|
+
/** The entry `set` would evict next, or `undefined` when empty. O(1). */
|
|
31
|
+
leastRecent() {
|
|
32
|
+
const { tail } = this;
|
|
33
|
+
return tail === null ? undefined : [tail.key, tail.value];
|
|
34
|
+
}
|
|
35
|
+
/** O(1). Counts as a use: the entry becomes the most recently used. */
|
|
36
|
+
get(key) {
|
|
37
|
+
const node = this.nodes.get(key);
|
|
38
|
+
if (node === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
this.touch(node);
|
|
42
|
+
return node.value;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* O(1). Counts as a use.
|
|
46
|
+
*
|
|
47
|
+
* @returns The evicted entry, or `undefined` if nothing was evicted.
|
|
48
|
+
* Overwriting an existing key never evicts.
|
|
49
|
+
*/
|
|
50
|
+
set(key, value) {
|
|
51
|
+
const existing = this.nodes.get(key);
|
|
52
|
+
if (existing !== undefined) {
|
|
53
|
+
existing.value = value;
|
|
54
|
+
this.touch(existing);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
// A zero capacity holds nothing, so the incoming entry is itself the
|
|
58
|
+
// casualty — storing it first and evicting it back out would be the same
|
|
59
|
+
// answer through more work.
|
|
60
|
+
if (this.capacity === 0) {
|
|
61
|
+
return [key, value];
|
|
62
|
+
}
|
|
63
|
+
let evicted;
|
|
64
|
+
if (this.nodes.size >= this.capacity) {
|
|
65
|
+
const victim = this.tail;
|
|
66
|
+
evicted = [victim.key, victim.value];
|
|
67
|
+
this.unlink(victim);
|
|
68
|
+
this.nodes.delete(victim.key);
|
|
69
|
+
}
|
|
70
|
+
const node = { key, value, prev: null, next: this.head };
|
|
71
|
+
if (this.head !== null) {
|
|
72
|
+
this.head.prev = node;
|
|
73
|
+
}
|
|
74
|
+
this.head = node;
|
|
75
|
+
this.tail ??= node;
|
|
76
|
+
this.nodes.set(key, node);
|
|
77
|
+
return evicted;
|
|
78
|
+
}
|
|
79
|
+
/** O(1) — no tombstone, no compaction. See the note on this module. */
|
|
80
|
+
delete(key) {
|
|
81
|
+
const node = this.nodes.get(key);
|
|
82
|
+
if (node === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
this.unlink(node);
|
|
86
|
+
this.nodes.delete(key);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/** Most recently used first. */
|
|
90
|
+
*entries() {
|
|
91
|
+
for (let node = this.head; node !== null; node = node.next) {
|
|
92
|
+
yield [node.key, node.value];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Most recently used first. */
|
|
96
|
+
*keys() {
|
|
97
|
+
for (let node = this.head; node !== null; node = node.next) {
|
|
98
|
+
yield node.key;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Most recently used first. */
|
|
102
|
+
*values() {
|
|
103
|
+
for (let node = this.head; node !== null; node = node.next) {
|
|
104
|
+
yield node.value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
touch(node) {
|
|
108
|
+
if (this.head === node) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.unlink(node);
|
|
112
|
+
node.prev = null;
|
|
113
|
+
node.next = this.head;
|
|
114
|
+
if (this.head !== null) {
|
|
115
|
+
this.head.prev = node;
|
|
116
|
+
}
|
|
117
|
+
this.head = node;
|
|
118
|
+
this.tail ??= node;
|
|
119
|
+
}
|
|
120
|
+
unlink(node) {
|
|
121
|
+
if (node.prev !== null) {
|
|
122
|
+
node.prev.next = node.next;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.head = node.next;
|
|
126
|
+
}
|
|
127
|
+
if (node.next !== null) {
|
|
128
|
+
node.next.prev = node.prev;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.tail = node.prev;
|
|
132
|
+
}
|
|
133
|
+
node.prev = null;
|
|
134
|
+
node.next = null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=_lru-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lru-store.js","sourceRoot":"","sources":["../../src/cache/_lru-store.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,QAAQ;IAQC,QAAQ;IAPZ,KAAK,GAAG,I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,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAElB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEtB,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;IACpB,CAAC;IAEO,MAAM,CAAC,IAAmB;QACjC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { DefinedValue } from "@ac-kit/core";
|
|
2
|
+
import { ReplacementPolicy } from "../collection/ireplacing.js";
|
|
3
|
+
import { IReplacingSet } from "../set/ireplacing-set.js";
|
|
4
|
+
import { ISet } from "../set/iset.js";
|
|
5
|
+
export type LruCacheOptions = {
|
|
6
|
+
/** The number of items held before adding one displaces another. */
|
|
7
|
+
capacity: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A fixed-capacity set that evicts the least recently used item to make room.
|
|
11
|
+
*
|
|
12
|
+
* `add` never throws and never blocks: it answers with whatever it had to
|
|
13
|
+
* displace, so a caller that needs to know what fell out can see it without
|
|
14
|
+
* tracking the size itself. `has` deliberately does **not** count as a use —
|
|
15
|
+
* only `add` and `touch` do — so a membership test cannot reshuffle the
|
|
16
|
+
* eviction order behind the caller's back.
|
|
17
|
+
*
|
|
18
|
+
* Time complexity: O(1) for `add`, `has`, `touch` and `delete`. The inherited
|
|
19
|
+
* set algebra is O(n·m), as on `EnhancedSet`, and returns an unbounded
|
|
20
|
+
* `EnhancedSet` rather than another cache — a capacity-bounded union would
|
|
21
|
+
* silently drop elements it was asked to combine.
|
|
22
|
+
*
|
|
23
|
+
* Items are compared by `SameValueZero`, native `Map` semantics. An arbitrary
|
|
24
|
+
* equality cannot be hashed, and a cache exists to be fast; use `EnhancedSet`
|
|
25
|
+
* when the equality matters more than the speed.
|
|
26
|
+
*
|
|
27
|
+
* @template T The type of items. Anything except `undefined`.
|
|
28
|
+
*/
|
|
29
|
+
export declare class LruCache<T extends DefinedValue> implements IReplacingSet<T> {
|
|
30
|
+
private readonly store;
|
|
31
|
+
readonly capacity: number;
|
|
32
|
+
/**
|
|
33
|
+
* Always `"lru"`. A different replacement policy is a different class, the
|
|
34
|
+
* same way `BoundedQueue`/`LossyQueue` are, never a constructor flag.
|
|
35
|
+
*/
|
|
36
|
+
readonly overflowPolicy: ReplacementPolicy;
|
|
37
|
+
constructor(iterable: Iterable<T> | undefined, options: LruCacheOptions);
|
|
38
|
+
/** Most recently used first. */
|
|
39
|
+
[Symbol.iterator](): Iterator<T>;
|
|
40
|
+
count(): number;
|
|
41
|
+
clear(): void;
|
|
42
|
+
/**
|
|
43
|
+
* O(1). Counts as a use, so re-adding a held item makes it the most recently
|
|
44
|
+
* used rather than doing nothing.
|
|
45
|
+
*
|
|
46
|
+
* @returns The item evicted to make room, in a one-element array, or an empty
|
|
47
|
+
* array if nothing was evicted.
|
|
48
|
+
*/
|
|
49
|
+
add(item: T): readonly T[];
|
|
50
|
+
/**
|
|
51
|
+
* O(n) in the number of items. Every eviction along the way is reported, in
|
|
52
|
+
* the order it happened — adding more items than the capacity evicts the
|
|
53
|
+
* earlier ones of the same batch.
|
|
54
|
+
*/
|
|
55
|
+
addAll(items: Iterable<T>): readonly T[];
|
|
56
|
+
/** O(1). */
|
|
57
|
+
delete(item: T): boolean;
|
|
58
|
+
/** O(1). Does **not** count as a use — see `touch`. */
|
|
59
|
+
has(item: T): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Marks a held item as the most recently used. O(1).
|
|
62
|
+
*
|
|
63
|
+
* @returns `true` if the item was held, `false` if it was not (in which case
|
|
64
|
+
* nothing changed — use `add` to insert it).
|
|
65
|
+
*/
|
|
66
|
+
touch(item: T): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The least recently used item — the one `add` would evict next. O(1). Does
|
|
69
|
+
* not count as a use.
|
|
70
|
+
*
|
|
71
|
+
* @returns The item, or `undefined` when the cache is empty.
|
|
72
|
+
*/
|
|
73
|
+
lru(): T | undefined;
|
|
74
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
75
|
+
union(other: Iterable<T>): ISet<T>;
|
|
76
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
77
|
+
intersection(other: Iterable<T>): ISet<T>;
|
|
78
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
79
|
+
difference(other: Iterable<T>): ISet<T>;
|
|
80
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
81
|
+
symmetricDifference(other: Iterable<T>): ISet<T>;
|
|
82
|
+
/** O(n·m). */
|
|
83
|
+
isSubsetOf(other: Iterable<T>): boolean;
|
|
84
|
+
/** O(m). */
|
|
85
|
+
isSupersetOf(other: Iterable<T>): boolean;
|
|
86
|
+
/** O(m). */
|
|
87
|
+
isDisjointFrom(other: Iterable<T>): boolean;
|
|
88
|
+
private toSet;
|
|
89
|
+
}
|
|
90
|
+
//# sour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AE,CAAC,GAAG,OAAO,CAEpB;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAEtB;IAED;;;;;OAKG;IACH,GAAG,IAAI,CAAC,GAAG,SAAS,CAEnB;IAED,oEAAoE;IACpE,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEjC;IAED,oEAAoE;IACpE,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAExC;IAED,oEAAoE;IACpE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEtC;IAED,oEAAoE;IACpE,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAE/C;IAED,cAAc;IACd,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAEtC;IAED,YAAY;IACZ,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAQxC;IAED,YAAY;IACZ,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAQ1C;IAED,OAAO,CAAC,KAAK;CAGb"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { EnhancedSet } from "../set/enhanced-set.js";
|
|
2
|
+
import { LruStore } from "./_lru-store.js";
|
|
3
|
+
const NOTHING_DISPLACED = [];
|
|
4
|
+
/**
|
|
5
|
+
* A fixed-capacity set that evicts the least recently used item to make room.
|
|
6
|
+
*
|
|
7
|
+
* `add` never throws and never blocks: it answers with whatever it had to
|
|
8
|
+
* displace, so a caller that needs to know what fell out can see it without
|
|
9
|
+
* tracking the size itself. `has` deliberately does **not** count as a use —
|
|
10
|
+
* only `add` and `touch` do — so a membership test cannot reshuffle the
|
|
11
|
+
* eviction order behind the caller's back.
|
|
12
|
+
*
|
|
13
|
+
* Time complexity: O(1) for `add`, `has`, `touch` and `delete`. The inherited
|
|
14
|
+
* set algebra is O(n·m), as on `EnhancedSet`, and returns an unbounded
|
|
15
|
+
* `EnhancedSet` rather than another cache — a capacity-bounded union would
|
|
16
|
+
* silently drop elements it was asked to combine.
|
|
17
|
+
*
|
|
18
|
+
* Items are compared by `SameValueZero`, native `Map` semantics. An arbitrary
|
|
19
|
+
* equality cannot be hashed, and a cache exists to be fast; use `EnhancedSet`
|
|
20
|
+
* when the equality matters more than the speed.
|
|
21
|
+
*
|
|
22
|
+
* @template T The type of items. Anything except `undefined`.
|
|
23
|
+
*/
|
|
24
|
+
export class LruCache {
|
|
25
|
+
store;
|
|
26
|
+
capacity;
|
|
27
|
+
/**
|
|
28
|
+
* Always `"lru"`. A different replacement policy is a different class, the
|
|
29
|
+
* same way `BoundedQueue`/`LossyQueue` are, never a constructor flag.
|
|
30
|
+
*/
|
|
31
|
+
overflowPolicy = "lru";
|
|
32
|
+
constructor(iterable, options) {
|
|
33
|
+
this.capacity = options.capacity;
|
|
34
|
+
this.store = new LruStore(options.capacity);
|
|
35
|
+
if (iterable) {
|
|
36
|
+
this.addAll(iterable);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Most recently used first. */
|
|
40
|
+
[Symbol.iterator]() {
|
|
41
|
+
return this.store.keys();
|
|
42
|
+
}
|
|
43
|
+
count() {
|
|
44
|
+
return this.store.count();
|
|
45
|
+
}
|
|
46
|
+
clear() {
|
|
47
|
+
this.store.clear();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* O(1). Counts as a use, so re-adding a held item makes it the most recently
|
|
51
|
+
* used rather than doing nothing.
|
|
52
|
+
*
|
|
53
|
+
* @returns The item evicted to make room, in a one-element array, or an empty
|
|
54
|
+
* array if nothing was evicted.
|
|
55
|
+
*/
|
|
56
|
+
add(item) {
|
|
57
|
+
const evicted = this.store.set(item, item);
|
|
58
|
+
return evicted === undefined ? NOTHING_DISPLACED : [evicted[1]];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* O(n) in the number of items. Every eviction along the way is reported, in
|
|
62
|
+
* the order it happened — adding more items than the capacity evicts the
|
|
63
|
+
* earlier ones of the same batch.
|
|
64
|
+
*/
|
|
65
|
+
addAll(items) {
|
|
66
|
+
let evicted;
|
|
67
|
+
for (const item of items) {
|
|
68
|
+
const dropped = this.store.set(item, item);
|
|
69
|
+
if (dropped !== undefined) {
|
|
70
|
+
(evicted ??= []).push(dropped[1]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return evicted ?? NOTHING_DISPLACED;
|
|
74
|
+
}
|
|
75
|
+
/** O(1). */
|
|
76
|
+
delete(item) {
|
|
77
|
+
return this.store.delete(item);
|
|
78
|
+
}
|
|
79
|
+
/** O(1). Does **not** count as a use — see `touch`. */
|
|
80
|
+
has(item) {
|
|
81
|
+
return this.store.has(item);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Marks a held item as the most recently used. O(1).
|
|
85
|
+
*
|
|
86
|
+
* @returns `true` if the item was held, `false` if it was not (in which case
|
|
87
|
+
* nothing changed — use `add` to insert it).
|
|
88
|
+
*/
|
|
89
|
+
touch(item) {
|
|
90
|
+
return this.store.get(item) !== undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The least recently used item — the one `add` would evict next. O(1). Does
|
|
94
|
+
* not count as a use.
|
|
95
|
+
*
|
|
96
|
+
* @returns The item, or `undefined` when the cache is empty.
|
|
97
|
+
*/
|
|
98
|
+
lru() {
|
|
99
|
+
return this.store.leastRecent()?.[1];
|
|
100
|
+
}
|
|
101
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
102
|
+
union(other) {
|
|
103
|
+
return this.toSet().union(other);
|
|
104
|
+
}
|
|
105
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
106
|
+
intersection(other) {
|
|
107
|
+
return this.toSet().intersection(other);
|
|
108
|
+
}
|
|
109
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
110
|
+
difference(other) {
|
|
111
|
+
return this.toSet().difference(other);
|
|
112
|
+
}
|
|
113
|
+
/** O(n·m). Returns an unbounded set: see the note on this class. */
|
|
114
|
+
symmetricDifference(other) {
|
|
115
|
+
return this.toSet().symmetricDifference(other);
|
|
116
|
+
}
|
|
117
|
+
/** O(n·m). */
|
|
118
|
+
isSubsetOf(other) {
|
|
119
|
+
return this.toSet().isSubsetOf(other);
|
|
120
|
+
}
|
|
121
|
+
/** O(m). */
|
|
122
|
+
isSupersetOf(other) {
|
|
123
|
+
for (const item of other) {
|
|
124
|
+
if (!this.store.has(item)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/** O(m). */
|
|
131
|
+
isDisjointFrom(other) {
|
|
132
|
+
for (const item of other) {
|
|
133
|
+
if (this.store.has(item)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
toSet() {
|
|
140
|
+
return new EnhancedSet(this.store.keys());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=lru-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../src/cache/lru-cache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,iBAAiB,GAAqB,EAAE,CAAC;AAO/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAQ;IACH,KAAK,CAAiB;IAE9B,QAAQ,CAAS;IAE1B;;;OAGG;IACM,cAAc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IAAI,CAAC,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,YAAY;IACZ,cAAc,CAAC,KAAkB;QAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,KAAK;QACZ,OAAO,IAAI,WAAW,CAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;CACD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DefinedValue } from "@ac-kit/core";
|
|
2
|
+
import { ReplacementPolicy } from "../collection/ireplacing.js";
|
|
3
|
+
import { IReplacingMap } from "../map/ireplacing-map.js";
|
|
4
|
+
export type LruMapOptions = {
|
|
5
|
+
/** The number of entries held before setting one displaces another. */
|
|
6
|
+
capacity: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A fixed-capacity map that evicts the least recently used entry to make room.
|
|
10
|
+
*
|
|
11
|
+
* The `Map`-shaped counterpart of `LruCache`, over the same engine. **Prefer
|
|
12
|
+
* this one**: a cache almost always has something to say about each key, and a
|
|
13
|
+
* `LruMap<K, undefined>` is the degenerate case `LruCache` covers. Reach for
|
|
14
|
+
* `LruCache` only when the membership itself is the whole answer — a
|
|
15
|
+
* seen-recently set, a dedupe window.
|
|
16
|
+
*
|
|
17
|
+
* `get` counts as a use; `has` and `peek` do not, so an inspection cannot
|
|
18
|
+
* reshuffle the eviction order behind the caller's back. `set` never throws and
|
|
19
|
+
* never blocks: it answers with whatever entry it had to displace. Overwriting
|
|
20
|
+
* a key already held never evicts.
|
|
21
|
+
*
|
|
22
|
+
* Time complexity: O(1) for `get`, `set`, `has`, `peek` and `delete`. Iteration
|
|
23
|
+
* is most-recently-used first, and does not count as a use.
|
|
24
|
+
*
|
|
25
|
+
* Keys are compared by `SameValueZero`, native `Map` semantics.
|
|
26
|
+
*
|
|
27
|
+
* @template K The key type.
|
|
28
|
+
* @template V The value type.
|
|
29
|
+
*/
|
|
30
|
+
export declare class LruMap<K, V extends DefinedValue> implements IReplacingMap<K, V> {
|
|
31
|
+
private readonly store;
|
|
32
|
+
readonly capacity: number;
|
|
33
|
+
/**
|
|
34
|
+
* Always `"lru"`. A different replacement policy is a different class, the
|
|
35
|
+
* same way `BoundedQueue`/`LossyQueue` are, never a constructor flag.
|
|
36
|
+
*/
|
|
37
|
+
readonly overflowPolicy: ReplacementPolicy;
|
|
38
|
+
constructor(iterable: Iterable<readonly [K, V]> | undefined, options: LruMapOptions);
|
|
39
|
+
/** Most recently used first. Does not count as a use. */
|
|
40
|
+
[Symbol.iterator](): Iterator<readonly [K, V]>;
|
|
41
|
+
count(): number;
|
|
42
|
+
clear(): void;
|
|
43
|
+
/** O(1). Counts as a use. */
|
|
44
|
+
get(key: K): V | undefined;
|
|
45
|
+
/** O(1). Does **not** count as a use, unlike `get`. */
|
|
46
|
+
peek(key: K): V | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* O(1). Counts as a use.
|
|
49
|
+
*
|
|
50
|
+
* @returns The entry evicted to make room, in a one-element array, or an
|
|
51
|
+
* empty array if nothing was evicted. Overwriting a held key never evicts.
|
|
52
|
+
*/
|
|
53
|
+
set(key: K, value: V): readonly (readonly [K, V])[];
|
|
54
|
+
/** O(1). Does **not** count as a use. */
|
|
55
|
+
has(key: K): boolean;
|
|
56
|
+
/** O(1) — no tombstone, no compaction. */
|
|
57
|
+
delete(key: K): boolean;
|
|
58
|
+
/** Most recently used first. */
|
|
59
|
+
keys(): IterableIterator<K>;
|
|
60
|
+
/** Most recently used first. */
|
|
61
|
+
values(): IterableIterator<V>;
|
|
62
|
+
/** Most recently used first. */
|
|
63
|
+
entries(): IterableIterator<readonly [K, V]>;
|
|
64
|
+
/**
|
|
65
|
+
* The least recently used entry — the one `set` would evict next. O(1). Does
|
|
66
|
+
* not count as a use.
|
|
67
|
+
*
|
|
68
|
+
* @returns The entry, or `undefined` when the map is empty.
|
|
69
|
+
*/
|
|
70
|
+
lru(): readonly [K, V] | undefined;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=lru-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-map.d.ts","sourceRoot":"","sources":["../../src/cache/lru-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,MAAM,MAAM,aAAa,GAAG;IAC3B,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,YAAY,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;IAEvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,iBAAiB,CAAS;IAEnD,YACC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,EAC/C,OAAO,EAAE,aAAa,EAUtB;IAED,yDAAyD;IACzD,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAE7C;IAED,KAAK,IAAI,MAAM,CAEd;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,6BAA6B;IAC7B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAEzB;IAED,uDAAuD;IACvD,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAE1B;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAIlD;IAED,yCAAyC;IACzC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAEnB;IAED,0CAA0C;IAC1C,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAEtB;IAED,gCAAgC;IAChC,IAAI,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAE1B;IAED,gCAAgC;IAChC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAE5B;IAED,gCAAgC;IAChC,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAE3C;IAED;;;;;OAKG;IACH,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAEjC;CACD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { LruStore } from "./_lru-store.js";
|
|
2
|
+
const NOTHING_DISPLACED = [];
|
|
3
|
+
/**
|
|
4
|
+
* A fixed-capacity map that evicts the least recently used entry to make room.
|
|
5
|
+
*
|
|
6
|
+
* The `Map`-shaped counterpart of `LruCache`, over the same engine. **Prefer
|
|
7
|
+
* this one**: a cache almost always has something to say about each key, and a
|
|
8
|
+
* `LruMap<K, undefined>` is the degenerate case `LruCache` covers. Reach for
|
|
9
|
+
* `LruCache` only when the membership itself is the whole answer — a
|
|
10
|
+
* seen-recently set, a dedupe window.
|
|
11
|
+
*
|
|
12
|
+
* `get` counts as a use; `has` and `peek` do not, so an inspection cannot
|
|
13
|
+
* reshuffle the eviction order behind the caller's back. `set` never throws and
|
|
14
|
+
* never blocks: it answers with whatever entry it had to displace. Overwriting
|
|
15
|
+
* a key already held never evicts.
|
|
16
|
+
*
|
|
17
|
+
* Time complexity: O(1) for `get`, `set`, `has`, `peek` and `delete`. Iteration
|
|
18
|
+
* is most-recently-used first, and does not count as a use.
|
|
19
|
+
*
|
|
20
|
+
* Keys are compared by `SameValueZero`, native `Map` semantics.
|
|
21
|
+
*
|
|
22
|
+
* @template K The key type.
|
|
23
|
+
* @template V The value type.
|
|
24
|
+
*/
|
|
25
|
+
export class LruMap {
|
|
26
|
+
store;
|
|
27
|
+
capacity;
|
|
28
|
+
/**
|
|
29
|
+
* Always `"lru"`. A different replacement policy is a different class, the
|
|
30
|
+
* same way `BoundedQueue`/`LossyQueue` are, never a constructor flag.
|
|
31
|
+
*/
|
|
32
|
+
overflowPolicy = "lru";
|
|
33
|
+
constructor(iterable, options) {
|
|
34
|
+
this.capacity = options.capacity;
|
|
35
|
+
this.store = new LruStore(options.capacity);
|
|
36
|
+
if (iterable) {
|
|
37
|
+
for (const [key, value] of iterable) {
|
|
38
|
+
this.store.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Most recently used first. Does not count as a use. */
|
|
43
|
+
[Symbol.iterator]() {
|
|
44
|
+
return this.store.entries();
|
|
45
|
+
}
|
|
46
|
+
count() {
|
|
47
|
+
return this.store.count();
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
this.store.clear();
|
|
51
|
+
}
|
|
52
|
+
/** O(1). Counts as a use. */
|
|
53
|
+
get(key) {
|
|
54
|
+
return this.store.get(key);
|
|
55
|
+
}
|
|
56
|
+
/** O(1). Does **not** count as a use, unlike `get`. */
|
|
57
|
+
peek(key) {
|
|
58
|
+
return this.store.peek(key);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* O(1). Counts as a use.
|
|
62
|
+
*
|
|
63
|
+
* @returns The entry evicted to make room, in a one-element array, or an
|
|
64
|
+
* empty array if nothing was evicted. Overwriting a held key never evicts.
|
|
65
|
+
*/
|
|
66
|
+
set(key, value) {
|
|
67
|
+
const evicted = this.store.set(key, value);
|
|
68
|
+
return evicted === undefined ? NOTHING_DISPLACED : [evicted];
|
|
69
|
+
}
|
|
70
|
+
/** O(1). Does **not** count as a use. */
|
|
71
|
+
has(key) {
|
|
72
|
+
return this.store.has(key);
|
|
73
|
+
}
|
|
74
|
+
/** O(1) — no tombstone, no compaction. */
|
|
75
|
+
delete(key) {
|
|
76
|
+
return this.store.delete(key);
|
|
77
|
+
}
|
|
78
|
+
/** Most recently used first. */
|
|
79
|
+
keys() {
|
|
80
|
+
return this.store.keys();
|
|
81
|
+
}
|
|
82
|
+
/** Most recently used first. */
|
|
83
|
+
values() {
|
|
84
|
+
return this.store.values();
|
|
85
|
+
}
|
|
86
|
+
/** Most recently used first. */
|
|
87
|
+
entries() {
|
|
88
|
+
return this.store.entries();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The least recently used entry — the one `set` would evict next. O(1). Does
|
|
92
|
+
* not count as a use.
|
|
93
|
+
*
|
|
94
|
+
* @returns The entry, or `undefined` when the map is empty.
|
|
95
|
+
*/
|
|
96
|
+
lru() {
|
|
97
|
+
return this.store.leastRecent();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=lru-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-map.js","sourceRoot":"","sources":["../../src/cache/lru-map.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,iBAAiB,GAAyC,EAAE,CAAC;AAOnE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,MAAM;IACD,KAAK,CAAiB;IAE9B,QAAQ,CAAS;IAE1B;;;OAGG;IACM,cAAc,GAAsB,KAAK,CAAC;IAEnD,YACC,QAA+C,EAC/C,OAAsB;QAEtB,IAAI,C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CAAC,GAAM;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,gCAAgC;IAChC,IAAI;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,gCAAgC;IAChC,MAAM;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,gCAAgC;IAChC,OAAO;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,GAAG;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IACjC,CAAC;CACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BoundedOptions, IBounded } from "./ibounded.js";
|
|
2
|
+
export declare function isBounded(value: unknown): value is IBounded;
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the capacity a bounded collection was constructed with.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately not generic over the storage: `BoundedOptions<TStorage>` is
|
|
7
|
+
* invariant in `TStorage` (it occurs both as a property and inside an
|
|
8
|
+
* intersection), so every caller would have to widen at the call site.
|
|
9
|
+
*
|
|
10
|
+
* @param itemCount How many items the initial iterable held.
|
|
11
|
+
* @throws {RangeError} If the capacity is not a finite, non-negative number,
|
|
12
|
+
* exceeds what the supplied storage can hold, or is already smaller than the
|
|
13
|
+
* initial iterable.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveBoundedCapacity(itemCount: number, options?: BoundedOptions<unknown>): number;
|
|
16
|
+
/**
|
|
17
|
+
* The capacity check every `Bounded*` collection repeats before adding items.
|
|
18
|
+
*
|
|
19
|
+
* No permit bookkeeping: every collection in this package counts in O(1), so
|
|
20
|
+
* asking it how full it is costs strictly less than mirroring its size in a
|
|
21
|
+
* second counter that can drift.
|
|
22
|
+
*
|
|
23
|
+
* @throws {CollectionCapacityExceededError} If the collection cannot take that
|
|
24
|
+
* many more items.
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkCapacity(count: number, added: number, capacity: number): void;
|
|
27
|
+
//# sourceMappingURL=_bounded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_bounded.d.ts","sourceRoot":"","sources":["../../src/collection/_bounded.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EAEd,QAAQ,EACR,MAAM,eAAe,CAAC;AAEvB,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAC/B,MAAM,CAwBR;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACd,IAAI,CAIN"}
|