
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@thi.ng/associative
Advanced tools
Alternative Set & Map data type implementations with customizable equality semantics & supporting operations
This project is part of the @thi.ng/umbrella monorepo.
This package provides alternative Set & Map data type
implementations with customizable equality semantics, as well as common
operations working with these types:
ArraySet, Linked List based LLSet,
Skiplist based SortedMap
& SortedSet and customizable EquivMap implement the full ES6
Map/Set APIs and additional features:
entries(), keys(), values())
(sorted types only)ICopy, IEmpty & IEquiv implementationsICompare implementation for sorted typesinto(),
dissoc() (maps) and disj() (sets)fromObject() converters (for maps only)K => V to V => KThe native ES6 implementations use object reference identity to determine key containment, but often it's more practical and useful to use equivalent value semantics for this purpose, especially when keys are structured data (arrays / objects).
Note: It's the user's responsibility to ensure the inserted keys are kept immutable (even if technically they're not).
// first two objects w/ equal values
a = [1, 2];
b = [1, 2];
Using native implementations
set = new Set();
set.add(a);
set.has(b);
// false
map = new Map();
map.set(a, "foo");
map.get(b);
// undefined
Using custom implementations:
import * as assoc from "@thi.ng/associative";
set = new assoc.ArraySet();
set.add(a);
set.add({a: 1});
// ArraySet { [ 1, 2 ], { a: 1 } }
set.has(b);
// true
set.has({a: 1});
// true
set = new assoc.LLSet();
set.add(a);
set.add({a: 1});
// LLSet { [ 1, 2 ], { a: 1 } }
set.has(b);
// true
set.has({a: 1});
// true
// by default EquivMap uses ArraySet for its canonical keys
map = new assoc.EquivMap();
// with custom implementation
map = new assoc.EquivMap(null, { keys: assoc.ArraySet });
map.set(a, "foo");
// EquivMap { [ 1, 2 ] => 'foo' }
map.get(b);
// "foo"
set = new assoc.SortedSet([a, [-1, 2], [-1, -2]]);
// SortedSet { [ -1, -2 ], [ -1, 2 ], [ 1, 2 ] }
set.has(b);
// true
map = new assoc.SortedMap([[a, "foo"], [[-1,-2], "bar"]]);
// SortedMap { [ -1, -2 ] => 'bar', [ 1, 2 ] => 'foo' }
map.get(b);
// "foo"
// key lookup w/ default value
map.get([3,4], "n/a");
// "n/a"
yarn add @thi.ng/associative
All Set implementations in this package implement the
IEquivSet
interface, an extension of the native ES6 Set API.
Simple array based Set implementation which by default uses
@thi.ng/api/equiv
for value equivalence checking.
Similar to ArraySet, but uses
@thi.ng/dcons linked list
as backing storage for values.
This Map implementation uses a native ES6 Map as backing storage for
its key-value pairs and an additional IEquivSet implementation for
canonical keys. By default uses ArraySet for this purpose.
Alternative implementation of the ES6 Map API using a Skip list as backing store and support for configurable key equality and sorting semantics. Like with sets, uses @thi.ng/api/equiv & @thi.ng/api/compare by default.
William Pugh's (creator of this data structure) description:
"Skip lists are probabilistic data structures that have the same asymptotic expected time bounds as balanced trees, are simpler, faster and use less space."
Data structure description:
map = new assoc.SortedMap([
["c", 3], ["a", 1], ["d", 4], ["b", 2]
]);
// SortedMap { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 }
// forward selection w/ given start key
// also works with `keys()` and `values()`
[...map.entries("c")]
// [ [ 'c', 3 ], [ 'd', 4 ] ]
// unknown start keys are ok
[...map.entries("cc")]
// [ [ 'd', 4 ] ]
// reverse order
[...map.entries(undefined, true)]
// [ [ 'd', 4 ], [ 'c', 3 ], [ 'b', 2 ], [ 'a', 1 ] ]
// reverse order from start key
[...map.entries("c", true)]
// [ [ 'c', 3 ], [ 'b', 2 ], [ 'a', 1 ] ]
Sorted set implementation with standard ES6 Set API, customizable value equality and comparison semantics and additional functionality:
entries, keys, values)into() and disj()Furthermore, this class implements the ICopy, IEmpty, ICompareandIEquivinterfaces defined by@thi.ng/api`. The latter two allow
instances to be used as keys themselves in other data types defined in
this (and other) package(s).
This set uses a SortedMap as backing store.
TODO... Please see tests and documentation in source code for now...
© 2017 - 2018 Karsten Schmidt // Apache Software License 2.0
FAQs
ES Map/Set-compatible implementations with customizable equality semantics & supporting operations
The npm package @thi.ng/associative receives a total of 2,487 weekly downloads. As such, @thi.ng/associative popularity was classified as popular.
We found that @thi.ng/associative demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.