Changeset: 3a598360f206 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3a598360f206
Branch: unlock
Log Message:

Merge unlock-cands branch into unlock.


diffs (truncated from 1542 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -9512,7 +9512,6 @@ stdout of test 'MAL-signatures` in direc
 [ "status",    "vm_maxsize",   "command status.vm_maxsize(X_1:lng):void ",     
"SYSsetvm_maxsize;",    ""      ]
 [ "str",       "ascii",        "command str.ascii(X_1:str):int ",      
"STRascii;",    ""      ]
 [ "str",       "endsWith",     "command str.endsWith(X_1:str, X_2:str):bit ",  
"STRSuffix;",   ""      ]
-[ "str",       "epilogue",     "command str.epilogue():void ", "STRepilogue;", 
""      ]
 [ "str",       "insert",       "command str.insert(X_1:str, X_2:int, X_3:int, 
X_4:str):str ",  "STRinsert;",   ""      ]
 [ "str",       "length",       "command str.length(X_1:str):int ",     
"STRLength;",   ""      ]
 [ "str",       "like", "command str.like(X_1:str, X_2:str):bit ",      
"STRlikewrap2;",        ""      ]
@@ -9525,7 +9524,7 @@ stdout of test 'MAL-signatures` in direc
 [ "str",       "ltrim",        "command str.ltrim(X_1:str):str ",      
"STRLtrim;",    ""      ]
 [ "str",       "nbytes",       "command str.nbytes(X_1:str):int ",     
"STRBytes;",    ""      ]
 [ "str",       "prefix",       "command str.prefix(X_1:str, X_2:int):str ",    
"STRprefix;",   ""      ]
-[ "str",       "prelude",      "command str.prelude():void ",  "STRprelude;",  
""      ]
+[ "str",       "prelude",      "command str.prelude():void ",  "strPrelude;",  
""      ]
 [ "str",       "r_search",     "command str.r_search(X_1:str, X_2:str):int ",  
"STRReverseStrSearch;", ""      ]
 [ "str",       "repeat",       "command str.repeat(X_1:str, X_2:int):str ",    
"STRrepeat;",   ""      ]
 [ "str",       "replace",      "command str.replace(X_1:str, X_2:str, X_3:str, 
X_4:str):str ", "PCREreplace_wrap;",    ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -12880,7 +12880,6 @@ stdout of test 'MAL-signatures` in direc
 [ "status",    "vm_maxsize",   "command status.vm_maxsize(X_1:lng):void ",     
"SYSsetvm_maxsize;",    ""      ]
 [ "str",       "ascii",        "command str.ascii(X_1:str):int ",      
"STRascii;",    ""      ]
 [ "str",       "endsWith",     "command str.endsWith(X_1:str, X_2:str):bit ",  
"STRSuffix;",   ""      ]
-[ "str",       "epilogue",     "command str.epilogue():void ", "STRepilogue;", 
""      ]
 [ "str",       "insert",       "command str.insert(X_1:str, X_2:int, X_3:int, 
X_4:str):str ",  "STRinsert;",   ""      ]
 [ "str",       "length",       "command str.length(X_1:str):int ",     
"STRLength;",   ""      ]
 [ "str",       "like", "command str.like(X_1:str, X_2:str):bit ",      
"STRlikewrap2;",        ""      ]
@@ -12893,7 +12892,7 @@ stdout of test 'MAL-signatures` in direc
 [ "str",       "ltrim",        "command str.ltrim(X_1:str):str ",      
"STRLtrim;",    ""      ]
 [ "str",       "nbytes",       "command str.nbytes(X_1:str):int ",     
"STRBytes;",    ""      ]
 [ "str",       "prefix",       "command str.prefix(X_1:str, X_2:int):str ",    
"STRprefix;",   ""      ]
-[ "str",       "prelude",      "command str.prelude():void ",  "STRprelude;",  
""      ]
+[ "str",       "prelude",      "command str.prelude():void ",  "strPrelude;",  
""      ]
 [ "str",       "r_search",     "command str.r_search(X_1:str, X_2:str):int ",  
"STRReverseStrSearch;", ""      ]
 [ "str",       "repeat",       "command str.repeat(X_1:str, X_2:int):str ",    
"STRrepeat;",   ""      ]
 [ "str",       "replace",      "command str.replace(X_1:str, X_2:str, X_3:str, 
X_4:str):str ", "PCREreplace_wrap;",    ""      ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -161,6 +161,7 @@ gdk_return BATjoin(BAT **r1p, BAT **r2p,
 gdk_return BATkey(BAT *b, bool onoff);
 bool BATkeyed(BAT *b);
 gdk_return BATleftjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, 
bool nil_matches, BUN estimate) __attribute__((__warn_unused_result__));
+gdk_return BATmaskedcands(BAT *dense_cands, BAT *masked, bool selected);
 void *BATmax(BAT *b, void *aggr);
 void *BATmax_skipnil(BAT *b, void *aggr, bit skipnil);
 BAT *BATmergecand(BAT *a, BAT *b);
@@ -168,7 +169,7 @@ void *BATmin(BAT *b, void *aggr);
 void *BATmin_skipnil(BAT *b, void *aggr, bit skipnil);
 gdk_return BATmode(BAT *b, bool transient);
 void BATmsync(BAT *b);
-gdk_return BATnegcands(BAT *cands, BAT *odels);
+gdk_return BATnegcands(BAT *dense_cands, BAT *odels);
 BAT *BATnil_grp(BAT *l, BAT *g, BAT *e, BAT *s);
 bool BATordered(BAT *b);
 bool BATordered_rev(BAT *b);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -991,6 +991,30 @@ typedef var_t stridx_t;
 
 #include "gdk_atoms.h"
 
+
+/* candidates by design are ordered oid lists, besides native oid bats
+ * there are
+ *     void bats for dense oid lists,
+ *     negative oid lists
+ *     masked oid lists
+ */
+
+#define CAND_NEGOID 0
+#define CAND_MSK 1
+
+typedef struct {
+       uint64_t
+               type:1,
+               mask:1;
+} ccand_t;
+
+#define CCAND(b)       ((ccand_t*)b->tvheap->base)
+#define complex_cand(b)        (b->ttype == TYPE_void && b->tvheap != NULL)
+#define negoid_cand(b) (b->ttype == TYPE_void && b->tvheap != NULL && 
CCAND(b)->type == CAND_NEGOID)
+#define mask_cand(b)   (b->ttype == TYPE_void && b->tvheap != NULL && 
CCAND(b)->type == CAND_MSK)
+#define ccand_first(b) (b->tvheap->base+sizeof(ccand_t))
+#define ccand_free(b)  (b->tvheap->free-sizeof(ccand_t))
+
 /* return the oid value at BUN position p from the (v)oid bat b
  * works with any TYPE_void or TYPE_oid bat */
 static inline oid
@@ -1011,16 +1035,17 @@ BUNtoid(BAT *b, BUN p)
        if (b->ttype == TYPE_oid || b->tvheap == NULL) {
                return o;
        }
+       assert(!mask_cand(b));
        /* exceptions only allowed on transient BATs */
        assert(b->batRole == TRANSIENT);
        /* make sure exception area is a reasonable size */
-       assert(b->tvheap->free % SIZEOF_OID == 0);
-       BUN nexc = (BUN) (b->tvheap->free / SIZEOF_OID);
+       assert(ccand_free(b) % SIZEOF_OID == 0);
+       BUN nexc = (BUN) (ccand_free(b) / SIZEOF_OID);
        if (nexc == 0) {
                /* no exceptions (why the vheap?) */
                return o;
        }
-       const oid *exc = (oid *) b->tvheap->base;
+       const oid *exc = (oid *) ccand_first(b);
        if (o < exc[0])
                return o;
        if (o + nexc > exc[nexc - 1])
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -982,7 +982,7 @@ mskCountOnes(BAT *b, struct canditer *ci
        BUN cnt = 0, ncand = ci->ncand;
 
        if (ci->tpe == cand_dense && BATcount(b)) {
-               const uint32_t *restrict src = Tloc(b, (ci->seq - b->hseqbase) 
/ 32);
+               const uint32_t *restrict src = mask_cand(b)?ccand_first(b)+ 
(ci->seq - b->hseqbase) / 32:Tloc(b, (ci->seq - b->hseqbase) / 32);
                int bits = (ci->seq - b->hseqbase) % 32;
                if (bits + ncand <= 32) {
                        if (ncand == 32)
@@ -1028,7 +1028,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                GDKerror("%s\n", err);
                return GDK_FAIL;
        }
-       if (ATOMstorage(b->ttype) == TYPE_msk) {
+       if (ATOMstorage(b->ttype) == TYPE_msk || mask_cand(b)) {
                ncand = mskCountOnes(b, &ci);
                switch (tp) {
                case TYPE_bte:
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -134,6 +134,8 @@ BATcreatedesc(oid hseq, int tt, bool hea
                                      sizeof(bn->tvheap->filename),
                                      nme, ".theap", NULL);
                }
+       } else {
+               assert(bn->theap == NULL);
        }
        char name[MT_NAME_LEN];
        snprintf(name, sizeof(name), "heaplock%d", bn->batCacheid); /* fits */
@@ -1596,7 +1598,7 @@ BUNfnd(BAT *b, const void *v)
        BATcheck(b, BUN_NONE);
        if (!v)
                return r;
-       if (b->ttype == TYPE_void && b->tvheap != NULL) {
+       if (complex_cand(b)) {
                struct canditer ci;
                canditer_init(&ci, NULL, b);
                return canditer_search(&ci, * (const oid *) v, false);
@@ -2350,8 +2352,8 @@ BATassertProps(BAT *b)
                                /* candidate list with exceptions */
                                assert(b->batRole == TRANSIENT);
                                assert(b->tvheap->free <= b->tvheap->size);
-                               assert(b->tvheap->free % SIZEOF_OID == 0);
-                               if (b->tvheap->free > 0) {
+                               assert((negoid_cand(b) && ccand_free(b) % 
SIZEOF_OID == 0) || mask_cand(b));
+                               if (negoid_cand(b) && ccand_free(b) > 0) {
                                        const oid *oids = (const oid *) 
b->tvheap->base;
                                        q = b->tvheap->free / SIZEOF_OID;
                                        assert(oids != NULL);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1458,7 +1458,7 @@ BATslice(BAT *b, BUN l, BUN h)
                goto doreturn;
        }
 
-       if (b->ttype == TYPE_void && b->tvheap != NULL) {
+       if (complex_cand(b)) {
                /* slicing a candidate list with exceptions */
                struct canditer ci;
                canditer_init(&ci, NULL, b);
diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c
--- a/gdk/gdk_cand.c
+++ b/gdk/gdk_cand.c
@@ -18,6 +18,8 @@ BATiscand(BAT *b)
                return true;
        if (ATOMtype(b->ttype) != TYPE_oid)
                return false;
+       if (complex_cand(b))
+               return true;
        if (b->ttype == TYPE_void && is_oid_nil(b->tseqbase))
                return false;
        return BATtordered(b) && BATtkey(b);
@@ -466,14 +468,14 @@ canditer_init(struct canditer *ci, BAT *
                .s = s,
        };
 
-       if (s->ttype == TYPE_void) {
+       if (s->ttype == TYPE_void && !mask_cand(s)) {
                assert(!is_oid_nil(ci->seq));
                if (s->tvheap) {
-                       assert(s->tvheap->free % SIZEOF_OID == 0);
-                       ci->nvals = s->tvheap->free / SIZEOF_OID;
+                       assert(ccand_free(s) % SIZEOF_OID == 0);
+                       ci->nvals = ccand_free(s) / SIZEOF_OID;
                        if (ci->nvals > 0) {
                                ci->tpe = cand_except;
-                               ci->oids = (const oid *) s->tvheap->base;
+                               ci->oids = (const oid *) ccand_first(s);
                        } else {
                                /* why the vheap? */
                                ci->tpe = cand_dense;
@@ -481,7 +483,13 @@ canditer_init(struct canditer *ci, BAT *
                } else {
                        ci->tpe = cand_dense;
                }
+       } else if (s->ttype == TYPE_void && mask_cand(s)) {
+               ci->tpe = cand_mask;
+               ci->mask = (const uint32_t *) ccand_first(s);
+               ci->seq = s->hseqbase;
+               ci->nvals = (cnt + 31U) / 32U;
        } else if (s->ttype == TYPE_msk) {
+               assert(0);
                ci->tpe = cand_mask;
                ci->mask = (const uint32_t *) s->theap->base;
                ci->seq = s->hseqbase;
@@ -680,7 +688,7 @@ canditer_init(struct canditer *ci, BAT *
                assert(i >= 0); /* there should be a set bit */
                ci->firstbit += i;
                cnt -= i;
-               ci->mskoff = s->hseqbase + (ci->mask - (const uint32_t *) 
s->theap->base) * 32U;
+               ci->mskoff = s->hseqbase + (ci->mask - (const uint32_t *) 
(mask_cand(s)?ccand_first(s):s->theap->base)) * 32U;
                ci->seq = ci->mskoff + ci->firstbit;
                ci->hseq = ci->seq;
                ci->nextbit = ci->firstbit;
@@ -1254,6 +1262,7 @@ BATnegcands(BAT *dense_cands, BAT *odels
        const char *nme;
        Heap *dels;
        BUN lo, hi;
+       ccand_t *c;
 
        assert(BATtdense(dense_cands));
        assert(dense_cands->ttype == TYPE_void);
@@ -1276,17 +1285,21 @@ BATnegcands(BAT *dense_cands, BAT *odels
        strconcat_len(dels->filename, sizeof(dels->filename),
                      nme, ".theap", NULL);
 
-       if (HEAPalloc(dels, hi - lo, sizeof(oid), 0) != GDK_SUCCEED) {
+       if (HEAPalloc(dels, hi - lo + (sizeof(ccand_t)/sizeof(oid)), 
sizeof(oid), 0) != GDK_SUCCEED) {
                GDKfree(dels);
                return GDK_FAIL;
        }
+       c = (ccand_t*)dels->base;
+       c->type = CAND_NEGOID;
        dels->parentid = dense_cands->batCacheid;
-       dels->free = sizeof(oid) * (hi - lo);
+       dels->free = sizeof(ccand_t) + sizeof(oid) * (hi - lo);
        if (odels->ttype == TYPE_void) {
+               oid *r = (oid*)(dels->base + sizeof(ccand_t));
                for (BUN x = lo; x < hi; x++)
-                       ((oid *) dels->base)[x - lo] = x + odels->tseqbase;
+                       r[x - lo] = x + odels->tseqbase;
        } else {
-               memcpy(dels->base, Tloc(odels, lo), dels->free);
+               oid *r = (oid*)(dels->base + sizeof(ccand_t));
+               memcpy(r, Tloc(odels, lo), dels->free);
        }
        dense_cands->batDirtydesc = true;
        dense_cands->tvheap = dels;
@@ -1298,6 +1311,56 @@ BATnegcands(BAT *dense_cands, BAT *odels
        return GDK_SUCCEED;
 }
 
+gdk_return
+BATmaskedcands(BAT *dense_cands, BAT *masked, bool selected)
+{
+       const char *nme;
+       Heap *msks;
+       ccand_t *c;
+
+       assert(BATtdense(dense_cands));
+       assert(dense_cands->ttype == TYPE_void);
+       assert(dense_cands->batRole == TRANSIENT);
+       assert(masked->ttype == TYPE_msk);
+
+       if (BATcount(masked) == 0)
+               return GDK_SUCCEED;
+
+       nme = BBP_physical(dense_cands->batCacheid);
+       if ((msks = (Heap*)GDKzalloc(sizeof(Heap))) == NULL ||
+           (msks->farmid = BBPselectfarm(dense_cands->batRole, 
dense_cands->ttype, varheap)) < 0){
+               GDKfree(msks);
+               return GDK_FAIL;
+       }
+       strconcat_len(msks->filename, sizeof(msks->filename),
+                     nme, ".theap", NULL);
+
+       if (HEAPalloc(msks, (BATcount(masked)+31)/32 + 
(sizeof(ccand_t)/sizeof(int)), sizeof(int), 0) != GDK_SUCCEED) {
+               GDKfree(msks);
+               return GDK_FAIL;
+       }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to