Changeset: 9d0e1c9e3201 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d0e1c9e3201
Branch: Jul2021
Log Message:
merged
diffs (truncated from 9020 to 300 lines):
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
@@ -187,7 +187,7 @@ BAT *BATsample_with_seed(BAT *b, BUN n,
gdk_return BATsave(BAT *b) __attribute__((__warn_unused_result__));
BAT *BATselect(BAT *b, BAT *s, const void *tl, const void *th, bool li, bool
hi, bool anti);
gdk_return BATsemijoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr,
bool nil_matches, bool max_one, BUN estimate)
__attribute__((__warn_unused_result__));
-gdk_return BATsetaccess(BAT *b, restrict_t mode);
+BAT *BATsetaccess(BAT *b, restrict_t mode)
__attribute__((__warn_unused_result__));
void BATsetcapacity(BAT *b, BUN cnt);
void BATsetcount(BAT *b, BUN cnt);
BAT *BATslice(BAT *b, BUN low, BUN high);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -776,14 +776,6 @@ typedef struct BAT {
MT_Lock batIdxLock; /* lock to manipulate other indexes/properties
*/
} BAT;
-typedef struct BATiter {
- BAT *b;
- union {
- oid tvid;
- bool tmsk;
- };
-} BATiter;
-
/* macros to hide complexity of the BAT structure */
#define ttype T.type
#define tkey T.key
@@ -808,6 +800,25 @@ typedef struct BATiter {
#define tprops T.props
+typedef struct BATiter {
+ BAT *b;
+ Heap *h;
+ Heap *vh;
+ BUN baseoff;
+ BUN count;
+ uint16_t width;
+ uint8_t shift;
+ int8_t type;
+ oid tseq;
+ union {
+ oid tvid;
+ bool tmsk;
+ };
+#ifndef NDEBUG
+ bool locked;
+#endif
+} BATiter;
+
/* some access functions for the bitmask type */
static inline void
mskSet(BAT *b, BUN p)
@@ -879,6 +890,78 @@ gdk_export size_t HEAPmemsize(Heap *h);
gdk_export void HEAPdecref(Heap *h, bool remove);
gdk_export void HEAPincref(Heap *h);
+static inline BATiter
+bat_iterator(BAT *b)
+{
+ /* needs matching bat_iterator_end */
+ BATiter bi;
+ if (b) {
+ MT_lock_set(&b->theaplock);
+ bi = (BATiter) {
+ .b = b,
+ .h = b->theap,
+ .vh = b->tvheap,
+ .baseoff = b->tbaseoff,
+ .count = b->batCount,
+ .width = b->twidth,
+ .shift = b->tshift,
+ .type = b->ttype,
+ .tseq = b->tseqbase,
+#ifndef NDEBUG
+ .locked = true,
+#endif
+ };
+ HEAPincref(bi.h);
+ if (bi.vh)
+ HEAPincref(bi.vh);
+ MT_lock_unset(&b->theaplock);
+ } else {
+ bi = (BATiter) {
+ .b = NULL,
+#ifndef NDEBUG
+ .locked = true,
+#endif
+ };
+ }
+ return bi;
+}
+
+static inline void
+bat_iterator_end(BATiter *bip)
+{
+ /* matches bat_iterator */
+ assert(bip);
+ assert(bip->locked);
+ if (bip->h)
+ HEAPdecref(bip->h, false);
+ if (bip->vh)
+ HEAPdecref(bip->vh, false);
+ *bip = (BATiter) {0};
+}
+
+static inline BATiter
+bat_iterator_nolock(BAT *b)
+{
+ /* does not get matched by bat_iterator_end */
+ if (b) {
+ return (BATiter) {
+ .b = b,
+ .h = b->theap,
+ .vh = b->tvheap,
+ .baseoff = b->tbaseoff,
+ .count = b->batCount,
+ .width = b->twidth,
+ .shift = b->tshift,
+ .type = b->ttype,
+ .tseq = b->tseqbase,
+#ifndef NDEBUG
+ .locked = false,
+#endif
+ };
+ }
+ return (BATiter) {0};
+}
+
/*
* @- Internal HEAP Chunk Management
* Heaps are used in BATs to store data for variable-size atoms. The
@@ -1011,12 +1094,12 @@ typedef var_t stridx_t;
#define SIZEOF_STRIDX_T SIZEOF_VAR_T
#define GDK_VARALIGN SIZEOF_STRIDX_T
-#define BUNtvaroff(bi,p) VarHeapVal(Tloc((bi).b, 0), (p), (bi).b->twidth)
+#define BUNtvaroff(bi,p) VarHeapVal((bi).h->base + ((bi).baseoff <<
(bi).shift), (p), (bi).width)
-#define BUNtloc(bi,p) (ATOMstorage((bi).b->ttype) == TYPE_msk ? Tmsk(&(bi),
p) : Tloc((bi).b,p))
+#define BUNtloc(bi,p) (ATOMstorage((bi).type) == TYPE_msk ? Tmsk(&(bi), p) :
(bi).h->base + (((bi).baseoff + (p)) << (bi).shift))
#define BUNtpos(bi,p) Tpos(&(bi),p)
-#define BUNtvar(bi,p) (assert((bi).b->ttype && (bi).b->tvarsized), (void *)
(Tbase((bi).b)+BUNtvaroff(bi,p)))
-#define BUNtail(bi,p)
((bi).b->ttype?(bi).b->tvarsized?BUNtvar(bi,p):BUNtloc(bi,p):BUNtpos(bi,p))
+#define BUNtvar(bi,p) (assert((bi).type && (bi).b->tvarsized), (void *)
((bi).vh->base+BUNtvaroff(bi,p)))
+#define BUNtail(bi,p)
((bi).type?(bi).b->tvarsized?BUNtvar(bi,p):BUNtloc(bi,p):BUNtpos(bi,p))
#define BUNlast(b) (assert((b)->batCount <= BUN_MAX), (b)->batCount)
@@ -1072,8 +1155,6 @@ BUNtoid(BAT *b, BUN p)
return o + hi;
}
-#define bat_iterator(_b) ((BATiter) {.b = (_b), .tvid = 0})
-
/*
* @- BAT properties
* @multitable @columnfractions 0.08 0.7
@@ -1144,7 +1225,8 @@ typedef enum {
BAT_APPEND, /* only reads and appends allowed */
} restrict_t;
-gdk_export gdk_return BATsetaccess(BAT *b, restrict_t mode);
+gdk_export BAT *BATsetaccess(BAT *b, restrict_t mode)
+ __attribute__((__warn_unused_result__));
gdk_export restrict_t BATgetaccess(BAT *b);
@@ -1867,6 +1949,53 @@ BATdescriptor(bat i)
static inline void *
Tpos(BATiter *bi, BUN p)
{
+ if (bi->h->base) {
+ bi->tvid = ((const oid *) bi->h->base)[p];
+ } else if (bi->vh) {
+ oid o;
+ if (((ccand_t *) bi->vh)->type == CAND_NEGOID) {
+ BUN nexc = (bi->vh->free - sizeof(ccand_t)) /
SIZEOF_OID;
+ o = bi->tseq + p;
+ if (nexc > 0) {
+ const oid *exc = (const oid *) (bi->vh->base +
sizeof(ccand_t));
+ if (o >= exc[0]) {
+ if (o + nexc > exc[nexc - 1]) {
+ o += nexc;
+ } else {
+ BUN lo = 0;
+ BUN hi = nexc - 1;
+ while (hi - lo > 1) {
+ BUN mid = (hi + lo) / 2;
+ if (exc[mid] - mid > o)
+ hi = mid;
+ else
+ lo = mid;
+ }
+ o += hi;
+ }
+ }
+ }
+ } else {
+ const uint32_t *msk = (const uint32_t *) (bi->vh->base
+ sizeof(ccand_t));
+ BUN nmsk = (bi->vh->free - sizeof(ccand_t)) /
sizeof(uint32_t);
+ o = 0;
+ for (BUN i = 0; i < nmsk; i++) {
+ uint32_t m = candmask_pop(msk[i]);
+ if (o + m > p) {
+ m = msk[i];
+ for (i = 0; i < 32; i++) {
+ if (m & (1U << i) && ++o == p)
+ break;
+ }
+ break;
+ }
+ o += m;
+ }
+ }
+ bi->tvid = o;
+ } else {
+ bi->tvid = bi->tseq + p;
+ }
bi->tvid = BUNtoid(bi->b, p);
return (void*)&bi->tvid;
}
@@ -1874,7 +2003,7 @@ Tpos(BATiter *bi, BUN p)
static inline void *
Tmsk(BATiter *bi, BUN p)
{
- bi->tmsk = mskGetVal(bi->b, p);
+ bi->tmsk = ((uint32_t *) bi->h->base)[p / 32] & (1U << (p % 32));
return &bi->tmsk;
}
@@ -2003,8 +2132,6 @@ gdk_export void BATundo(BAT *b);
* @tab VIEWhparent (BAT *b)
* @item bat
* @tab VIEWtparent (BAT *b)
- * @item BAT*
- * @tab VIEWreset (BAT *b)
* @end multitable
*
* Alignments of two columns of a BAT means that the system knows
@@ -2022,10 +2149,6 @@ gdk_export void BATundo(BAT *b);
* any) is returned by VIEWtparent (otherwise it returns 0).
*
* VIEW bats are read-only!!
- *
- * VIEWreset creates a normal BAT with the same contents as its view
- * parameter (it converts void columns with seqbase!=nil to
- * materialized oid columns).
*/
gdk_export int ALIGNsynced(BAT *b1, BAT *b2);
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -903,7 +903,7 @@ BATgroupsum(BAT *b, BAT *g, BAT *e, BAT
return NULL;
}
- if (BATcount(b) == 0 || ngrp == 0) {
+ if (ncand == 0 || ngrp == 0) {
/* trivial: no sums, so return bat aligned with g with
* nil in the tail */
return BATconstant(ngrp == 0 ? 0 : min, tp, ATOMnilptr(tp),
ngrp, TRANSIENT);
@@ -927,9 +927,15 @@ BATgroupsum(BAT *b, BAT *g, BAT *e, BAT
else
gids = (const oid *) Tloc(g, 0);
- nils = dosum(Tloc(b, 0), b->tnonil, b->hseqbase, &ci, ncand,
+ MT_lock_set(&b->theaplock);
+ Heap *h = b->theap;
+ HEAPincref(h);
+ BUN baseoff = b->tbaseoff;
+ MT_lock_unset(&b->theaplock);
+ nils = dosum(h->base + (baseoff << b->tshift), b->tnonil, b->hseqbase,
&ci, ncand,
Tloc(bn, 0), ngrp, b->ttype, tp, gids, min, max,
skip_nils, abort_on_error, true, __func__, &algo);
+ HEAPdecref(h, false);
if (nils < BUN_NONE) {
BATsetcount(bn, ngrp);
@@ -961,13 +967,21 @@ mskCountOnes(BAT *b, struct canditer *ci
if (ci->s == NULL && mask_cand(b))
return BATcount(b);
- if (ci->tpe == cand_dense && BATcount(b) && !mask_cand(b)) {
- const uint32_t *restrict src = Tloc(b, (ci->seq - b->hseqbase)
/ 32);
+ if (ci->tpe == cand_dense && ncand > 0 && !mask_cand(b)) {
+ MT_lock_set(&b->theaplock);
+ Heap *h = b->theap;
+ BUN baseoff = b->tbaseoff;
+ HEAPincref(h);
+ MT_lock_unset(&b->theaplock);
+ const uint32_t *restrict src = (const uint32_t *) (h->base +
baseoff + 4 * ((ci->seq - b->hseqbase) / 32));
int bits = (ci->seq - b->hseqbase) % 32;
if (bits + ncand <= 32) {
if (ncand == 32)
- return candmask_pop(src[0]);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list