Changeset: cd42437881d1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cd42437881d1
Modified Files:
        monetdb5/modules/mal/txtsim.c
        monetdb5/modules/mal/txtsim.h
        monetdb5/modules/mal/txtsim.mal
Branch: default
Log Message:

Split return BAT for qgram operation


diffs (78 lines):

diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c
--- a/monetdb5/modules/mal/txtsim.c
+++ b/monetdb5/modules/mal/txtsim.c
@@ -875,11 +875,11 @@ fstrcmp0_impl(dbl *ret, str *string1, st
 /* ============ Q-GRAM SELF JOIN ============== */
 
 str
-CMDqgramselfjoin(BAT **res, BAT *qgram, BAT *id, BAT *pos, BAT *len, flt *c, 
int *k)
+CMDqgramselfjoin(BAT **res, BAT **res2, BAT *qgram, BAT *id, BAT *pos, BAT 
*len, flt *c, int *k)
 {
        BUN n = BATcount(qgram);
        BUN i, j;
-       BAT *bn;
+       BAT *bn, *bn2;
 
        oid *qbuf = (oid *) Tloc(qgram, BUNfirst(qgram));
        int *ibuf = (int *) Tloc(id, BUNfirst(id));
@@ -904,12 +904,19 @@ CMDqgramselfjoin(BAT **res, BAT *qgram, 
        ERRORcheck((Tsize(pos) != ATOMsize(pos->ttype)), "CMDqgramselfjoin: pos 
is not a true void bat");
        ERRORcheck((Tsize(len) != ATOMsize(len->ttype)), "CMDqgramselfjoin: len 
is not a true void bat");
 
-       *res = bn = BATnew(TYPE_int, TYPE_int, n);
+       *res = bn = BATnew(TYPE_void, TYPE_int, n);
+       *res2 = bn2 = BATnew(TYPE_void, TYPE_int, n);
+       if (bn == NULL || bn2 == NULL){
+               if (bn) BBPreclaim(bn);
+               if (bn2) BBPreclaim(bn2);
+               throw(MAL, "txtsim.qgramselfjoin", MAL_MALLOC_FAIL);
+       }
 
        for (i = 0; i < n - 1; i++) {
                for (j = i + 1; (j < n && qbuf[j] == qbuf[i] && pbuf[j] <= 
(pbuf[i] + (*k + *c * MYMIN(lbuf[i], lbuf[j])))); j++) {
                        if (ibuf[i] != ibuf[j] && abs(lbuf[i] - lbuf[j]) <= (*k 
+ *c * MYMIN(lbuf[i], lbuf[j]))) {
-                               bunfastins(bn, ibuf + i, ibuf + j);
+                               BUNappend(bn, ibuf + i, FALSE);
+                               BUNappend(bn2, ibuf + j, FALSE);
                        }
                }
        }
@@ -918,10 +925,11 @@ CMDqgramselfjoin(BAT **res, BAT *qgram, 
        bn->hrevsorted = bn->trevsorted = 0;
        bn->H->nonil = bn->T->nonil = 0;
 
+       bn2->hsorted = bn2->tsorted = 0;
+       bn2->hrevsorted = bn2->trevsorted = 0;
+       bn2->H->nonil = bn2->T->nonil = 0;
+
        return MAL_SUCCEED;
-      bunins_failed:
-       BBPreclaim(bn);
-       throw(MAL, "txtsim.qgramselfjoin", MAL_MALLOC_FAIL);
 }
 
 /* copy up to utf8len UTF-8 encoded characters from src to buf
diff --git a/monetdb5/modules/mal/txtsim.h b/monetdb5/modules/mal/txtsim.h
--- a/monetdb5/modules/mal/txtsim.h
+++ b/monetdb5/modules/mal/txtsim.h
@@ -51,7 +51,7 @@ txtsim_export str fstrcmp0_impl(dbl *ret
 txtsim_export str soundex_impl(str *res, str *Name);
 txtsim_export str stringdiff_impl(int *res, str *s1, str*s2);
 txtsim_export str CMDqgramnormalize(str *res, str *input);
-txtsim_export str CMDqgramselfjoin(BAT **res, BAT *qgram, BAT *id, BAT *pos, 
BAT *len, flt *c, int *k);
+txtsim_export str CMDqgramselfjoin(BAT **res, BAT **res2, BAT *qgram, BAT *id, 
BAT *pos, BAT *len, flt *c, int *k);
 txtsim_export str CMDstr2qgrams(int *ret, str *val);
 
 #endif /*_TXTSIM_H*/
diff --git a/monetdb5/modules/mal/txtsim.mal b/monetdb5/modules/mal/txtsim.mal
--- a/monetdb5/modules/mal/txtsim.mal
+++ b/monetdb5/modules/mal/txtsim.mal
@@ -53,7 +53,7 @@ command qgramnormalize(input:str): str
 address CMDqgramnormalize
 comment "'Normalizes' strings (eg. toUpper and replaces non-alphanumerics with 
one space";
 
-command qgramselfjoin(qgram:bat[:oid, :oid], id:bat[:oid, :oid], pos:bat[:oid, 
:int], len:bat[:oid, :int], c:flt, k:int) :bat[:int, :int]
+command qgramselfjoin(qgram:bat[:oid, :oid], id:bat[:oid, :oid], pos:bat[:oid, 
:int], len:bat[:oid, :int], c:flt, k:int) (:bat[:oid,:int],:bat[:oid, :int])
 address CMDqgramselfjoin
 comment "QGram self-join on ordered(!) qgram tables and sub-ordered q-gram 
positions";
 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to