Author(s): Tom Howland (http://home.pacbell.net/tomjdnh/pd.html), derived from work by Anil Nair, F. Bueno (for the Ciao package).
Version: 1.11#222 (2004/5/24, 13:8:7 CEST)
Version of last change: 1.11#101 (2003/12/21, 20:21:31 CET)
This package is an extension of the idea of Prolog indexing, usually performed, in a limited way, on the first argument. This package provides more powerful indexing schemes. It lets you pick different arguments to index on, and provides for different combinations of arguments to index on. E.g., it will let you index on the first and third argument or the second and the third argument of a predicate.
indexer
)indexer
)
Usage: :- index(IndexSpecs)
.
IndexSpecs
must be terms for the same predicate. Each spec declares an indexing on a combination of the arguments. Indexing will be performed using any of the specs in IndexSpecs
(being thus interpreted as an or).
You should use a *
in an argument position if you wish to hash on the entire term in that argument. If a +
is used only one level of the term in the argument is used for hashing. An i
is used to indicate that argument is already an integer, and therefore its own value will be used for hashing. The argspec ?
simply indicates not to use the argument for indexing.
For example, the index specification:
:- index foo(+,?,*,i), foo(?,?,?,i).declares indexing for
foo/4
either on a combination of the first, third, and fourht arguments, or only on the last argument, which is an integer. In the first case, only the principal functor of the first argument will be used for hashing; the third argument will be used in its entirety.
The argspec n
is a pragmatic extension and can not be used in conjunction with the other specifiers aside from ?
. It stands for "nonvar" and implies that the argument will not be used for hashing, since only ground terms can effectively be used in hashing. Thus, it can not be used in combination with other specifiers within a particular index specification. It is often the fastest thing to use.
IndexSpecs
is an index specification.
(indexer_doc:indexspecs/1
)
An index specification is defined as follows:
indexspecs(Spec) :- indexspec(Spec). indexspecs((Spec,Specs)) :- indexspec(Spec), indexspecs(Specs).
indexspec(Spec) :- Spec=..[_F|Args], list(Args,argspec).
Usage: indexspecs(IndexSpecs)
IndexSpecs
is an index specification.
An argument hash specification is defined as follows:
argspec(+). argspec(*). argspec(i). argspec(n). argspec(?).
Usage: argspec(Spec)
Spec
is an argument hash specification.
hash_term(Term, HashValue)
Provides an efficient way to calculate an integer HashValue
for a ground Term
.
Usage 1: hash_term(T, N)
N
is a hashing index for T
.
T
is currently ground (it contains no variables).
(term_typing:ground/1
)
N
is a free variable.
(term_typing:var/1
)
N
is an integer.
(basic_props:int/1
)
Usage 2: hash_term(T, N)
T
is not ground.
(native_props:nonground/1
)
N
is a free variable.
(term_typing:var/1
)
N
is a free variable.
(term_typing:var/1
)
Go to the first, previous, next, last section, table of contents.