HashMap

hashing~ HashMap

Key/Value container.

Implements the same interface ES6 Map, except that keys are compared based on equality using a hash function and not based on identity.

Iterates its elements in insertion order.

const assert = require('assert');
const { hashmap } = require('ferrum');

const m = new Map([ [{}, 42] ]);
assert(!m.has({})); // Identity based comparison

const hm = hashmap([ [{}, 42] ]);
assert(hm.has({}));
assert.strictEqual(hm.get({}), 42);

Iteration order is defined to be the order of insertation

Version history

  • 1.9.0 Initial implementation

Constructor

new HashMap(seq, opts)

Source:
Implements:
  • Shallowclone
  • Deepclone
  • Into
  • Size
  • Equals
  • Hashable
  • Get
  • Has
  • Assign
  • Delete
  • Sequence
  • Pairs
  • inspect.custom
Parameters:
Name Type Description
seq Sequence

Any se­quence of key value pairs. Op­tional.

opts Object
Properties
Name Type Description
genBuildHasher function

A func­tion that cre­ates a new build hasher. Which in turn is a func­tion that in­stan­ti­ates a hasher so gen­Build­Hasher()() in­stan­ti­ates a hasher. This is ad­mit­tedly a bit over com­plex. The de­fault value is ran­dom­Build­Hasher; the prac­tical up­shot here is that this con­struc­tion al­lows us to reran­dom­ize the seed even when deep­clone() or shal­low­clone() is used. The down­side is that sup­ply­ing a simple hasher is quite a bit of work.

Hasher con­tains an ex­ample of how this prop­erty can be used to im­ple­ment a hash table that util­izes the ob­ject-hash lib­rary to hash un­known types.

Methods

(static) fromSeq(seq) → {HashMap}

Source:

Con­structs a hashmap from a se­quence

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
seq Sequence
Returns:
Type
HashMap

(static) fromSeqWithOpts(seq, opts) → {HashMap}

Source:

Con­structs a hashmap from a se­quence and op­tions

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
seq Sequence
opts Options
Properties
Name Type Description
genBuildHasher function
Returns:
Type
HashMap

(static) new() → {HashMap}

Source:

Con­structs an empty hashmap

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Returns:
Type
HashMap

clear()

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion

delete(key) → {Boolean}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
key *
Returns:
Type
Boolean

entries() → {Iterator}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Returns:
Type
Iterator

forEach(fn, thisArg)

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
fn function
thisArg *

get(key) → {*}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
key *
Returns:

the value

Type
*

getPair(key) → {Array}

Source:

Re­turns a key/​value pair given a key. This is ad­ded so users can ac­cess the key as it is stored in the table.

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
key *
Returns:

A key/​vaue pair

Type
Array

has(key) → {Boolean}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
key *
Returns:
Type
Boolean

keys() → {Iterator}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Returns:
Type
Iterator

set(key, val) → {HashMap}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Parameters:
Name Type Description
key *
val *
Returns:

this

Type
HashMap

size()

Source:

Get­ter, not a method. See ht­tps://​de­veloper.moz­illa.org/​en-US/​docs/​Web/​JavaS­cript/​Ref­er­ence/​Glob­al_Ob­jects/​Map/​size

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion

values() → {Iterator}

Source:

Ver­sion his­tory

  • 1.9.0 Ini­tial im­ple­ment­a­tion
Returns:
Type
Iterator