Expand all

ve.dm.HashValueStore

Constructor

new ve.dm.HashValueStore([values]) #

Ordered append-only hash store, whose values once inserted are immutable

Values are objects, strings or Arrays, and are hashed using an algorithm with low collision probability: values with the same hash can be assumed equal.

Values are stored in insertion order, and the store can be sliced to get a subset of values inserted consecutively.

Two stores can be merged even if they have differently computed hashes, so long as two values will (with high probability) have the same hash only if equal. In this case, equivalent values can have two different hashes.

Parameters:

Name Type Attributes Description
values Array.<Object> optional

Values to insert

Source:

Ordered append-only hash store, whose values once inserted are immutable

Values are objects, strings or Arrays, and are hashed using an algorithm with low collision probability: values with the same hash can be assumed equal.

Methods

clone() → {ve.dm.HashValueStore} #

Clone a store.

Deprecated:
  • Use #slice with no arguments.
Source:

Returns:

New store with the same contents as this one

Type
ve.dm.HashValueStore
Clone a store.

difference(omit) → {ve.dm.HashValueStore} #

Clone this store excluding certain values, like a set difference operation

Parameters:

Name Type Description
omit ve.dm.HashValueStore | Object

Store of values to omit, or object whose keys are hashes to emit

Source:

Returns:

All values in this that do not appear in other

Type
ve.dm.HashValueStore
Clone this store excluding certain values, like a set difference operation

getLength() → {number} #

Get the number of values in the store

Source:

Returns:

Number of values in the store

Type
number
Get the number of values in the store

hash(value, [stringified]) → {string} #

Insert a value into the store

Parameters:

Name Type Attributes Description
value Object | string | Array

Value to store

stringified string optional

Stringified version of value; default OO.getHash( value )

Source:

Returns:

Hash value with low collision probability

Type
string
Insert a value into the store

hashAll(values) → {Array.<string>} #

Get the hashes of values in the store

Same as hash but with arrays.

Parameters:

Name Type Description
values Array.<Object>

Values to lookup or store

Source:

Returns:

The hashes of the values in the store

Type
Array.<string>

Get the hashes of values in the store

Same as hash but with arrays.

hashOfValue(value, [stringified]) → {string} #

Get the hash of a value without inserting it in the store

Parameters:

Name Type Attributes Description
value Object | string | Array

Value to hash

stringified string optional

Stringified version of value; default OO.getHash( value )

Source:

Returns:

Hash value with low collision probability

Type
string
Get the hash of a value without inserting it in the store

merge(other) #

Merge another store into this store.

It is allowed for the two stores to have differently computed hashes, so long as two values will (with high probability) have the same hash only if equal. In this case, equivalent values can have two different hashes.

Values are added in the order they appear in the other store. Objects added to the store are added by reference, not cloned, unlike in .hash()

Parameters:

Name Type Description
other ve.dm.HashValueStore

Store to merge into this one

Source:
Merge another store into this store.

replaceHash(oldHash, value) → {string} #

Replace a value's stored hash, e.g. if the value has changed and you want to discard the old one.

Parameters:

Name Type Description
oldHash string

The value's previously stored hash

value Object | string | Array

New value

Source:

Returns:

New hash

Type
string

Throws:

Old hash not found

Type
Error
Replace a value's stored hash, e.g.

serialize(serializeValue) → {Object|null} #

Serialize the store into a JSONable object

Parameters:

Name Type Description
serializeValue function

Serializer for arbitrary store values

Source:

Returns:

Serialized store, null if empty

Type
Object | null
Serialize the store into a JSONable object

slice([start], [end]) → {ve.dm.HashValueStore} #

Return a new store containing a slice of the values in insertion order

Parameters:

Name Type Attributes Description
start number optional

Include values from position start onwards (default: 0)

end number optional

Include values to position end exclusive (default: slice to end)

Source:

Returns:

Slice of the current store (with non-cloned value references)

Type
ve.dm.HashValueStore
Return a new store containing a slice of the values in insertion order

value(hash) → {Object|undefined} #

Get the value stored for a particular hash

Parameters:

Name Type Description
hash string

Hash to look up

Source:

Returns:

Value stored for this hash if present, else undefined

Type
Object | undefined
Get the value stored for a particular hash

values(hashes) → {Array} #

Get the values stored for a list of hashes

Same as value but with arrays.

Parameters:

Name Type Description
hashes Array.<string>

Hashes to lookup

Source:

Returns:

Values for these hashes (undefined for any not present)

Type
Array

Get the values stored for a list of hashes

Same as value but with arrays.

deserialize(deserializeValue, data) → {ve.dm.HashValueStore}static #

Deserialize a store from a JSONable object

Parameters:

Name Type Description
deserializeValue function

Deserializer for arbitrary store values

data Object | null

Store serialized as a JSONable object

Source:

Returns:

Deserialized store

Type
ve.dm.HashValueStore
Deserialize a store from a JSONable object