npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

set-ds

v1.0.1

Published

Set data structure

Downloads

12

Readme

npm version

Set Data Structure

Description

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


Basic Usage

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

API

Available methods for a Set instance:

  • isEmpty()

    Determines if the set is empty

  • size()

    Returns the size, or number of items in the set

  • clear()

    Clears all the items from the set

  • add(value)

    Adds an item to the set. If the set already contains the item, it is not added.

  • remove(value)

    Removes an item from the set.

  • has(value)

    Determines of the set contains, or has, the value

  • values()

    Returns an array containing all the items in the set

  • union(otherSet)

    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.

  • intersection(otherSet)

    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.

  • difference(otherSet)

    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'.

  • subset(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.


License

MIT © Jason Jones