4.7.1 • Published 2 months ago

things v4.7.1

Weekly downloads
4
License
MIT
Repository
github
Last release
2 months ago

things

Data Structures for modern JavaScript and TypeScript

This is an experimental package. It is subject to rapid change, experimentation, and bugs.

Installation

To add things to your project:

npm install things

Example

Try out the following code example to get started:

import {HashMaps, Numbers, NumbersDescending, Nats} from "things";
console.log("things Example");
console.log("--------------");
const M = HashMaps(Numbers, Numbers);
let h = M.from([[1, 7], [3, 2], [3, 1]]);
console.log("h = " + M.print(h));
console.log("get(h, 3) = " + M.get(h, 3));
let g = M.from([[3, 5], [1, 7]]);
console.log("g = " + M.print(g));
console.log(`compare(h, g) = ${M.compare(h, g)}`);
console.log(`compare(g, h) = ${M.compare(g, h)}`);
M.put(h, 3, 5);
console.log(`put(h, 3, 5): h = ${M.print(h)}`);
console.log(`equals(h, g) = ${M.equals(h, g)}`);
console.log(`compare(h, g) = ${M.compare(h, g)}`);
M.remove(h, 3);
console.log(`remove(h, 3): h = ${M.print(h)}`);
console.log(`equals(h, g) = ${M.equals(h, g)}`);
console.log(`compare(h, g) = ${M.compare(h, g)}`);
const N = HashMaps(Nats, NumbersDescending);
h = N.from([[1, 7], [3, 2], [3, 1]]);
g = N.from([[3, 5], [1, 7]]);
console.log("h = " + N.print(h));
console.log("g = " + N.print(g));
console.log(`compare(h, g) = ${N.compare(h, g)}`);
console.log(`compare(g, h) = ${N.compare(g, h)}`);
try {
    M.print(h);
} catch (error) {
    console.log("" + error);
}
console.log(M.print(M.from(N.entries(h))));
try {
    N.from([[1.1, 7]]);
} catch (error) {
    console.log("" + error);
}

This will generate the following output:

things Example
--------------
h = [1 ↦ 7, 3 ↦ 1]
get(h, 3) = 1
g = [3 ↦ 5, 1 ↦ 7]
compare(h, g) = -1
compare(g, h) = 1
put(h, 3, 5): h = [1 ↦ 7, 3 ↦ 5]
equals(h, g) = true
compare(h, g) = 0
remove(h, 3): h = [1 ↦ 7]
equals(h, g) = false
compare(h, g) = NaN
h = [Nat(1) ↦ 7, Nat(3) ↦ 1]
g = [Nat(3) ↦ 5, Nat(1) ↦ 7]
compare(h, g) = 1
compare(g, h) = -1
Error: Cannot access sealed content. 
[1 ↦ 7, 3 ↦ 1]
Error: Key '1.1' is not in domain.

Features

  • Data structure package specifically designed for both JavaScript and TypeScript, based on ES modules.
  • Provides a hardened and tamper-proof API surface through careful design and the excessive use of Object.freeze.
  • Supports both mutable and immutable data structures.
  • Highly flexible, as all functionality lives outside the type it applies to. For example, you can view numbers either ascendingly ordered as [Numbers], or descendingly ordered via [NumbersDescending].

Data Structures

The list of implemented data structures is short so far, but already useful:

4.7.1

2 months ago

4.6.13

3 months ago

4.6.12

3 months ago

4.6.9

3 months ago

4.6.11

3 months ago

4.6.10

3 months ago

4.6.7

3 months ago

4.6.8

3 months ago

4.6.5

3 months ago

4.7.0

3 months ago

4.6.1

4 months ago

4.6.3

4 months ago

4.6.2

4 months ago

4.6.4

4 months ago

4.6.0

4 months ago

4.5.0

4 months ago

4.5.2

4 months ago

4.5.1

4 months ago

4.4.1

6 months ago

4.4.0

6 months ago

4.4.3

6 months ago

4.4.2

6 months ago

4.2.2

10 months ago

4.3.0

10 months ago

4.1.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.1.1

2 years ago

0.0.2

2 years ago

0.1.4

2 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.10.0

10 years ago

0.9.3

10 years ago

0.9.2

10 years ago

0.9.1

10 years ago

0.9.0

10 years ago

0.8.0

10 years ago

0.7.3

10 years ago

0.7.1

10 years ago

0.6.0

10 years ago

0.5.1

11 years ago

0.5.0

11 years ago

0.4.0

11 years ago

0.3.0

12 years ago

0.2.0

12 years ago

0.1.0

12 years ago

0.0.1

12 years ago