| fprint_mindex | mindex_empty | mindex_retrieve_cancel | mindex_update |
| fprint_mindex_mem | mindex_free | mindex_retrieve_first | p_mindex_mem |
| mindex_destroy | mindex_init | mindex_retrieve_next |
void fprint_mindex(FILE *fp, Mindex mdx);This routine prints (to FILE *fp) Mindex mdx.
void fprint_mindex_mem(FILE *fp, BOOL heading);This routine prints (to FILE *fp) memory usage statistics for data types associated with the mindex package. The Boolean argument heading tells whether to print a heading on the table.
void mindex_destroy(Mindex mdx);This frees all the memory associated with an Mindex. Do not refer to the Mindex after calling this routine.
BOOL mindex_empty(Mindex mdx);This Boolean routine checks if an Mindex is empty, that is, has no terms. It must exist (be non-NULL).
void mindex_free(Mindex mdx);This routine frees an empty Mindex. (If the Mindex is not empty, nothing happens.)
Mindex mindex_init(Mindextype mtype, Uniftype utype, int fpa_depth);This routine allocates and returns an (empty) Mindex, which is used to retrieve unifiable terms.
Associative-commutative (AC) and commutative (C) symbols. DISCRIM_BIND does not support AC symbols. All other combinations are okay. If you have any AC or C symbols, you must specify unif_type BACKTRACK_UNIF. (BACKTRACK_UNIF is also okay with no AC or C symbols, but it is a little bit slower than ORDINARY_UNIF.)
AC symbols must be declared (with set_assoc_comm()) before calling mindex_update(). C symbols need not be declared before mindex_update(), but they must be declared (with set_commutative()) before calling mindex_retrieve_first().
void mindex_retrieve_cancel(Mindex_pos pos);This routine should be called if you get some, but not all, answers to a query. For example, if you need only one answer you can do something like the following:
{
Mindex_pos pos;
Term t2;
Context cf = get_context();
t2 = mindex_retrieve_first(t, mdx, GENERALIZATION, (Context) NULL, cf, &pos);
if (t2 != NULL) {
printf("we found a mate!\n");
mindex_retrieve_cancel(pos);
}
else
printf("no answer\n");
free_context(cf);
}
If you fail to call this routine, then the memory associated
with an Mindex_pos will be forever lost, that is, you will have
a memory leak.
Term mindex_retrieve_first(Term t, Mindex mdx, Querytype qtype, Context query_subst, Context found_subst, BOOL partial_match, Mindex_pos *ppos);This routine finds and returns the first answer to a query (returning NULL if there are no answers).
Here is an example of how to retrieve all answers. Assume we have Term t and Mindex mdx.
{
Mindex_pos pos;
Term t2;
Context cq = get_context();
Context cf = get_context();
int n = 0;
t2 = mindex_retrieve_first(t, mdx, UNIFY, cq, cf, FALSE, &pos);
while (t2 != NULL) {
t2 = mindex_retrieve_next(pos);
n++;
}
free_context(cq);
free_context(cf);
printf("there are %d mates\n", n);
}
Term mindex_retrieve_next(Mindex_pos pos);This routine finds and returns the next answer to a query. See mindex_retrieve_first() for an explanation.
void mindex_update(Mindex mdx, Term t, Indexop op);This routine inserts (op==INSERT) or deletes (op==DELETE) a Term t into/from an Mindex mdx.
It is your responsibility to remember that t is in the index, because we don't currently have a routine "mindex_member()".
void p_mindex_mem();This routine prints (to stdout) memory usage statistics for data types associated with the mindex package.
/* types of index */
typedef enum { LINEAR,
FPA,
DISCRIM_WILD,
DISCRIM_BIND
} Mindextype;
/* types of unification */
typedef enum { ORDINARY_UNIF,
BACKTRACK_UNIF
} Uniftype;
typedef struct mindex * Mindex;
typedef struct mindex_pos * Mindex_pos;
struct mindex {
Mindextype index_type;
Uniftype unif_type;
/* FPA */
Fpa_index fpa;
/* LINEAR */
Plist linear_first;
Plist linear_last;
/* DISCRIM_WILD and DISCRIM_BIND */
Discrim discrim_tree;
Mindex next; /* for avail list */
};
Types of Retrieval
UNIFY, INSTANCE, GENERALIZATION, VARIANT, IDENTICAL.
Types of Unification
Associative-commutative (AC) and commutative/symmetric (C) symbols are supported in most cases. If you have any AC or C symbols, you must use backtrack unification, which handles more than one unifier for a pair of terms; otherwise, you can use ordinary unification, which assumes at most one unifier for a pair of terms. (For the empty theory, ordinary unification is a bit faster than backtrack unification.)
Types of Indexing