Changeset: 3822af945f28 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3822af945f28
Modified Files:
        gdk/gdk_cand.c
        gdk/gdk_private.h
        gdk/gdk_select.c
Branch: viewless
Log Message:

Do not use BATslice to slice a candidate list, but CANDlist.

A BATslice might lead to a view, which we want to get rid of.
Instead use a CANDslice.


diffs (240 lines):

diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c
--- a/gdk/gdk_cand.c
+++ b/gdk/gdk_cand.c
@@ -20,14 +20,14 @@
 BAT *
 CANDnewdense(oid first, oid last)
 {
-       BAT *bn;
-       if ((bn = COLnew(0, TYPE_void, 0, TRANSIENT)) == NULL)
+       BAT *s;
+       if ((s = COLnew(0, TYPE_void, 0, TRANSIENT)) == NULL)
                return NULL;
        if (last < first)
                first = last = 0; /* empty range */
-       BATsetcount(bn, last - first + 1);
-       BATtseqbase(bn, first);
-       return bn;
+       BATsetcount(s, last - first + 1);
+       BATtseqbase(s, first);
+       return s;
 }
 
 /* binary search in a candidate list, return 1 if found, 0 if not */
@@ -87,3 +87,76 @@ CANDvirtualize(BAT *bn)
        return bn;
 }
 
+BAT *
+CANDdoublerange(oid l1, oid h1, oid l2, oid h2)
+{
+       BAT *bn;
+       oid *restrict p;
+
+       assert(l1 <= h1);
+       assert(l2 <= h2);
+       assert(h1 <= l2);
+       if (l1 == h1 || l2 == h2) {
+               bn = COLnew(0, TYPE_void, h1 - l1 + h2 - l2, TRANSIENT);
+               if (bn == NULL)
+                       return NULL;
+               BATsetcount(bn, h1 - l1 + h2 - l2);
+               BATtseqbase(bn, l1 == h1 ? l2 : l1);
+               return bn;
+       }
+       bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT);
+       if (bn == NULL)
+               return NULL;
+       BATsetcount(bn, h1 - l1 + h2 - l2);
+       p = (oid *) Tloc(bn, 0);
+       while (l1 < h1)
+               *p++ = l1++;
+       while (l2 < h2)
+               *p++ = l2++;
+       bn->tkey = 1;
+       bn->tsorted = 1;
+       bn->trevsorted = BATcount(bn) <= 1;
+       bn->tnil = 0;
+       bn->tnonil = 1;
+       return bn;
+}
+
+BAT *
+CANDdoubleslice(BAT *s, BUN l1, BUN h1, BUN l2, BUN h2)
+{
+       BAT *bn;
+       oid *restrict p;
+       const oid *restrict o;
+
+       assert(l1 <= h1);
+       assert(l2 <= h2);
+       assert(h1 <= l2);
+       assert(s->tsorted);
+       assert(s->tkey);
+       if (s->ttype == TYPE_void)
+               return CANDdoublerange(l1 + s->tseqbase, h1 + s->tseqbase,
+                                  l2 + s->tseqbase, h2 + s->tseqbase);
+       bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT);
+       if (bn == NULL)
+               return NULL;
+       BATsetcount(bn, h1 - l1 + h2 - l2);
+       p = (oid *) Tloc(bn, 0);
+       o = (const oid *) Tloc(s, l1);
+       while (l1++ < h1)
+               *p++ = *o++;
+       o = (const oid *) Tloc(s, l2);
+       while (l2++ < h2)
+               *p++ = *o++;
+       bn->tkey = 1;
+       bn->tsorted = 1;
+       bn->trevsorted = BATcount(bn) <= 1;
+       bn->tnil = 0;
+       bn->tnonil = 1;
+       return CANDvirtualize(bn);
+}
+
+BAT *
+CANDslice(BAT *s, BUN l, BUN h)
+{
+       return CANDdoubleslice(s, 0,0, l, h);
+}
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -226,6 +226,13 @@ void BBPdump(void);                /* never called: fo
        __attribute__((__visibility__("hidden")));
 __hidden BAT *CANDnewdense(oid first, oid last)
        __attribute__((__visibility__("hidden")));
+__hidden BAT *CANDslice(BAT *s, BUN l, BUN h)
+       __attribute__((__visibility__("hidden")));
+__hidden BAT *CANDdoubleslice(BAT *s, BUN l1, BUN h1, BUN l2, BUN h2)
+       __attribute__((__visibility__("hidden")));
+__hidden BAT *CANDdoublerange(oid l1, oid h1, oid l2, oid h2)
+       __attribute__((__visibility__("hidden")));
+
 
 
 __hidden void gdk_bbp_reset(void)
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -46,74 +46,6 @@ newempty(void)
        return bn;
 }
 
-static BAT *
-doublerange(oid l1, oid h1, oid l2, oid h2)
-{
-       BAT *bn;
-       oid *restrict p;
-
-       assert(l1 <= h1);
-       assert(l2 <= h2);
-       assert(h1 <= l2);
-       if (l1 == h1 || l2 == h2) {
-               bn = COLnew(0, TYPE_void, h1 - l1 + h2 - l2, TRANSIENT);
-               if (bn == NULL)
-                       return NULL;
-               BATsetcount(bn, h1 - l1 + h2 - l2);
-               BATtseqbase(bn, l1 == h1 ? l2 : l1);
-               return bn;
-       }
-       bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT);
-       if (bn == NULL)
-               return NULL;
-       BATsetcount(bn, h1 - l1 + h2 - l2);
-       p = (oid *) Tloc(bn, 0);
-       while (l1 < h1)
-               *p++ = l1++;
-       while (l2 < h2)
-               *p++ = l2++;
-       bn->tkey = 1;
-       bn->tsorted = 1;
-       bn->trevsorted = BATcount(bn) <= 1;
-       bn->tnil = 0;
-       bn->tnonil = 1;
-       return bn;
-}
-
-static BAT *
-doubleslice(BAT *b, BUN l1, BUN h1, BUN l2, BUN h2)
-{
-       BAT *bn;
-       oid *restrict p;
-       const oid *restrict o;
-
-       assert(l1 <= h1);
-       assert(l2 <= h2);
-       assert(h1 <= l2);
-       assert(b->tsorted);
-       assert(b->tkey);
-       if (b->ttype == TYPE_void)
-               return doublerange(l1 + b->tseqbase, h1 + b->tseqbase,
-                                  l2 + b->tseqbase, h2 + b->tseqbase);
-       bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT);
-       if (bn == NULL)
-               return NULL;
-       BATsetcount(bn, h1 - l1 + h2 - l2);
-       p = (oid *) Tloc(bn, 0);
-       o = (const oid *) Tloc(b, l1);
-       while (l1++ < h1)
-               *p++ = *o++;
-       o = (const oid *) Tloc(b, l2);
-       while (l2++ < h2)
-               *p++ = *o++;
-       bn->tkey = 1;
-       bn->tsorted = 1;
-       bn->trevsorted = BATcount(bn) <= 1;
-       bn->tnil = 0;
-       bn->tnonil = 1;
-       return CANDvirtualize(bn);
-}
-
 #define HASHloop_bound(bi, h, hb, v, lo, hi)           \
        for (hb = HASHget(h, HASHprobe((h), v));        \
             hb != HASHnil(h);                          \
@@ -1359,7 +1291,7 @@ BATselect(BAT *b, BAT *s, const void *tl
                        oid o = b->hseqbase + BATcount(b);
                        BUN q = SORTfndfirst(s, &o);
                        BUN p = SORTfndfirst(s, &b->hseqbase);
-                       return BATslice(s, p, q);
+                       return CANDslice(s, p, q);
                } else {
                        return BATdense(0, b->hseqbase, BATcount(b));
                }
@@ -1552,9 +1484,9 @@ BATselect(BAT *b, BAT *s, const void *tl
                                        high = SORTfndfirst(s, &o);
                                        o = b->hseqbase + b->batCount;
                                        last = SORTfndfirst(s, &o);
-                                       bn = doubleslice(s, first, low, high, 
last);
+                                       bn = CANDdoubleslice(s, first, low, 
high, last);
                                } else {
-                                       bn = doublerange(first + b->hseqbase,
+                                       bn = CANDdoublerange(first + 
b->hseqbase,
                                                         low + b->hseqbase,
                                                         high + b->hseqbase,
                                                         BATcount(b) + 
b->hseqbase);
@@ -1576,9 +1508,9 @@ BATselect(BAT *b, BAT *s, const void *tl
                                        high = SORTfndfirst(s, &o);
                                        o = b->hseqbase;
                                        first = SORTfndfirst(s, &o);
-                                       bn = doubleslice(s, first, low, high, 
last);
+                                       bn = CANDdoubleslice(s, first, low, 
high, last);
                                } else {
-                                       bn = doublerange(0 + b->hseqbase,
+                                       bn = CANDdoublerange(0 + b->hseqbase,
                                                         low + b->hseqbase,
                                                         high + b->hseqbase,
                                                         last + b->hseqbase);
@@ -1628,9 +1560,9 @@ BATselect(BAT *b, BAT *s, const void *tl
                                        low = SORTfndfirst(s, &o);
                                        o = (oid) high + b->hseqbase;
                                        high = SORTfndfirst(s, &o);
-                                       bn = doubleslice(s, 0, 0, low, high);
+                                       bn = CANDdoubleslice(s, 0, 0, low, 
high);
                                } else {
-                                       bn = doublerange(0, 0,
+                                       bn = CANDdoublerange(0, 0,
                                                         low + b->hseqbase,
                                                         high + b->hseqbase);
                                }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to