Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
JavaScript Set
and Map
native utilities have a maximum key size of 2 ^ 24 (16,777,216). BigBoiSet
and BigBoiMap
preserve the interface methods of the native Set
and Map
, while silently putting the items into bucketed instances of their respective native counterparts. Keys are hashed before bucketing, and therefore do not need to be uniformly distributed in order to be bucketed appropriately.
npm install --save bigboi
or
yarn add bigboi
Except for constructor, same interface as Set
and Map
There are 2 variants of the Set
and Map
available.
import {
BigBoiSetSimple,
BigBoiMapSimple,
BigBoiSetHashed,
BigBoiMapHashed,
}
The Simple variants will simply push items into a Set/Map until there is no room, then move onto the next one, and so on. The lookup process is naive, and will simply go through the buckets of items to check if a given key is present. This means that any given lookup has a worst case of (total items) / (2 ^ 24)
. Bear in mind, lookups happen on reads/checks, but also on insertions, as we don't want to add the same item to multiple different buckets.
Map
or Set
The Hashed variants will hash the keys and get a deterministic and uniformly distributed bucket assignment for each item. This means that there is O(1) reads and writes, allowing this solution to scale to an arbitrarily high number of items limited only by the available memory in the runtime environment.
const bigSet = new BigBoiSetSimple();
// Add elements
for (let i = 0; i < 20_000_000; i++) {
bigSet.add('Hello' + i);
}
// Check if an element exists
bigSet.has('Hello0'); // returns true
// Remove an element
bigSet.delete('Hello0');
// Iterate over elements
bigSet.forEach((value) => {
console.log(value);
});
// Return iterators
bigSet.entries();
bigSet.keys();
bigSet.values();
// Clear
bigSet.clear();
const bigMap = new BigBoiMapSimple();
// Add elements
for (let i = 0; i < 20_000_000; i++) {
bigMap.add('Hello' + i, i);
}
// Get a value at a given key
bigMap.get('Hello0'); // returns 0
// Check if an element exists
bigMap.has('Hello0'); // returns true
// Remove an element
bigMap.delete('Hello0');
// Iterate over elements
bigMap.forEach((value, key) => {
console.log(key, value);
});
// Return iterators
bigMap.entries();
bigMap.keys();
bigMap.values();
// Clear
bigMap.clear();
We welcome contributions! Please see our contributing guidelines for more information.
MIT
FAQs
Big Sets and Big Maps! Get around the 2 ^ 24 item limit in JS Sets and Maps.
We found that bigboi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.