1.0.2 • Published 10 months ago

@esfx/collections-sortedset v1.0.2

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
10 months ago

@esfx/collections-sortedset

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

Overview

Installation

npm i @esfx/collections-sortedset

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);
    }
}

SortedSet

import { SortedSet } from "@esfx/collections-sortedset";

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

// ECMAScript native set iterates in insertion order
const set = new Set(); // native ECMAScript Set
set.add(obj1);
set.add(obj2);
[...set]; // Alice Johnson,Bob Clark

// SortedSet uses Comparable.compareTo if available
const sortedSet = new SortedSet();
sortedSet.add(obj1);
sortedSet.add(obj2);
[...sortedSet]; // Bob Clark,Alice Johnson

API

You can read more about the API here.

1.0.2

2 years ago

1.0.0

2 years ago

1.0.0-dev.7

2 years ago

1.0.0-pre.42

2 years ago

1.0.0-dev.8

2 years ago

1.0.0-pre.41

2 years ago

1.0.0-dev.5

2 years ago

1.0.0-pre.44

2 years ago

1.0.0-dev.6

2 years ago

1.0.0-pre.43

2 years ago

1.0.0-dev.4

2 years ago

1.0.0-dev.0

2 years ago

1.0.0-pre.40

2 years ago

1.0.0-pre.31

2 years ago

1.0.0-pre.33

2 years ago

1.0.0-pre.32

2 years ago

1.0.0-pre.35

2 years ago

1.0.0-pre.34

2 years ago

1.0.0-pre.37

2 years ago

1.0.0-pre.36

2 years ago

1.0.0-pre.39

2 years ago

1.0.0-pre.38

2 years ago

1.0.0-pre.24

3 years ago

1.0.0-pre.23

3 years ago

1.0.0-pre.19

3 years ago

1.0.0-pre.17

3 years ago

1.0.0-pre.16

3 years ago

1.0.0-pre.13

5 years ago

1.0.0-pre.12

5 years ago

1.0.0-pre.11

5 years ago

1.0.0-pre.10

5 years ago

1.0.0-pre.9

5 years ago

1.0.0-pre.8

5 years ago

1.0.0-pre.7

5 years ago

1.0.0-pre.6

5 years ago

1.0.0-pre.5

5 years ago