Gathering detailed insights and metrics for sweet-collections
Gathering detailed insights and metrics for sweet-collections
Gathering detailed insights and metrics for sweet-collections
Gathering detailed insights and metrics for sweet-collections
Typescript implementations of in-memory cache data-structures for Node and Browser.
npm install sweet-collections
Typescript
Module System
Node Version
NPM Version
TypeScript (83.65%)
JavaScript (16.35%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
35 Commits
1 Forks
3 Branches
1 Contributors
Updated on Mar 30, 2024
Latest Version
1.1.0
Package Id
sweet-collections@1.1.0
Unpacked Size
44.37 kB
Size
8.78 kB
File Count
40
NPM Version
6.14.11
Node Version
14.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Typescript implementations of in-memory cache data-structures for Node and Browser. These data-structures are:
Map
which removes the least recently used entry.Set
which removes the least recently used entry. (Backed by a LruMap
)Map
which removes the least frequently used entry.Set
which removes the least frequently used entry. (Backed by a LfuMap
)Array
that stays sorted after any modification.Map
with entries stays sorted by key after any modification. (Backed by a SortedArray
)Set
with entries stays sorted after any modification. (Backed by a SortedArray
)1npm install --save sweet-collections
or
1yarn add sweet-collections
1import { LruMap } from 'sweet-collections'; 2 3const map = new LruMap<number, number>(3); 4map.set(1, 1); 5map.set(2, 2); 6map.set(3, 3); // least recent used: 1 7console.log(map.has(1)) // true, least recent used: 2 8console.log(map.get(2)) // 1, least recent used: 3 9 10map.set(4, 4); 11console.log(map.has(3)) // false 12console.log(map.get(3)) // undefined 13 14console.log(map.isFull()) // true 15map.delete(1); 16console.log(map.size) // 2 17 18map.clear(); 19console.log(map.size) // 0
1import { LruSet } from 'sweet-collections'; 2 3const set = new LruSet<number>(3); 4set.add(1); 5set.add(2); 6set.add(3); // least recent used: 1 7console.log(set.has(1)) // true, least recent used: 2 8 9set.add(4); 10console.log(set.has(2)) // false 11 12console.log(set.isFull()) // true 13set.delete(1); 14console.log(set.size) // 2 15 16set.clear(); 17console.log(set.size) // 0
1import { LfuMap } from 'sweet-collections'; 2 3const map = new LfuMap<number, number>(3); 4map.set(1, 1); 5map.set(2, 2); 6map.set(3, 3); // least frequently used: 1 7console.log(map.has(1)) // true, least frequently used: 2 8console.log(map.get(2)) // 1, least frequently used: 3 9 10map.set(4, 4); 11console.log(map.has(3)) // false 12console.log(map.get(3)) // undefined 13 14console.log(map.isFull()) // true 15map.delete(1); 16console.log(map.size) // 2 17 18map.clear(); 19console.log(map.size) // 0
1import { LfuSet } from 'sweet-collections'; 2 3const set = new LfuSet<number>(3); 4set.add(1); 5set.add(2); 6set.add(3); // least frequently used: 1 7console.log(set.has(1)) // true, least frequently used: 2 8console.log(set.has(2)) // true, least frequently used: 3 9 10set.add(4); 11console.log(set.has(3)) // false 12 13console.log(set.isFull()) // true 14set.delete(1); 15console.log(set.size) // 2 16 17set.clear(); 18console.log(set.size) // 0
1import { SortedArray } from 'sweet-collections'; 2 3// Increasing order sorted array 4const array = new SortedArray<number>((a: number, b: number) => a - b); 5array.push(4); 6array.push(1); 7array.push(2); 8array.push(3); 9array.push(5); 10console.log(array.toArray()); // [1, 2, 3, 4, 5] 11console.log(array.get(2)); // 3 12console.log(array.get(4)); // 5 13console.log(array.length); // 5 14 15array.delete(4); 16console.log(array.toArray()); // [1, 2, 3, 5] 17console.log(array.includes(4)); // false 18 19array.push(1); 20console.log(array.toArray()); // [1, 1, 2, 3, 5] 21console.log(array.count(1)); // 2 22console.log(array.firstIndexOf(1)); // 0 23console.log(array.lastIndexOf(1)); // 1 24 25console.log(array.shift()); // 1 26console.log(array.pop()); // 1 27console.log(array.min()); // 1 28console.log(array.max()); // 3 29console.log(array.toArray()); // [1, 2, 3]
1import { SortedMap } from 'sweet-collections'; 2 3// Increasing order sorted map 4const map = new SortedMap<number, string>((a: number, b: number) => a - b); 5map.set(3, 'c'); 6map.set(2, 'd'); 7map.set(5, 'a'); 8map.set(4, 'b'); 9map.set(1, 'e'); 10console.log([...map.keys()]); // [1, 2, 3, 4, 5] 11console.log([...map.values()]); // ["e", "d", "c", "b", "a"] 12console.log(map.get(2)); // "d" 13console.log(map.get(4)); // "b" 14console.log(map.size); // 5 15 16map.delete(4); 17console.log([...map.keys()]); // [1, 2, 3, 5] 18console.log([...map.values()]); // ["e", "d", "c", "a"] 19console.log(map.has(4)); // false
1import { SortedSet } from 'sweet-collections'; 2 3// Increasing order sorted set 4const set = new SortedSet<number>((a: number, b: number) => a - b); 5set.add(3); 6set.add(2); 7set.add(5); 8set.add(4); 9set.add(1); 10console.log([...set.keys()]); // [1, 2, 3, 4, 5] 11console.log(set.has(2)); // true 12console.log(set.has(4)); // true 13console.log(set.size); // 5 14 15set.delete(4); 16console.log([...set.keys()]); // [1, 2, 3, 5] 17console.log(set.has(4)); // false
1import { Heap } from 'sweet-collections'; 2 3// Heap with the maximum value on top 4const heap = new Heap<number>((a: number, b: number) => a > b); 5heap.push(3); 6heap.push(2); 7heap.push(5); 8heap.push(4); 9heap.push(1); 10console.log(heap.peek()); // 5 11console.log(heap.pop()); // 5 12console.log(heap.peek()); // 4 13console.log(heap.replace(0)); // 4 14console.log(heap.peek()); // 3
1import { Stack } from 'sweet-collections'; 2 3const stack = new Stack<number>(); 4stack.push(3); 5stack.push(2); 6console.log(stack.top()); // 2 7stack.push(5, 4, 1); 8console.log(stack.pop()); // 1 9console.log(stack.top()); // 4 10console.log(stack.size); // 4
1import { Queue } from 'sweet-collections'; 2 3const queue = new Queue<number>(); 4queue.push(3); 5queue.push(2); 6console.log(queue.pop()); // 3 7queue.push(5, 4, 1); 8console.log(queue.pop()); // 2 9console.log(queue.peek()); // 5 10console.log(queue.size); // 3
👤 Nasreddine Bac Ali
Give a ⭐️ if this project helped you!
Copyright © 2021 Nasreddine Bac Ali. This project is ISC licensed.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More