Hash! datatype

1. Abstract

A `hash!` value provides a block-like interface with fast lookups.

The underlying hashing function is a custom implementation of the MurmurHash3 algorithm.

`Hash!` is a member of the following typesets: `default!`, `series!`, `any-block!`, `any-list!`

2. Creation

Hash values can be created at runtime by using a `make` constructor or a `to` conversion.

2.1. Runtime creation

``````>> list: make hash! [a 123 "hello" b c 789]
== make hash! [a 123 "hello" b c 789]``````
``````>> list: to hash! [a 123 "hello" b c 789]
== make hash! [a 123 "hello" b c 789]``````

3. Accessing `hash!` elements

3.1. Using `path!` notation

Getting a value, using `c` as a key.

``````>> list/c
== 789``````

Setting a value, using `c` as a key.

``````>> list/c: 42
== 42

>> list
== make hash! [a 123 "hello" b c 42]``````

3.2. Using `find`

``````>> find list 'b
== make hash! [b c 42]``````

3.3. Using `select`

``````>> dict: make hash! [a 123 b 456 c 789]
== make hash! [a 123 b 456 c 789]

>> select dict 'c
== 789

>> dict: make hash! [2 123 4 456 6 2 8 789]
== make hash! [2 123 4 456 6 2 8 789]

>> select/skip dict 2 2
== 123``````

4. Data set operations

The following data set operations are possible with hash values: `difference`, `exclude`, `intersect`, `union`, `unique`

``````>> dict1: make hash! [a 123 b 456 c 789]
== make hash! [a 123 b 456 c 789]

>> dict2: make hash! [2 123 4 456 6 2 8 789]
== make hash! [2 123 4 456 6 2 8 789]``````
``````>> difference dict1 dict2
== make hash! [a b c 2 4 6 8]``````
``````>> exclude dict1 dict2
== make hash! [a b c]``````
``````>> intersect dict1 dict2
== make hash! [123 456 789]``````
``````>> union dict1 dict2
== make hash! [a 123 b 456 c 789 2 4 6 8]``````
``````>> unique dict2
== make hash! [2 123 4 456 6 8 789]``````

5. Comparisons

All comparators can be applied on `hash!`: `=, ==, <>, >, <, >=, <=, =?`. In addition, `min`, and `max` are also supported.

6. Testing values

Use `hash?` to check if a value is of the `hash!` datatype.

``````>> hash? dict1
== true``````

Use `type?` to return the datatype of a given value.

``````>> type? dict2
== hash!``````

7. Predefined words

7.1. Functions

`average`, `hash?`, `path-thru`, `sum`, `to-hash`

7.2. Natives

`checksum`, `difference`, `exclude`, `extend`, `intersect`, `union`, `unique`