UDI: more work

This commit is contained in:
David Vaz 2012-12-20 17:13:30 +00:00
parent a655c0bb51
commit 4efa594f0a
3 changed files with 82 additions and 52 deletions

View File

@ -68,7 +68,7 @@ int Yap_udi_args_init(Term spec, int arity, UdiInfo blk);
* New user indexed predicate: * New user indexed predicate:
* the first argument is the term. * the first argument is the term.
*/ */
static Int static int
p_new_udi( USES_REGS1 ) p_new_udi( USES_REGS1 )
{ {
Term spec = Deref(ARG1); Term spec = Deref(ARG1);
@ -171,7 +171,7 @@ Yap_udi_args_init(Term spec, int arity, UdiInfo blk)
//fprintf(stderr,"cb: %p %p-%s\n", *p, (*p)->decl, YAP_AtomName((*p)->decl)); //fprintf(stderr,"cb: %p %p-%s\n", *p, (*p)->decl, YAP_AtomName((*p)->decl));
if (idxtype == (*p)->decl){ if (idxtype == (*p)->decl){
blk->args[i-1].control = *p; blk->args[i-1].control = *p;
blk->args[i-1].idxstr = (*p)->init(spec, NULL, arity); blk->args[i-1].idxstr = (*p)->init(spec, i, arity);
} }
} }
if (blk->args[i-1].control == NULL){ /* not "-" and not found*/ if (blk->args[i-1].control == NULL){ /* not "-" and not found*/
@ -204,7 +204,7 @@ Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
for (i = 0; i < UDI_MI ; i++) { for (i = 0; i < UDI_MI ; i++) {
if (info->args[i].control != NULL){ if (info->args[i].control != NULL){
//fprintf(stderr,"call insert\n"); //fprintf(stderr,"call insert\n");
info->args[i].control->insert(t,info->args[i].idxstr, (void *)cl); info->args[i].idxstr = info->args[i].control->insert(info->args[i].idxstr, t, i + 1, (void *)cl);
// info->cb = info->functions->insert(t, info->cb, (void *)cl); // info->cb = info->functions->insert(t, info->cb, (void *)cl);
} }
} }
@ -248,7 +248,7 @@ Yap_udi_search(PredEntry *p)
for (i = 0; i < UDI_MI ; i++) { for (i = 0; i < UDI_MI ; i++) {
if (info->args[i].control != NULL){ if (info->args[i].control != NULL){
// fprintf(stderr,"call search %d %p\n", i, (void *)c); // fprintf(stderr,"call search %d %p\n", i, (void *)c);
r = info->args[i].control->search(info->args[i].idxstr, callback,c); r = info->args[i].control->search(info->args[i].idxstr, i + 1, callback, c);
/*info->functions->search(info->cb);*/ /*info->functions->search(info->cb);*/
} }
} }

View File

@ -1,48 +1,78 @@
/*chamada a cada index/2 /*
controi estrutura de control, para definir a indexação, contem a * This file is part of the YAP Prolog
rtree p.e. *
retorna a estrutura de control * User Defined Indexing was developed by:
* David Vaz <davidvaz@dcc.fc.up.pt>
* Vitor Santos Costa <vsc@dcc.fc.up.pt>
*
* UDI Indexing Interface:
*
* Each new indexing mechanism should register it self by filling up a
* UdiControlBlock and calling Yap_UdiRegister(UdiControlBlock).
*
* UdiControlBlock has the main declaration that triggers the
* indexing structure as well as the pointers to the needed functions
* called at the appropriate times.
*
* For now each indexing structure only works with a single argument
* even when multiple arguments are indexed with the same struture.
*
* TODO: think of alternamive ways of support both cases, e.g. a rtree
* does not benefit from multiple rtree indexing, but a hash table do
*/ */
typedef void *
(* Yap_UdiInit)( /* This is called upon udi mode spec call, and the purpose is to allow
YAP_Term spec, /* mode spec */ * the indexing struture to initialize itself.
void *pred, /* pass predicate information */ * Should return the need opaque struture to be used in future calls
*
* arg is used to track the specific call, on multiple indexing with the
* same struture
*/
typedef void * (* Yap_UdiInit)
(YAP_Term spec,
int arg, /* argument regarding this call */
int arity); int arity);
/*chamada a cada assert*/ /* Upon each assert the struture insert method is called to perform
typedef void * * its work
(* Yap_UdiInsert)(YAP_Term t, /* termo asserted */
void *control, /* estrutura de control*/
void *clausule); /* valor a guardar na arvore, para retornar na pesquisa */
/* Callback for each value found in a search */
typedef int /* with a FALSE return should abort the search */
(* Yap_UdiCallback) (void *key, /*index key*/
void *clausule, /*clause*/
void *arg); /* auxiliary to callback */
/* chamada cada vez que um predicado indexado aparece no código
Returns:
NULL quando não indexação usavel no predicado (fallback to
yap indexing)
FALSE
TRY_RETRY_TRUST quando resultados positivos
*/ */
typedef void * typedef void * (* Yap_UdiInsert)
(* Yap_UdiSearch)(void * control, (void *control, /* indexing structure opaque handle */
YAP_Term term, /* asserted argument */
int arg, /* argument regarding this call */
void *data); /* value to return on search */
/* Callback for each value found in a search
* if it returns FALSE the search should be immediately aborted
*/
typedef int (* Yap_UdiCallback)
(void *key, /* index key */
void *data, /* data */
void *arg); /* auxiliary data to callback */
/* Called upon search
*
* If there is any search to do with this struture should return >= 0
* corresponding to the values found
*
* returns -1 if there is nothing to search with this indexing structure
* e.g. a Variable as argument
*/
typedef int (* Yap_UdiSearch)
(void * control, /* indexing structure opaque handle */
int arg, /* argument regarding this call */
Yap_UdiCallback f, /* callback on each found value */ Yap_UdiCallback f, /* callback on each found value */
void *arg); void *args); /* auxiliary data to callback */
/* chamada cada vez que um predicado indexado aparece no código /* Called upond abolish of the term
Returns: * to allow for a clean destroy of the indexing structures
NULL quando não indexação usavel no predicado (fallback to
yap indexing)
FALSE
TRY_RETRY_TRUST quando resultados positivos
*/ */
typedef int typedef int (* Yap_UdiDestroy)
(* Yap_UdiDestroy)(void * control); (void * control);
/*
* Main structure used in UDI
*/
typedef struct udi_control_block { typedef struct udi_control_block {
YAP_Atom decl; //atom that triggers this indexing structure YAP_Atom decl; //atom that triggers this indexing structure
Yap_UdiInit init; Yap_UdiInit init;
@ -51,5 +81,5 @@ typedef struct udi_control_block {
Yap_UdiDestroy destroy; Yap_UdiDestroy destroy;
} * UdiControlBlock; } * UdiControlBlock;
/* used to register the new indexing structure */ /* Register a new indexing structure */
void Yap_UdiRegister(UdiControlBlock); void Yap_UdiRegister(UdiControlBlock);

@ -1 +1 @@
Subproject commit 13e78d741400614b2b7da1fecf83a7c6ce1ecb8d Subproject commit 5ee82f11ac12dbd22ec8fca040bc6589cc9f7683