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:
- 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
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
getLength() → {number}
#
Get the number of values in the store
- Source:
Returns:
Number of values in the store
- Type
- number
hash(value, [stringified]) → {string}
#
hashAll(values) → {Array.<string>}
#
Get the hashes of values in the store
Same as hash but with arrays.
Parameters:
- 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
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:
replaceHash(oldHash, value) → {string}
#
serialize(serializeValue) → {Object|null
}
#
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
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
value(hash) → {Object|undefined
}
#
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
values(hashes) → {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