New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@esfx/collections-hashset

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esfx/collections-hashset

Provides 'HashSet', a collection class that utilizes '@esfx/collection-core' and '@esfx/equatable'.

1.0.2
latest
Source
npm
Version published
Weekly downloads
696
19.59%
Maintainers
1
Weekly downloads
 
Created
Source

@esfx/collections-hashset

The @esfx/collections-hashset package provides HashSet, a collection class that utilizes @esfx/collection-core and @esfx/equatable.

Overview

  • Installation
  • Usage
  • API

Installation

npm i @esfx/collections-hashset

Usage

NOTE: The examples below use the following definition of Person:

import { Equatable, Equaler, Comparable, Comparer } from "@esfx/equatable";

class Person {
    constructor(firstName, lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    toString() {
        return `${this.firstName} ${this.lastName}`;
    }

    [Equatable.equals](other) {
        return other instanceof Person
            && this.lastName === other.lastName
            && this.firstName === other.firstName;
    }

    [Equatable.hash]() {
        return Equaler.defaultEqualer.hash(this.lastName)
             ^ Equaler.defaultEqualer.hash(this.firstName);
    }

    [Comparable.compareTo](other) {
        if (!(other instanceof Person)) throw new TypeError();
        return Comparer.defaultComparer.compare(this.lastName, other.lastName)
            || Comparer.defaultComparer.compare(this.firstName, other.firstName);
    }
}

HashSet

import { HashSet } from "@esfx/collections-hashset";

// NOTE: see definition of Person above
const obj1 = new Person("Bob", "Clark");
const obj2 = new Person("Bob", "Clark");

const set = new Set(); // native ECMAScript Set
set.add(obj1);
set.add(obj2);
set.length; // 2

const hashSet = new HashSet();
hashSet.add(obj1);
hashSet.add(obj2);
hashSet.length; // 1

API

You can read more about the API here.

FAQs

Package last updated on 01 Nov 2022

Did you know?

Socket

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.

Install

Related posts