Did you know ... | Search Documentation: |
Pack hashtbl -- prolog/hashtbl/utils.pl |
Both variants of the hashtbl library share a common data representation: A hash table is a term nb_hashtbl/2 or p_hashtbl/2. The first argument contains metadata such as the hash table's current load. The second is a term bucket/N containing the hash buckets. Hash buckets are lists of Key-Values pairs where Key is a hash table key (a ground term) and Values is the list of Values associated with that key. Each key only occurs once in the table. When several values are added for the same key, later ones come before the older ones in the Values list. They have "higher priority" and are said to "shadow" the older values.
Due to this common representation of hash tables, many operations are identical on the two variants, differing only in the outermost functor. These non-destructive common operations, such as getting values from the table, or mapping higher-order predicates over the table, are defined in this module.
The concrete implementations of the hash tables use the predicates from this module. This is the only intended use of this module: It should be treated as internal to the library. Clients of the library should use one of the concrete hash table modules.
nb_hashtbl_get(Table, Key, _)
to test whether Key is
present in Table.If Key is ground, this behaves like hashtbl_get_all/3 for that Key. However, hashtbl_get_all/3 is more efficient in this case.
Goal(Key, Value, Value1)
and
unifies TableOut with a hash table containing all Key-Value1 pairs.
Deterministic if Goal is deterministic. If Goal backtracks,
hashtbl_map/3 enumerates several TableOut tables accordingly.Goal(Key,
Value, Acc, Result)
, using each call's Result as the next call's
accumulator Acc, and unifying Result with the final call's Result.
Deterministic if Goal is deterministic. If Goal backtracks, enumerates
several results accordingly.Goal(Key, Value)
for every Key and Value stored in Table. This
is useful to ensure that all entries satisfy some predicate, or for
Goal's side effects. Deterministic if Goal is deterministic.