fprint_mindex | mindex_destroy | mindex_init | mindex_retrieve_first |
fprint_mindex_mem | mindex_empty | mindex_insert | mindex_retrieve_next |
mindex_delete | mindex_free | mindex_retrieve_cancel | p_mindex_mem |
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 general mindexing. The Boolean argument heading tells whether to print a heading on the table.
void mindex_delete(Mindex mdx, Term t);This routine removes Term t from an Mindex mdx. A fatal error can occur if t is not a member of the Mindex.
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/symmetric (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_insert(). C symbols need not be declared before mindex_insert(), but they must be declared (with set_commutative()) before calling mindex_retrieve_first().
void mindex_insert(Mindex mdx, Term t);This routine inserts Term t into 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()". The Term field "INDEX_ID" is reserved for use by this routine and its subordinates.
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 p_mindex_mem(void);This routine prints (to stdout) memory usage statistics for data types associated with general mindexing.
/* types of index */ typedef enum { LINEAR, FPA, DISCRIM, DISCRIM_BIND } Mindextype; /* types of unification */ typedef enum { ORDINARY_UNIF, BACKTRACK_UNIF } Uniftype; /* types of retrieval */ typedef enum { UNIFY, INSTANCE, GENERALIZATION, VARIANT, IDENTICAL } Querytype; typedef struct mindex * Mindex; typedef struct mindex_pos * Mindex_pos; struct mindex { Mindextype index_type; Uniftype unif_type; /* FPA */ Fpa_index fpa; /* LINEAR */ Glist linear_first; Glist linear_last; /* DISCRIM 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
These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.