Changeset: 55a5017d91c9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55a5017d91c9
Modified Files:
        gdk/gdk_batop.c
Branch: Feb2013
Log Message:

BATmergecand(): we can simply return one input as-is, if it fully covers the 
other one

exploiting the fact that inputs are sorted and key (unique)


diffs (35 lines):

diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -2218,6 +2218,9 @@ BATmergecand(BAT *a, BAT *b)
        BAT *bn;
        const oid *ap, *bp, *ape, *bpe;
        oid *p, i;
+       oid af, al, bf, bl;
+       BATiter ai, bi;
+       bit ad, bd;
 
        BATcheck(a, "BATmergecand");
        BATcheck(b, "BATmergecand");
@@ -2239,6 +2242,21 @@ BATmergecand(BAT *a, BAT *b)
        if ( BATcount(b) == 0){
                return BATcopy(a, a->htype, a->ttype, 0);
        }
+       /* we can return a if a fully covers b (and v.v) */
+       ai = bat_iterator(a);
+       bi = bat_iterator(b);
+       af = *(oid*) BUNtail(ai, BUNfirst(a));
+       bf = *(oid*) BUNtail(bi, BUNfirst(b));
+       al = *(oid*) BUNtail(ai, BUNlast(a) - 1);
+       bl = *(oid*) BUNtail(bi, BUNlast(b) - 1);
+       ad = (af + BATcount(a) - 1 == al); /* i.e., dense */
+       bd = (bf + BATcount(b) - 1 == bl); /* i.e., dense */
+       if (ad && af <= bf && al >= bl) {
+               return BATcopy(a, a->htype, a->ttype,0);
+       }
+       if (bd && bf <= af && bl >= al) {
+               return BATcopy(b, b->htype, b->ttype,0);
+       }
 
        bn = BATnew(TYPE_void, TYPE_oid, BATcount(a) + BATcount(b));
        if (bn == NULL)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to