Hash tables are one of the many key-value representations available to SWI-Prolog.
This module implements a hash table as a mutable and backtrackable data structure. The hash table is implemented as a closed hash table, where the buckets array is implemented using an unbounded arity compound term. Elements in this array are manipulated using setarg/3.
Hash tables allow for any Prolog data types as keys or values, except
that the key cannot be a variable. Applications that require a plain
variable as key can do so by wrapping all keys in a compound, e.g.,
k(Var)
.
update_word_count(HT, Word) :- ( ht_update(HT, Word, Old, New) -> New is Old+1 ; ht_put(HT, Word, 1) ).
ht_put_list(HT, Key, Value) :- ht_put(HT, Key, [Value|Tail], [], Tail).