4.14.1.2 Indexing databases
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Database
          • Managing (dynamic) predicates
            • Indexing databases
              • term_hash/2
              • term_hash/4
              • variant_sha1/2
              • variant_hash/2
    • Packages
Availability:built-in
[det]term_hash(+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 leaves HashKey an unbound variable. Hash keys are in the range 0 ... 72,057,594,037,927,935 (2^56), the maximal integer that can be stored efficiently (see max_tagged_integer.

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 and versions of SWI-Prolog.90Last change: version 9.3.28 The term_hash/2 predicate is cycle-safe.bugAll arguments that (indirectly) lead to a cycle have the same hash key. bugHashes differ between big and little endian machines and hashes for big integers (currently > 2^56) differ depending on the big integer backend (GMP or LibBF). See gmp_version.