diff --git a/C/exo.c b/C/exo.c index 9a7561279..a0f9585e1 100644 --- a/C/exo.c +++ b/C/exo.c @@ -381,6 +381,8 @@ Yap_ExoLookup(PredEntry *ap USES_REGS) } if (count) { yamop *code = LOOKUP(i, arity, j0, LOCAL_ibnds); + if (code == FAILCODE) + return code; if (i->is_udi) return ((CEnterExoIndex)i->udi_first)(i PASS_REGS); else return code; diff --git a/C/exo_udi.c b/C/exo_udi.c index e9da05cab..aef754e36 100644 --- a/C/exo_udi.c +++ b/C/exo_udi.c @@ -90,7 +90,7 @@ compare(const BITS32 *ip, Int j USES_REGS) { BITS32 *sorted0, *sorted; /* be conservative */ - sz = sizeof(BITS32)*(it->ntrys+it->nentries); + sz = sizeof(BITS32)*(2*it->ntrys+it->nentries); /* allocate space */ if (!(it->udi_data = malloc(sz))) return; diff --git a/H/clause.h b/H/clause.h index eb4fd51d6..9d565a53a 100644 --- a/H/clause.h +++ b/H/clause.h @@ -176,7 +176,8 @@ typedef struct index_t { BITS32 *links; size_t size; yamop *code; - void *udi_data, *udi_first, *udi_next; + BITS32 *udi_data; + void *udi_first, *udi_next; UInt udi_arg; } Index_t; diff --git a/docs/yap.tex b/docs/yap.tex index b1ae24468..0fe01fe4d 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -9095,11 +9095,11 @@ This package assumes you use UDI exo-indexing, that is: @end example It is designed to optimise the following type of queries: @example -?- max(X, diagnoses(X, 9, Y)). +?- max(X, diagnoses(X, 9, Y), X). -?- min(X, diagnoses(X, 9, 36211117)). +?- min(X, diagnoses(X, 9, 36211117), X). -?- X #< Y, min(X, diagnoses(9, X, 36211117)), diagnoses(Y, 9, _). +?- X #< Y, min(X, diagnoses(X, 9, 36211117), X ), diagnoses(Y, 9, _). @end example The first argument gives the time, the second the patient, and the third the condition code. The first query should find the last time diff --git a/library/exo_interval.yap b/library/exo_interval.yap index b4098e4a0..a625386aa 100644 --- a/library/exo_interval.yap +++ b/library/exo_interval.yap @@ -89,6 +89,19 @@ X #=< Y :- X =< Y ). +X #= Y :- + ( var(X) -> insert_atts(X, i(Y-1,Y+1,_)) + ; + ( var(Y) -> insert_atts(Y, i(X-1,X+1,_) ) ; + true + ) + ; + var(Y) -> insert_atts(Y, i(X-1,X+Y,_)) + ; + X =:= Y + ). + + attribute_goals(X) --> { get_attr(X, exo_interval, Op) }, ( { Op = max } -> [max(X)] ;