Changeset: 25367d1b0e7f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/25367d1b0e7f
Modified Files:
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_private.h
Branch: default
Log Message:

Specify materialized capacity in argument.
This way, batCapacity is only changed after the capacity was created.


diffs (157 lines):

diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -169,9 +169,8 @@ VIEWcreate(oid seq, BAT *b)
  */
 
 gdk_return
-BATmaterialize(BAT *b)
+BATmaterialize(BAT *b, BUN cap)
 {
-       BUN cnt;
        Heap *tail;
        Heap *h, *vh = NULL;
        BUN p, q;
@@ -179,17 +178,19 @@ BATmaterialize(BAT *b)
 
        BATcheck(b, GDK_FAIL);
        assert(!isVIEW(b));
+       if (cap == BUN_NONE)
+               cap = BATcapacity(b);
+       assert(cap >= BATcapacity(b));
        if (b->ttype != TYPE_void) {
-               /* no voids */
-               return GDK_SUCCEED;
+               /* no voids; just call BATextend to make sure of capacity */
+               return BATextend(b, cap);
        }
 
-       cnt = BATcapacity(b);
        if ((tail = GDKmalloc(sizeof(Heap))) == NULL)
                return GDK_FAIL;
        p = 0;
        q = BATcount(b);
-       assert(cnt >= q - p);
+       assert(cap >= q - p);
        TRC_DEBUG(ALGO, "BATmaterialize(" ALGOBATFMT ")\n", ALGOBATPAR(b));
 
        /* cleanup possible ACC's */
@@ -203,7 +204,7 @@ BATmaterialize(BAT *b)
                .dirty = true,
        };
        settailname(tail, BBP_physical(b->batCacheid), TYPE_oid, 0);
-       if (HEAPalloc(tail, cnt, sizeof(oid), 0) != GDK_SUCCEED) {
+       if (HEAPalloc(tail, cap, sizeof(oid), 0) != GDK_SUCCEED) {
                GDKfree(tail);
                return GDK_FAIL;
        }
@@ -266,6 +267,7 @@ BATmaterialize(BAT *b)
        BATsetdims(b, 0);
        b->batDirtydesc = true;
        BATsetcount(b, b->batCount);
+       BATsetcapacity(b, cap);
        MT_lock_unset(&b->theaplock);
        HEAPdecref(h, false);
        if (vh)
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1046,8 +1046,7 @@ BUNappendmulti(BAT *b, const void *value
                        return GDK_SUCCEED;
                } else {
                        /* we need to materialize b; allocate enough capacity */
-                       b->batCapacity = BATcount(b) + count;
-                       if (BATmaterialize(b) != GDK_SUCCEED)
+                       if (BATmaterialize(b, BATcount(b) + count) != 
GDK_SUCCEED)
                                return GDK_FAIL;
                }
        }
@@ -1336,7 +1335,7 @@ BUNdelete(BAT *b, oid o)
                /* replace to-be-delete BUN with last BUN; materialize
                 * void column before doing so */
                if (b->ttype == TYPE_void &&
-                   BATmaterialize(b) != GDK_SUCCEED)
+                   BATmaterialize(b, BUN_NONE) != GDK_SUCCEED)
                        return GDK_FAIL;
                if (ATOMstorage(b->ttype) == TYPE_msk) {
                        msk mval = mskGetVal(b, BATcount(b) - 1);
@@ -1685,7 +1684,7 @@ BUNreplacemulti(BAT *b, const oid *posit
 {
        BATcheck(b, GDK_FAIL);
 
-       if (b->ttype == TYPE_void && BATmaterialize(b) != GDK_SUCCEED)
+       if (b->ttype == TYPE_void && BATmaterialize(b, BUN_NONE) != GDK_SUCCEED)
                return GDK_FAIL;
 
        return BUNinplacemulti(b, positions, values, count, force, false);
@@ -1698,7 +1697,7 @@ BUNreplacemultiincr(BAT *b, oid position
 {
        BATcheck(b, GDK_FAIL);
 
-       if (b->ttype == TYPE_void && BATmaterialize(b) != GDK_SUCCEED)
+       if (b->ttype == TYPE_void && BATmaterialize(b, BUN_NONE) != GDK_SUCCEED)
                return GDK_FAIL;
 
        return BUNinplacemulti(b, &position, values, count, force, true);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -756,9 +756,8 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool 
                        goto doreturn;
                }
                /* we need to materialize b; allocate enough capacity */
-               b->batCapacity = BATcount(b) + ci.ncand;
                MT_lock_unset(&b->theaplock);
-               if (BATmaterialize(b) != GDK_SUCCEED) {
+               if (BATmaterialize(b, BATcount(b) + ci.ncand) != GDK_SUCCEED) {
                        bat_iterator_end(&ni);
                        return GDK_FAIL;
                }
@@ -948,7 +947,7 @@ BATdel(BAT *b, BAT *d)
                                p++;
                        }
                }
-               if (BATtdense(b) && BATmaterialize(b) != GDK_SUCCEED)
+               if (BATtdense(b) && BATmaterialize(b, BUN_NONE) != GDK_SUCCEED)
                        return GDK_FAIL;
                MT_lock_set(&b->theaplock);
                if (o + c < b->hseqbase + BATcount(b)) {
@@ -991,7 +990,7 @@ BATdel(BAT *b, BAT *d)
                        GDKerror("cannot delete committed values\n");
                        return GDK_FAIL;
                }
-               if (BATtdense(b) && BATmaterialize(b) != GDK_SUCCEED) {
+               if (BATtdense(b) && BATmaterialize(b, BUN_NONE) != GDK_SUCCEED) 
{
                        bat_iterator_end(&di);
                        return GDK_FAIL;
                }
@@ -2512,7 +2511,7 @@ BATsort(BAT **sorted, BAT **order, BAT *
                assert(g->ttype == TYPE_oid);
                grps = (oid *) Tloc(g, 0);
                prev = grps[0];
-               if (BATmaterialize(bn) != GDK_SUCCEED)
+               if (BATmaterialize(bn, BUN_NONE) != GDK_SUCCEED)
                        goto error;
                for (r = 0, p = 1, q = BATcount(g); p < q; p++) {
                        if (grps[p] != prev) {
@@ -2559,7 +2558,7 @@ BATsort(BAT **sorted, BAT **order, BAT *
                }
                if ((reverse != nilslast ||
                     (reverse ? !bn->trevsorted : !bn->tsorted)) &&
-                   (BATmaterialize(bn) != GDK_SUCCEED ||
+                   (BATmaterialize(bn, BUN_NONE) != GDK_SUCCEED ||
                     do_sort(Tloc(bn, 0),
                             ords,
                             bn->tvheap ? bn->tvheap->base : NULL,
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -78,7 +78,7 @@ bool BATiscand(BAT *b)
        __attribute__((__visibility__("hidden")));
 BAT *BATload_intern(bat bid, bool lock)
        __attribute__((__visibility__("hidden")));
-gdk_return BATmaterialize(BAT *b)
+gdk_return BATmaterialize(BAT *b, BUN cap)
        __attribute__((__warn_unused_result__))
        __attribute__((__visibility__("hidden")));
 void BATrmprop(BAT *b, enum prop_t idx)
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to