[Up] [Contents] [Index] [Summary]

3.10.1 Indexing databases

By default, SWI-Prolog, as most other implementations, indexes predicates on their first argument. SWI-Prolog allows indexing on other and multiple arguments using the declaration index/1.

For advanced database indexing, it defines hash_term/2:

hash_term(+Term, -HashKey)
If Term is a ground term (see ground/1), HashKey is unified with a positive integer value that may be used as a hash-key to the value. If Term is not ground, the predicate succeeds immediately, leaving HashKey an unbound variable.

This predicate may be used to build hash-tables as well as to exploit argument-indexing to find complex terms more quickly.

The hash-key does not rely on temporary information like addresses of atoms and may be assumed constant over different invocations of SWI-Prolog.