nikita-volkov / hashing-containers / HashingContainers.HashDict

HashDict API.


type HashDict key value

Generic dictionary from hashable keys to values.

Unlike Dict from the "core" library it is not limited to any specific set of supported types for keys.

Unlike the association list implementations it does not suffer from linear performance characteristics.

Construction

All construction functions require you to provide instances for Equality and Hashing explicit typeclasses.

For general introduction to explicit typeclasses, see the readme of the "typeclasses" library.

empty : Typeclasses.Classes.Equality.Equality key -> Typeclasses.Classes.Hashing.Hashing key -> HashDict key value

Construct an empty HashDict, providing the required instances for key.

fromList : Typeclasses.Classes.Equality.Equality key -> Typeclasses.Classes.Hashing.Hashing key -> List ( key, value ) -> HashDict key value

Construct HashDict from a list of association pairs, providing the required instances for key.

fromArray : Typeclasses.Classes.Equality.Equality key -> Typeclasses.Classes.Hashing.Hashing key -> Array ( key, value ) -> HashDict key value

Construct HashDict from an array of association pairs, providing the required instances for key.

Transformation

insert : key -> value -> HashDict key value -> HashDict key value

Insert an association pair into dictionary, replacing a value if it already exists.

remove : key -> HashDict key value -> HashDict key value

Remove a key-value pair from a dictionary. If the key is not found, no changes are made.

update : key -> (Maybe value -> Maybe value) -> HashDict key value -> HashDict key value

Update the value of a dictionary for a specific key with a given function.

Access

get : key -> HashDict key value -> Maybe value

Lookup a value by key. Returns Nothing, when there is none.

isEmpty : HashDict key value -> Basics.Bool

Determine if a dictionary is empty.

size : HashDict key value -> Basics.Int

O(n). Count the elements of the dict. Same as foldl (\ _ x -> x + 1) 0.

foldl : (( key, value ) -> folding -> folding) -> folding -> HashDict key value -> folding

Fold over the key-value pairs in the dictionary.

toList : HashDict key value -> List ( key, value )

Convert a dictionary into an association list of key-value pairs.