This library provides a non-backtrackabe set of terms that are
variants of each other. It is primarily intended to implement distinct/1
from library(solution_sequences). The set is implemented as a hash table
that is built using non-backtrackable primitives, notably nb_setarg/3.
The original version of this library used binary trees which provides
immediate ordering. As the trees were not balanced, performance could
get really poor. The complexity of balancing trees using
non-backtrackable primitives is too high. The next iteration used open
hash tables, while the current incarnation uses closed hash tables,
providing better perfomance and less space usage.
- author
- - Jan Wielemaker
- empty_nb_set(-Set)
- Create an empty non-backtrackable set.
- add_nb_set(+Key, !Set) is det
- add_nb_set(+Key, !Set, ?New) is semidet
- Insert Key into the set. If a variant (see =@=/2) of Key is
already in the set, the set is unchanged and New is unified with
false
. Otherwise, New is unified with true
and a copy of
Key is added to the set.
- To be done
- - Computing the hash for cyclic terms is performed with
the help of term_factorized/3, which performs rather
poorly.
- index(+Hash, +Capacity, -Index) is nondet[private]
- Generate candidate values for Index, starting from
Hash mod
Capacity
, round tripping to 1 when Capacity is reached.
- hash_key(+Key, -Hash:integer) is det[private]
- Compute a hash for Term. Note that variant_hash/2 currently does
not handle cyclic terms, so use term_factorized/3 to get rid of
the cycles. This means that this library is rather slow when
cyclic terms are involved.
- nb_set_to_list(+NBSet, -OrdSet) is det
- nb_set_to_list(-NBSet, +List) is det
- Get the elements of a an nb_set. OrdSet is sorted to the standard
order of terms, providing a set representation that is compatible to
library(ordsets).
- gen_nb_set(+Set, -Key) is nondet
- Enumerate the members of a set in the standard order of terms.
- size_nb_set(+Set, -Size) is det
- Unify Size with the number of elements in the set
Re-exported predicates
The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
- add_nb_set(+Key, !Set) is det
- add_nb_set(+Key, !Set, ?New) is semidet
- Insert Key into the set. If a variant (see =@=/2) of Key is
already in the set, the set is unchanged and New is unified with
false
. Otherwise, New is unified with true
and a copy of
Key is added to the set.
- To be done
- - Computing the hash for cyclic terms is performed with
the help of term_factorized/3, which performs rather
poorly.