Changeset: 704ffe11198a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/704ffe11198a
Modified Files:
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_cand.c
gdk/gdk_group.c
gdk/gdk_select.c
monetdb5/mal/mal_profiler.c
Branch: default
Log Message:
Move minpos and maxpos properties into BAT structure.
Remove minval and maxval properties, they're a simple indirection
away; copy minpos and maxpos properties in COLcopy.
diffs (truncated from 1546 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -724,6 +724,7 @@ typedef struct {
BUN nokey[2]; /* positions that prove key==FALSE */
BUN nosorted; /* position that proves sorted==FALSE */
BUN norevsorted; /* position that proves revsorted==FALSE */
+ BUN minpos, maxpos; /* location of min/max value */
oid seq; /* start of dense sequence */
Heap *heap; /* space for the column. */
@@ -793,6 +794,8 @@ typedef struct BAT {
#define tnokey T.nokey
#define tnosorted T.nosorted
#define tnorevsorted T.norevsorted
+#define tminpos T.minpos
+#define tmaxpos T.maxpos
#define theap T.heap
#define tbaseoff T.baseoff
#define tvheap T.vheap
@@ -919,6 +922,7 @@ typedef struct BATiter {
int8_t type;
oid tseq;
BUN hfree, vhfree;
+ BUN minpos, maxpos;
union {
oid tvid;
bool tmsk;
@@ -929,13 +933,11 @@ typedef struct BATiter {
} BATiter;
static inline BATiter
-bat_iterator(BAT *b)
+bat_iterator_nolock(BAT *b)
{
- /* needs matching bat_iterator_end */
- BATiter bi;
+ /* does not get matched by bat_iterator_end */
if (b) {
- MT_lock_set(&b->theaplock);
- bi = (BATiter) {
+ return (BATiter) {
.b = b,
.h = b->theap,
.base = b->theap->base ? b->theap->base + (b->tbaseoff
<< b->tshift) : NULL,
@@ -947,10 +949,27 @@ bat_iterator(BAT *b)
.tseq = b->tseqbase,
.hfree = b->theap->free,
.vhfree = b->tvheap ? b->tvheap->free : 0,
+ .minpos = b->tminpos,
+ .maxpos = b->tmaxpos,
#ifndef NDEBUG
- .locked = true,
+ .locked = false,
#endif
};
+ }
+ return (BATiter) {0};
+}
+
+static inline BATiter
+bat_iterator(BAT *b)
+{
+ /* needs matching bat_iterator_end */
+ BATiter bi;
+ if (b) {
+ MT_lock_set(&b->theaplock);
+ bi = bat_iterator_nolock(b);
+#ifndef NDEBUG
+ bi.locked = true;
+#endif
HEAPincref(bi.h);
if (bi.vh)
HEAPincref(bi.vh);
@@ -979,31 +998,6 @@ bat_iterator_end(BATiter *bip)
*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,
- .base = b->theap->base ? b->theap->base + (b->tbaseoff
<< b->tshift) : NULL,
- .vh = b->tvheap,
- .count = b->batCount,
- .width = b->twidth,
- .shift = b->tshift,
- .type = b->ttype,
- .tseq = b->tseqbase,
- .hfree = b->theap->free,
- .vhfree = b->tvheap ? b->tvheap->free : 0,
-#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
@@ -1446,6 +1440,8 @@ BATsettrivprop(BAT *b)
} else {
b->tnonil = true;
b->tnil = false;
+ b->tminpos = 0;
+ b->tmaxpos = 0;
}
b->tseqbase = sqbs;
}
@@ -2242,11 +2238,7 @@ gdk_export void VIEWbounds(BAT *b, BAT *
* levels.
*/
enum prop_t {
- GDK_MIN_VALUE = 3, /* smallest non-nil value in BAT */
- GDK_MIN_POS, /* BUN position of smallest value (oid) */
- GDK_MAX_VALUE, /* largest non-nil value in BAT */
- GDK_MAX_POS, /* BUN position of largest value (oid) */
- GDK_HASH_BUCKETS, /* last used hash bucket size (oid) */
+ GDK_HASH_BUCKETS = 3, /* last used hash bucket size (oid) */
GDK_NUNIQUE, /* number of unique values (oid) */
GDK_UNIQUE_ESTIMATE, /* estimate of number of distinct values (dbl)
*/
};
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -81,14 +81,9 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
max = 0;
ngrp = 1;
} else if (e == NULL) {
- /* we need to find out the min and max of g */
- const ValRecord *prop;
-
- prop = BATgetprop(g, GDK_MAX_VALUE);
- if (prop) {
- assert(prop->vtype == TYPE_oid);
- min = 0; /* just assume it starts at 0 */
- max = prop->val.oval;
+ if (g->tmaxpos != BUN_NONE) {
+ min = 0;
+ max = BUNtoid(g, g->tmaxpos);
} else {
min = oid_nil; /* note that oid_nil > 0! (unsigned) */
max = 0;
@@ -3324,14 +3319,14 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
#define AGGR_CMP(TYPE, OP) \
do { \
- const TYPE *restrict vals = (const TYPE *) bi.base; \
+ const TYPE *restrict vals = (const TYPE *) bi->base; \
if (ngrp == ncand) { \
/* single element groups */ \
TIMEOUT_LOOP(ncand, timeoffset) { \
- i = canditer_next(ci) - b->hseqbase; \
+ i = canditer_next(ci) - hseq; \
if (!skip_nils || \
!is_##TYPE##_nil(vals[i])) { \
- oids[i] = i + b->hseqbase; \
+ oids[i] = i + hseq; \
nils--; \
} \
} \
@@ -3340,19 +3335,19 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
} else { \
gid = 0; /* in case gids == NULL */ \
TIMEOUT_LOOP(ncand, timeoffset) { \
- i = canditer_next(ci) - b->hseqbase; \
+ i = canditer_next(ci) - hseq; \
if (gids == NULL || \
(gids[i] >= min && gids[i] <= max)) { \
if (gids) \
gid = gids[i] - min; \
if (!skip_nils ||
!is_##TYPE##_nil(vals[i])) { \
if (is_oid_nil(oids[gid])) { \
- oids[gid] = i +
b->hseqbase; \
+ oids[gid] = i + hseq; \
nils--; \
- } else if
(!is_##TYPE##_nil(vals[oids[gid] - b->hseqbase]) && \
+ } else if
(!is_##TYPE##_nil(vals[oids[gid] - hseq]) && \
(is_##TYPE##_nil(vals[i]) || \
- OP(vals[i],
vals[oids[gid] - b->hseqbase]))) \
- oids[gid] = i +
b->hseqbase; \
+ OP(vals[i],
vals[oids[gid] - hseq]))) \
+ oids[gid] = i + hseq; \
} \
} \
} \
@@ -3366,7 +3361,7 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
* note that this functions returns *positions* of where the minimum
* values occur */
static BUN
-do_groupmin(oid *restrict oids, BAT *b, const oid *restrict gids, BUN ngrp,
+do_groupmin(oid *restrict oids, BATiter *bi, const oid *restrict gids, BUN
ngrp,
oid min, oid max, struct canditer *restrict ci, BUN ncand,
bool skip_nils, bool gdense)
{
@@ -3388,12 +3383,11 @@ do_groupmin(oid *restrict oids, BAT *b,
if (ncand == 0)
return nils;
- t = b->ttype;
+ t = bi->b->ttype;
nil = ATOMnilptr(t);
atomcmp = ATOMcompare(t);
t = ATOMbasetype(t);
-
- BATiter bi = bat_iterator(b);
+ oid hseq = bi->b->hseqbase;
switch (t) {
case TYPE_bte:
@@ -3420,7 +3414,7 @@ do_groupmin(oid *restrict oids, BAT *b,
AGGR_CMP(dbl, LT);
break;
case TYPE_void:
- if (!skip_nils || !is_oid_nil(b->tseqbase)) {
+ if (!skip_nils || !is_oid_nil(bi->tseq)) {
if (!gdense && gids == NULL) {
oids[0] = canditer_next(ci);
nils--;
@@ -3429,15 +3423,15 @@ do_groupmin(oid *restrict oids, BAT *b,
while (ncand > 0) {
ncand--;
i = canditer_next(ci);
- oids[i - b->hseqbase] = i;
+ oids[i - hseq] = i;
nils--;
}
} else {
while (ncand > 0) {
ncand--;
i = canditer_next(ci);
- if (is_oid_nil(oids[i - b->hseqbase])) {
- oids[i - b->hseqbase] = i;
+ if (is_oid_nil(oids[i - hseq])) {
+ oids[i - hseq] = i;
nils--;
}
}
@@ -3445,15 +3439,15 @@ do_groupmin(oid *restrict oids, BAT *b,
}
break;
default:
- assert(b->ttype != TYPE_oid);
+ assert(bi->b->ttype != TYPE_oid);
if (gdense) {
/* single element groups */
TIMEOUT_LOOP(ncand, timeoffset) {
- i = canditer_next(ci) - b->hseqbase;
+ i = canditer_next(ci) - hseq;
if (!skip_nils ||
- (*atomcmp)(BUNtail(bi, i), nil) != 0) {
- oids[i] = i + b->hseqbase;
+ (*atomcmp)(BUNtail(*bi, i), nil) != 0) {
+ oids[i] = i + hseq;
nils--;
}
}
@@ -3462,23 +3456,23 @@ do_groupmin(oid *restrict oids, BAT *b,
} else {
gid = 0; /* in case gids == NULL */
TIMEOUT_LOOP(ncand, timeoffset) {
- i = canditer_next(ci) - b->hseqbase;
+ i = canditer_next(ci) - hseq;
if (gids == NULL ||
(gids[i] >= min && gids[i] <= max)) {
- const void *v = BUNtail(bi, i);
+ const void *v = BUNtail(*bi, i);
if (gids)
gid = gids[i] - min;
if (!skip_nils ||
(*atomcmp)(v, nil) != 0) {
if (is_oid_nil(oids[gid])) {
- oids[gid] = i +
b->hseqbase;
+ oids[gid] = i + hseq;
nils--;
} else if (t != TYPE_void) {
- const void *g =
BUNtail(bi, (BUN) (oids[gid] - b->hseqbase));
+ const void *g =
BUNtail(*bi, (BUN) (oids[gid] - hseq));
if ((*atomcmp)(g, nil)
!= 0 &&
((*atomcmp)(v, nil)
== 0 ||
LT((*atomcmp)(v,
g), 0)))
- oids[gid] = i +
b->hseqbase;
+ oids[gid] = i +
hseq;
}
}
}
@@ -3489,8 +3483,6 @@ do_groupmin(oid *restrict oids, BAT *b,
break;
}
- bat_iterator_end(&bi);
-
return nils;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list