Changes Rtree so almost working
This commit is contained in:
parent
8511e87e32
commit
43e459b8f8
90
C/udi.c
90
C/udi.c
@ -2,6 +2,7 @@
|
|||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
#include "clause.h"
|
#include "clause.h"
|
||||||
|
#include "clause_list.h"
|
||||||
#include "udi.h"
|
#include "udi.h"
|
||||||
#include "utarray.h"
|
#include "utarray.h"
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ p_new_udi( USES_REGS1 )
|
|||||||
UdiInfo blk;
|
UdiInfo blk;
|
||||||
int info;
|
int info;
|
||||||
|
|
||||||
fprintf(stderr,"new pred\n");
|
//fprintf(stderr,"new pred\n");
|
||||||
|
|
||||||
/* get the predicate from the spec, copied from cdmgr.c */
|
/* get the predicate from the spec, copied from cdmgr.c */
|
||||||
if (IsVarTerm(spec)) {
|
if (IsVarTerm(spec)) {
|
||||||
@ -123,13 +124,18 @@ p_new_udi( USES_REGS1 )
|
|||||||
|
|
||||||
/* this is the real work */
|
/* this is the real work */
|
||||||
blk = (UdiInfo) Yap_AllocCodeSpace(sizeof(struct udi_info));
|
blk = (UdiInfo) Yap_AllocCodeSpace(sizeof(struct udi_info));
|
||||||
|
memset((void *) blk,0, sizeof(struct udi_info));
|
||||||
|
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
Yap_Error(OUT_OF_HEAP_ERROR, spec, "new user index/1");
|
Yap_Error(OUT_OF_HEAP_ERROR, spec, "new user index/1");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
blk->next = UdiControlBlocks;
|
blk->next = UdiControlBlocks;
|
||||||
blk->clauselist = NULL;
|
utarray_new(blk->clauselist, &ptr_icd);
|
||||||
blk->p = p;
|
blk->p = p;
|
||||||
|
UdiControlBlocks = blk;
|
||||||
|
|
||||||
|
//fprintf(stderr,"PRED %p\n",p);
|
||||||
|
|
||||||
info = Yap_udi_args_init(spec, p->ArityOfPE, blk);
|
info = Yap_udi_args_init(spec, p->ArityOfPE, blk);
|
||||||
if (!info)
|
if (!info)
|
||||||
@ -150,24 +156,22 @@ Yap_udi_args_init(Term spec, int arity, UdiInfo blk)
|
|||||||
Atom idxtype;
|
Atom idxtype;
|
||||||
UdiControlBlock *p;
|
UdiControlBlock *p;
|
||||||
|
|
||||||
fprintf(stderr,"udi init\n");
|
//fprintf(stderr,"udi init\n");
|
||||||
|
|
||||||
for (i = 1; i <= arity && i <= UDI_MI ; i++) {
|
for (i = 1; i <= arity && i <= UDI_MI ; i++) {
|
||||||
blk->args[i-1].idxstr = NULL;
|
|
||||||
blk->args[i-1].control = NULL;
|
|
||||||
fprintf(stderr,"%d\n",i);
|
|
||||||
arg = ArgOfTerm(i,spec);
|
arg = ArgOfTerm(i,spec);
|
||||||
if (IsAtomTerm(arg)) {
|
if (IsAtomTerm(arg)) {
|
||||||
idxtype = AtomOfTerm(arg);
|
idxtype = AtomOfTerm(arg);
|
||||||
fprintf(stderr,"%p-%s %p-%s\n",idxtype, YAP_AtomName(idxtype),
|
// fprintf(stderr,"%p-%s %p-%s\n",idxtype, YAP_AtomName(idxtype),
|
||||||
AtomMinus, YAP_AtomName(AtomMinus));
|
// AtomMinus, YAP_AtomName(AtomMinus));
|
||||||
if (idxtype == AtomMinus)
|
if (idxtype == AtomMinus)
|
||||||
continue;
|
continue;
|
||||||
p = NULL;
|
p = NULL;
|
||||||
while ((p = (UdiControlBlock *) utarray_next(indexing_structures, p))) {
|
while ((p = (UdiControlBlock *) utarray_next(indexing_structures, p))) {
|
||||||
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].idxstr = NULL;
|
|
||||||
blk->args[i-1].control = *p;
|
blk->args[i-1].control = *p;
|
||||||
|
blk->args[i-1].idxstr = (*p)->init(spec, NULL, arity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blk->args[i-1].control == NULL){ /* not "-" and not found*/
|
if (blk->args[i-1].control == NULL){ /* not "-" and not found*/
|
||||||
@ -183,6 +187,8 @@ Yap_udi_args_init(Term spec, int arity, UdiInfo blk)
|
|||||||
int
|
int
|
||||||
Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
|
Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
/* find our structure*/
|
/* find our structure*/
|
||||||
struct udi_info *info = UdiControlBlocks;
|
struct udi_info *info = UdiControlBlocks;
|
||||||
while (info->p != p && info)
|
while (info->p != p && info)
|
||||||
@ -191,21 +197,81 @@ Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* do the actual insertion */
|
/* do the actual insertion */
|
||||||
fprintf(stderr,"udi insert\n");
|
|
||||||
|
/*insert into clauselist*/
|
||||||
|
utarray_push_back(info->clauselist,(void *) cl);
|
||||||
|
|
||||||
|
for (i = 0; i < UDI_MI ; i++) {
|
||||||
|
if (info->args[i].control != NULL){
|
||||||
|
// fprintf(stderr,"call insert\n");
|
||||||
|
info->args[i].control->insert(t,info->args[i].idxstr, (void *)cl);
|
||||||
// info->cb = info->functions->insert(t, info->cb, (void *)cl);
|
// info->cb = info->functions->insert(t, info->cb, (void *)cl);
|
||||||
|
}
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CallbackM
|
||||||
|
{
|
||||||
|
clause_list_t cl;
|
||||||
|
void * pred;
|
||||||
|
};
|
||||||
|
typedef struct CallbackM * callback_m_t;
|
||||||
|
|
||||||
|
static int callback(void *key, void *data, void *arg)
|
||||||
|
{
|
||||||
|
callback_m_t x;
|
||||||
|
x = (callback_m_t) arg;
|
||||||
|
return Yap_ClauseListExtend(x->cl,data,x->pred);
|
||||||
|
}
|
||||||
|
|
||||||
/* index, called from absmi.c */
|
/* index, called from absmi.c */
|
||||||
yamop *
|
yamop *
|
||||||
Yap_udi_search(PredEntry *p)
|
Yap_udi_search(PredEntry *p)
|
||||||
{
|
{
|
||||||
|
int i, r = -1;
|
||||||
|
struct ClauseList clauselist;
|
||||||
|
struct CallbackM cm;
|
||||||
|
callback_m_t c;
|
||||||
|
|
||||||
|
/* find our structure*/
|
||||||
struct udi_info *info = UdiControlBlocks;
|
struct udi_info *info = UdiControlBlocks;
|
||||||
while (info->p != p && info)
|
while (info->p != p && info)
|
||||||
info = info->next;
|
info = info->next;
|
||||||
if (!info)
|
if (!info)
|
||||||
return NULL;
|
return NULL;
|
||||||
return NULL; /*info->functions->search(info->cb);*/
|
|
||||||
|
/*TODO: handle intersection*/
|
||||||
|
c = &cm;
|
||||||
|
c->cl = Yap_ClauseListInit(&clauselist);
|
||||||
|
c->pred = p;
|
||||||
|
for (i = 0; i < UDI_MI ; i++) {
|
||||||
|
if (info->args[i].control != NULL){
|
||||||
|
// fprintf(stderr,"call search %d %p\n", i, (void *)c);
|
||||||
|
r = info->args[i].control->search(info->args[i].idxstr, callback,c);
|
||||||
|
/*info->functions->search(info->cb);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Yap_ClauseListClose(c->cl);
|
||||||
|
|
||||||
|
if (r >= 0) {
|
||||||
|
if (Yap_ClauseListCount(c->cl) == 0)
|
||||||
|
{
|
||||||
|
Yap_ClauseListDestroy(c->cl);
|
||||||
|
return Yap_FAILCODE();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Yap_ClauseListCount(c->cl) == 1)
|
||||||
|
{
|
||||||
|
return Yap_ClauseListToClause(c->cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Yap_ClauseListCode(c->cl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Yap_ClauseListDestroy(c->cl);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* index, called from absmi.c */
|
/* index, called from absmi.c */
|
||||||
|
@ -15,6 +15,12 @@ typedef void *
|
|||||||
void *control, /* estrutura de control*/
|
void *control, /* estrutura de control*/
|
||||||
void *clausule); /* valor a guardar na arvore, para retornar na pesquisa */
|
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
|
/* chamada cada vez que um predicado indexado aparece no código
|
||||||
Returns:
|
Returns:
|
||||||
NULL quando não há indexação usavel no predicado (fallback to
|
NULL quando não há indexação usavel no predicado (fallback to
|
||||||
@ -23,7 +29,9 @@ yap indexing)
|
|||||||
TRY_RETRY_TRUST quando há resultados positivos
|
TRY_RETRY_TRUST quando há resultados positivos
|
||||||
*/
|
*/
|
||||||
typedef void *
|
typedef void *
|
||||||
(* Yap_UdiSearch)(void * control);
|
(* Yap_UdiSearch)(void * control,
|
||||||
|
Yap_UdiCallback f, /* callback on each found value*/
|
||||||
|
void *arg);
|
||||||
|
|
||||||
/* chamada cada vez que um predicado indexado aparece no código
|
/* chamada cada vez que um predicado indexado aparece no código
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8c00c4e1eb0b23d4c63ee1b64265a26ceb28ac64
|
Subproject commit 5431e61ef86b65adf62fda7d71683f4780e4e2fa
|
@ -22,5 +22,4 @@
|
|||||||
******************/
|
******************/
|
||||||
|
|
||||||
udi(Pred) :-
|
udi(Pred) :-
|
||||||
writeln(('udi.yap ',Pred)),
|
|
||||||
'$udi_init'(Pred).
|
'$udi_init'(Pred).
|
||||||
|
Reference in New Issue
Block a user