@esfx/collections-hashset
npm i @esfx/collections-hashset

@esfx/collections-hashset

A suite of packages designed to provide low-level APIs for interoperable libraries.

by esfx

1.0.0-pre.24 (see all)License:Apache-2.0TypeScript:Not Found
npm i @esfx/collections-hashset
Readme

@esfx/collections-hashset

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

Overview

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.

Downloads/wk

101

GitHub Stars

141

LAST COMMIT

3mos ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

4

OPEN PRs

11
VersionTagPublished
1.0.0-pre.24
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial