Skip to content

Latest commit

 

History

History
74 lines (47 loc) · 1.55 KB

File metadata and controls

74 lines (47 loc) · 1.55 KB

About

{{pkg.description}}

This package contains functionality which was previously part of and has been extracted from the @thi.ng/associative package.

SparseSet8/16/32

Sparse sets provide super fast (approx. 4x faster than the native Set impl) insertion & lookups for numeric values in the interval [0..n) . The implementation in this package provides most of the ES6 Set API and internally relies on 2 uint typed arrays, with the actual backing type dependent on n.

Furthermore, unless (or until) values are being removed from the set, they retain their original insertion order. For some use cases (e.g. deduplication of values), this property can be very useful.

import { defSparseSet } from "@thi.ng/sparse-set";

// create sparse set for value range 0 - 99 (uint8 backed)
const a = defSparseSet(100);
a.into([99, 42, 66, 23, 66, 42]);
// SparseSet8 { 99, 42, 66, 23 }

a.has(66)
// true

// sparse sets are iterable
[...a]
// [ 99, 42, 66, 23 ]

// attempting to add out-of-range values will fail
a.add(100)
// SparseSet8 { 99, 42, 66, 23 }

// create sparse set for 16 bit value range 0 - 0xffff (uint16 backed)
const b = defSparseSet(0x10000);
// SparseSet16 {}

{{meta.status}}

{{repo.supportPackages}}

{{repo.relatedPackages}}

{{meta.blogPosts}}

Installation

{{pkg.install}}

{{pkg.size}}

Dependencies

{{pkg.deps}}

{{repo.examples}}

API

{{pkg.docs}}

TODO