Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
This is a javascript implementation of a set data structure.
A set data structure is an implementation of the mathematical concept of a finite set. A set is a collection of unique values (no duplicates) that have no particular order. A set is more concerned whether or not values are contained in the set than the order in which they are added.
This implementation of a set inlcudes the common set operations of union, intersection, difference, and subset.
For specific examples and documentation, see the below sections
Install with npm :
npm install set-ds --save
Basic usage example below. Note: it does not cover all the available methods, rather just highlights the main functionality to get up and running with this data structure. For a description of all the methods, see the API section.
var SetDS = require('set-ds');
var setA = new SetDS();
setA.isEmpty();
// --> true
setA.add(1);
setA.add(2);
setA.add(3);
setA.add(4);
setA.add(5);
setA.values();
// --> [1, 2, 3, 4, 5]
setA.has(4);
// --> true
// or instantiate with an array or args
var setB = new SetDS([7, 6, 5, 8, 4]);
setB.isEmpty();
// --> false
setB.values();
// --> [4, 5, 6, 7, 8]
var setC = setA.union(setB);
setC.values();
// --> [1, 2, 3, 4, 5, 6, 7, 8]
var setD = setA.intersection(setB);
setD.values();
// --> [4, 5]
var setE = setA.difference(setB);
setE.values();
// --> [1, 2, 3]
setA.subset(new SetDS(1, 7, 3, 4, 6, 5, 2));
// --> true
setA.clear();
setA.isEmpty();
// --> true
Available methods for a Set instance:
Determines if the set is empty
Returns the size, or number of items in the set
Clears all the items from the set
Adds an item to the set. If the set already contains the item, it is not added.
Removes an item from the set.
Determines of the set contains, or has, the value
Returns an array containing all the items in the set
Returns a Set that is the union of this set and the 'otherSet'. The returned set will contain all the elements from both sets, and by definition, will not contain any duplicates.
Returns a Set that ts the intersection of this set and the 'otherSet', The returned set will have only those items that both sets have in common.
Returns a Set that ts the different of this and the 'otherSet', The returned set will have those items that are contained in this set, but NOT contained in the 'otherSet'.
Returns whether or not this set is a subset of the 'otherSet'. If all items of this set are contained in the otherSet, this function returns true; false otherwise.
MIT © Jason Jones
FAQs
Set data structure
The npm package set-ds receives a total of 2 weekly downloads. As such, set-ds popularity was classified as not popular.
We found that set-ds demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.