Changeset: 058481076ace for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=058481076ace
Modified Files:
        gdk/ChangeLog
        gdk/gdk.h
        gdk/gdk_aggr.c
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_imprints.c
        gdk/gdk_join.c
        gdk/gdk_select.c
        gdk/gdk_storage.c
        monetdb5/mal/mal_debugger.c
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

BATmirror is gone.
This involved changing a few places, making sure various functions are
always called with a positive BAT id, so appropriately negating the
parentid of the tail (fixed-size) heap.
This also means that we could simplify even more code (head column is
always VOID, so is never a view and does not have indexes).


diffs (truncated from 804 to 300 lines):

diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -1,6 +1,11 @@
 # ChangeLog file for MonetDB
 # This file is updated with Maddlog
 
+* Tue Jun 28 2016 Sjoerd Mullender <[email protected]>
+- The function BATmirror is gone.  The HEAD column is always VOID (with
+  a non-nil seqbase) and the TAIL column carries the data.  All functions
+  that deal with data work on the TAIL column.
+
 * Mon Jun 27 2016 Sjoerd Mullender <[email protected]>
 - BATkey now works on the TAIL column instead of the HEAD column.
 - Replaced BATseqbase with BAThseqbase and BATtseqbase, the former for
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -816,12 +816,6 @@ gdk_export int VALisnil(const ValRecord 
  * more complex, but GDK programmers should refrain of making use of
  * that.
  *
- * The reason for this complex structure is to allow for a BAT to
- * exist in two incarnations at the time: the @emph{normal view} and
- * the @emph{reversed view}. Each bat @emph{b} has a
- * BATmirror(@emph{b}) which has the negative @strong{cacheid} of b in
- * the BBP.
- *
  * Since we don't want to pay cost to keep both views in line with
  * each other under BAT updates, we work with shared pieces of memory
  * between the two views. An update to one will thus automatically
@@ -1106,9 +1100,6 @@ gdk_export bte ATOMelmshift(int sz);
  * The routine BUNfnd provides fast access to a single BUN providing a
  * value for the tail of the binary association.
  *
- * To select on a tail, one should use the reverse view obtained by
- * BATmirror.
- *
  * The routine BUNtail returns a pointer to the second value in an
  * association.  To guard against side effects on the BAT, one should
  * normally copy this value into a scratch variable for further
@@ -1515,20 +1506,12 @@ gdk_export int BATgetaccess(BAT *b);
  * @tab BATclear (BAT *b, int force)
  * @item BAT *
  * @tab COLcopy (BAT *b, int tt, int writeable, int role)
- * @item BAT *
- * @tab BATmirror (BAT *b)
- * @item BAT *
  * @end multitable
  *
  * The routine BATclear removes the binary associations, leading to an
  * empty, but (re-)initialized BAT. Its properties are retained.  A
  * temporary copy is obtained with Colcopy. The new BAT has an unique
  * name.
- *
- * The routine BATmirror returns the mirror image BAT (where tail is
- * head and head is tail) of that same BAT. This does not involve a
- * state change in the BAT (as previously): both views on the BAT
- * exist at the same time.
  */
 gdk_export gdk_return BATclear(BAT *b, int force);
 gdk_export BAT *COLcopy(BAT *b, int tt, int writeable, int role);
@@ -2600,14 +2583,6 @@ Tpos(BATiter *bi, BUN p)
        return (char*)&bi->tvid;
 }
 
-static inline BAT *
-BATmirror(register BAT *b)
-{
-       if (b == NULL)
-               return NULL;
-       return BBP_cache(-b->batCacheid);
-}
-
 #endif
 
 /*
@@ -2789,8 +2764,8 @@ gdk_export void ALIGNsetT(BAT *b1, BAT *
 #define ALIGNinp(x,y,f,e)      do {if (!(f)) 
VIEWchk(x,y,BAT_READ|BAT_APPEND,e);(x)->talign=0; } while (0)
 #define ALIGNapp(x,y,f,e)      do {if (!(f)) 
VIEWchk(x,y,BAT_READ,e);(x)->talign=0; } while (0)
 
-#define BAThrestricted(b) (VIEWhparent(b) ? 
BBP_cache(VIEWhparent(b))->batRestricted : (b)->batRestricted)
-#define BATtrestricted(b) (VIEWtparent(b) ? 
BBP_cache(VIEWtparent(b))->batRestricted : (b)->batRestricted)
+#define BAThrestricted(b) ((b)->batRestricted)
+#define BATtrestricted(b) (VIEWtparent(b) ? 
BBP_cache(-VIEWtparent(b))->batRestricted : (b)->batRestricted)
 
 /* The batRestricted field indicates whether a BAT is readonly.
  * we have modes: BAT_WRITE  = all permitted
@@ -2811,14 +2786,11 @@ gdk_export void ALIGNsetT(BAT *b1, BAT *
  * correct for the reversed view.
  */
 #define isVIEW(x)                                                      \
-       ((x)->H->heap.parentid ||                                       \
-        (x)->T->heap.parentid ||                                       \
-        ((x)->H->vheap && (x)->H->vheap->parentid != abs((x)->batCacheid)) || \
-        ((x)->T->vheap && (x)->T->vheap->parentid != abs((x)->batCacheid)))
+       (assert((x)->batCacheid > 0 && (x)->htype == TYPE_void),        \
+        ((x)->T->heap.parentid ||                                      \
+         ((x)->T->vheap && (x)->T->vheap->parentid != (x)->batCacheid)))
 
 #define isVIEWCOMBINE(x) ((x)->H == (x)->T)
-#define VIEWhparent(x) ((x)->H->heap.parentid)
-#define VIEWvhparent(x)        
(((x)->H->vheap==NULL||(x)->H->vheap->parentid==abs((x)->batCacheid))?0:(x)->H->vheap->parentid)
 #define VIEWtparent(x) ((x)->T->heap.parentid)
 #define VIEWvtparent(x)        
(((x)->T->vheap==NULL||(x)->T->vheap->parentid==abs((x)->batCacheid))?0:(x)->T->vheap->parentid)
 
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -2288,7 +2288,7 @@ BATminmax(BAT *b, void *aggr,
        if (!BAThdense(b))
                return NULL;
        if ((VIEWtparent(b) == 0 ||
-            BATcount(b) == BATcount(BBPdescriptor(VIEWtparent(b)))) &&
+            BATcount(b) == BATcount(BBPdescriptor(-VIEWtparent(b)))) &&
            BATcheckimprints(b)) {
                Imprints *imprints = VIEWtparent(b) ? 
BBPdescriptor(-VIEWtparent(b))->T->imprints : b->T->imprints;
                pos = oid_nil;
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -224,7 +224,7 @@ VIEWcreate_(oid seq, BAT *b, int slice_v
        }
 
        if (tp)
-               BBPshare(tp);
+               BBPshare(-tp);
        if (bn->T->vheap) {
                assert(b->T->vheap);
                assert(bn->T->vheap->parentid > 0);
@@ -344,11 +344,12 @@ VIEWunlink(BAT *b)
                BAT *tpb = NULL;
                BAT *vtpb = NULL;
 
+               assert(b->batCacheid > 0);
                assert(b->htype == TYPE_void);
                if (tp)
-                       tpb = BBP_cache(tp);
+                       tpb = BBP_cache(-tp);
                if (tp && !vtp)
-                       vtp = tp;
+                       vtp = -tp;
                if (vtp)
                        vtpb = BBP_cache(vtp);
 
@@ -357,20 +358,23 @@ VIEWunlink(BAT *b)
 
                /* unlink heaps shared with parent */
                assert(b->H->vheap == NULL);
+               assert(b->H->props == NULL);
+               assert(b->H->hash == NULL);
+               assert(b->H->imprints == NULL);
                assert(b->T->vheap == NULL || b->T->vheap->parentid > 0);
-               if (b->T->vheap && b->T->vheap->parentid != abs(b->batCacheid))
+               if (b->T->vheap && b->T->vheap->parentid != b->batCacheid)
                        b->T->vheap = NULL;
 
                /* unlink properties shared with parent */
-               if (tpb && b->T->props && b->T->props == tpb->H->props)
+               if (tpb && b->T->props && b->T->props == tpb->T->props)
                        b->T->props = NULL;
 
                /* unlink hash accelerators shared with parent */
-               if (tpb && b->T->hash && b->T->hash == tpb->H->hash)
+               if (tpb && b->T->hash && b->T->hash == tpb->T->hash)
                        b->T->hash = NULL;
 
                /* unlink imprints shared with parent */
-               if (tpb && b->T->imprints && b->T->imprints == tpb->H->imprints)
+               if (tpb && b->T->imprints && b->T->imprints == tpb->T->imprints)
                        b->T->imprints = NULL;
        }
 }
@@ -390,7 +394,7 @@ VIEWreset(BAT *b)
                return GDK_FAIL;
        assert(b->htype == TYPE_void);
        assert(b->batCacheid > 0);
-       tp = VIEWtparent(b);
+       tp = -VIEWtparent(b);
        tvp = VIEWvtparent(b);
        if (tp || tvp) {
                BAT *m;
@@ -403,7 +407,6 @@ VIEWreset(BAT *b)
                memset(&head, 0, sizeof(Heap));
                memset(&tail, 0, sizeof(Heap));
 
-               m = BATmirror(b);
                bs = BBP_desc(b->batCacheid);
                cnt = BATcount(b) + 1;
                nme = BBP_physical(b->batCacheid);
@@ -451,6 +454,7 @@ VIEWreset(BAT *b)
                }
 
                /* make sure everything points there */
+               m = BBP_cache(-b->batCacheid);
                m->S = b->S = &bs->S;
                m->T = b->H = &bs->H;
                m->H = b->T = &bs->T;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -463,7 +463,7 @@ BATclear(BAT *b, int force)
                            ATOMheap(b->ttype, &th, 0) != GDK_SUCCEED)
                                return GDK_FAIL;
                }
-               assert(b->T->vheap == NULL || b->T->vheap->parentid == 
abs(b->batCacheid));
+               assert(b->T->vheap == NULL || b->T->vheap->parentid == 
b->batCacheid);
                if (b->T->vheap && b->T->vheap->free > 0) {
                        th.parentid = b->T->vheap->parentid;
                        HEAPfree(b->T->vheap, 0);
@@ -507,44 +507,32 @@ BATfree(BAT *b)
                return;
 
        /* deallocate all memory for a bat */
-       if (b->batCacheid < 0)
-               b = BBP_cache(-(b->batCacheid));
+       assert(b->batCacheid > 0);
        if (b->hident && !default_ident(b->hident))
                GDKfree(b->hident);
        b->hident = BATstring_h;
        if (b->tident && !default_ident(b->tident))
                GDKfree(b->tident);
        b->tident = BATstring_t;
-       if (b->H->props)
-               PROPdestroy(b->H->props);
-       b->H->props = NULL;
+       assert(b->H->props == NULL);
        if (b->T->props)
                PROPdestroy(b->T->props);
        b->T->props = NULL;
        HASHfree(b);
        IMPSfree(b);
        OIDXfree(b);
-       if (b->htype)
-               HEAPfree(&b->H->heap, 0);
-       else
-               assert(!b->H->heap.base);
+       assert(b->H->heap.base == NULL);
+       assert(b->H->vheap == NULL);
        if (b->ttype)
                HEAPfree(&b->T->heap, 0);
        else
                assert(!b->T->heap.base);
-       if (b->H->vheap) {
-               assert(b->H->vheap->parentid == b->batCacheid);
-               HEAPfree(b->H->vheap, 0);
-       }
        if (b->T->vheap) {
                assert(b->T->vheap->parentid == b->batCacheid);
                HEAPfree(b->T->vheap, 0);
        }
 
-       b = BBP_cache(-b->batCacheid);
-       if (b) {
-               BBP_cache(b->batCacheid) = NULL;
-       }
+       BBP_cache(-b->batCacheid) = NULL;
 }
 
 /* free a cached BAT descriptor */
@@ -702,13 +690,12 @@ COLcopy(BAT *b, int tt, int writable, in
                        bunstocopy = cnt;
                } else if (isVIEW(b)) {
                        /* extra checks needed for views */
-                       bat hp = VIEWhparent(b), tp = VIEWtparent(b);
+                       bat tp = VIEWtparent(b);
 
                        if (isVIEWCOMBINE(b) || /* oops, mirror view! */
                            /* reduced slice view: do not copy too
                             * much garbage */
-                           (hp != 0 && BATcapacity(BBP_cache(hp)) > cnt + cnt) 
||
-                           (tp != 0 && BATcapacity(BBP_cache(tp)) > cnt + cnt))
+                           (tp != 0 && BATcapacity(BBP_cache(-tp)) > cnt + 
cnt))
                                bunstocopy = cnt;
                }
 
@@ -2313,9 +2300,7 @@ BATassertProps(BAT *b)
        /* general BAT sanity */
        assert(b != NULL);
        assert(b->batCacheid > 0);
-       assert(VIEWhparent(b) == 0);
-       assert(VIEWvhparent(b) == 0);
-       bm = BATmirror(b);
+       bm = BBP_cache(-b->batCacheid);
        assert(bm != NULL);
        assert(b->H == bm->T);
        assert(b->T == bm->H);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -21,12 +21,13 @@
 gdk_return
 unshare_string_heap(BAT *b)
 {
+       assert(b->batCacheid > 0);
        if (b->ttype == TYPE_str &&
-           b->T->vheap->parentid != abs(b->batCacheid)) {
+           b->T->vheap->parentid != b->batCacheid) {
                Heap *h = GDKzalloc(sizeof(Heap));
                if (h == NULL)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to