next up previous contents index
Next: Unification Factoring Up: Compiler Directives Previous: Tabling Directives   Contents   Index


Indexing Directives

The XSB compiler usually generates an index on the principal functor of the first argument of a predicate. Indexing on the appropriate argument of a predicate may significantly speed up its execution time. In many cases the first argument of a predicate may not be the most appropriate argument for indexing and changing the order of arguments may seem unnatural. In these cases, the user may generate an index on any other argument by means of an indexing directive. This is a directive of the form:

:- index Functor/Arity-IndexArg.

indicating that an index should be created for predicate Functor/ Arity on its ${\tt IndexArg}^{\rm th}$ argument. One may also use the form:

:- index(Functor/Arity, IndexArg, HashTableSize).

which allows further specification of the size of the hash table to use for indexing this predicate if it is a dynamic (i.e., asserted) predicate. For predicates that are dynamically loaded, this directive can be used to specify indexing on more than one argument, or indexing on a combination of arguments (see its description on page [*]). For a compiled predicate the size of the hash table is computed automatically, so HashTableSize is ignored.

All of the values Functor, Arity, IndexArg (and possibly HashTableSize) should be ground in the directive. More specifically, Functor should be an atom, Arity an integer in the range 0..255, and IndexArg an integer between 0 and Arity. If IndexArg is equal to 0, then no index is created for that predicate. An index directive may be placed anywhere in the file containing the predicate it refers to.

As an example, if we wished to create an index on the third argument of predicate foo/5, the compiler directive would be:

:- index foo/5-3.


next up previous contents index
Next: Unification Factoring Up: Compiler Directives Previous: Tabling Directives   Contents   Index
Baoqiu Cui
2000-04-23