Changeset: 7760275fadff for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7760275fadff Modified Files: gdk/gdk_cand.h monetdb5/modules/kernel/batmmath.c monetdb5/modules/mal/pcre.c Branch: candidate-exceptions Log Message:
Converted batmmath.c and pcre.c to using candidate iterators; removed CANDINIT. diffs (truncated from 425 to 300 lines): diff --git a/gdk/gdk_cand.h b/gdk/gdk_cand.h --- a/gdk/gdk_cand.h +++ b/gdk/gdk_cand.h @@ -9,56 +9,6 @@ #ifndef _GDK_CAND_H_ #define _GDK_CAND_H_ -/* This macro initializes the variables start, end, cnt, cand, and - * candend that were passed as arguments from the input parameters b - * and s (the candidate list). Start and end are the start and end - * BUNs of b that need to be considered. They are relative to the - * start of the heap. Cand and candend point into the candidate list, - * if present. Note that if the candidate list is dense, cand and - * candend are set to NULL and start and end are adjusted instead. */ -#define CANDINIT(b, s, start, end, cnt, cand, candend) \ - do { \ - start = 0; \ - end = cnt = BATcount(b); \ - cand = candend = NULL; \ - if (s) { \ - assert(BATttype(s) == TYPE_oid); \ - if (BATcount(s) == 0) { \ - start = end = 0; \ - } else { \ - if (BATtdense(s)) { \ - start = (s)->tseqbase; \ - end = start + BATcount(s); \ - } else { \ - start = SORTfndfirst((s), &(b)->hseqbase); \ - end = SORTfndfirst((s), &(oid){(b)->hseqbase+BATcount(b)}); \ - cand = (const oid *) Tloc((s), start); \ - candend = (const oid *) Tloc((s), end); \ - if (cand == candend) { \ - start = end = 0; \ - } else { \ - assert(cand < candend); \ - end = cand[end-start-1] + 1; \ - start = *cand; \ - } \ - } \ - assert(start <= end); \ - if (start <= (b)->hseqbase) \ - start = 0; \ - else if (start >= (b)->hseqbase + cnt) \ - start = cnt; \ - else \ - start -= (b)->hseqbase; \ - if (end >= (b)->hseqbase + cnt) \ - end = cnt; \ - else if (end <= (b)->hseqbase) \ - end = 0; \ - else \ - end -= (b)->hseqbase; \ - } \ - } \ - } while (0) - struct canditer { const oid *oids; /* candidate or exceptions for non-dense */ BAT *s; /* candidate BAT the iterator is based on */ diff --git a/monetdb5/modules/kernel/batmmath.c b/monetdb5/modules/kernel/batmmath.c --- a/monetdb5/modules/kernel/batmmath.c +++ b/monetdb5/modules/kernel/batmmath.c @@ -44,20 +44,13 @@ } while (0) -/* from gdk_calc.c */ -#define CANDLOOP(dst, i, NIL, low, high) \ - do { \ - for ((i) = (low); (i) < (high); (i)++) \ - (dst)[i] = NIL; \ - nils += (high) - (low); \ - } while (0) - #define scienceFcnImpl(FUNC,TYPE,SUFF) \ str CMDscience_bat_##TYPE##_##FUNC##_cand(bat *ret, const bat *bid, const bat *sid) \ { \ BAT *b, *s = NULL, *bn; \ - BUN i, cnt, start, end; \ - const oid *restrict cand = NULL, *candend = NULL; \ + BUN i, cnt; \ + struct canditer ci; \ + oid x; \ BUN nils = 0; \ int e = 0, ex = 0; \ \ @@ -69,7 +62,8 @@ str CMDscience_bat_##TYPE##_##FUNC##_can BBPunfix(b->batCacheid); \ throw(MAL, #TYPE, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \ } \ - CANDINIT(b, s, start, end, cnt, cand, candend); \ + canditer_init(&ci, b, s); \ + cnt = BATcount(b); \ bn = COLnew(b->hseqbase, TYPE_##TYPE, cnt, TRANSIENT); \ if (bn == NULL) { \ BBPunfix(b->batCacheid); \ @@ -79,41 +73,28 @@ str CMDscience_bat_##TYPE##_##FUNC##_can \ const TYPE *restrict src = (const TYPE *) Tloc(b, 0); \ TYPE *restrict dst = (TYPE *) Tloc(bn, 0); \ - CANDLOOP(dst, i, TYPE##_nil, 0, start); \ errno = 0; \ feclearexcept(FE_ALL_EXCEPT); \ - if (b->tnonil && cand == NULL) { \ - for (i = start; i < end; i++) \ + for (i = 0; i < cnt; i++) { \ + x = canditer_next(&ci); \ + if (is_oid_nil(x)) \ + break; \ + x -= b->hseqbase; \ + while (i < x) { \ + dst[i++] = TYPE##_nil; \ + nils++; \ + } \ + if (is_##TYPE##_nil(src[i])) { \ + nils++; \ + dst[i] = TYPE##_nil; \ + } else { \ dst[i] = FUNC##SUFF(src[i]); \ - } else { \ - if (cand) { \ - for (i = start; i < end; i++) { \ - if (i < *cand - b->hseqbase) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - continue; \ - } \ - assert(i == *cand - b->hseqbase); \ - if (++cand == candend) \ - end = i + 1; \ - if (is_##TYPE##_nil(src[i])) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - } else { \ - dst[i] = FUNC##SUFF(src[i]); \ - } \ - } \ - } else { \ - for (i = start; i < end; i++) { \ - if (is_##TYPE##_nil(src[i])) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - } else { \ - dst[i] = FUNC##SUFF(src[i]); \ - } \ - } \ } \ } \ + while (i < cnt) { \ + dst[i++] = TYPE##_nil; \ + nils++; \ + } \ e = errno; \ ex = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW); \ BBPunfix(b->batCacheid); \ @@ -132,7 +113,6 @@ str CMDscience_bat_##TYPE##_##FUNC##_can err = "Invalid result"; \ throw(MAL, "batmmath." #FUNC, "Math exception: %s", err); \ } \ - CANDLOOP(dst, i, TYPE##_nil, end, cnt); \ BATsetcount(bn, cnt); \ bn->theap.dirty = true; \ \ @@ -155,8 +135,9 @@ str CMDscience_bat_cst_##FUNC##_##TYPE## const TYPE *d, const bat *sid) \ { \ BAT *b, *s = NULL, *bn; \ - BUN i, cnt, start, end; \ - const oid *restrict cand = NULL, *candend = NULL; \ + BUN i, cnt; \ + struct canditer ci; \ + oid x; \ BUN nils = 0; \ int e = 0, ex = 0; \ \ @@ -168,7 +149,8 @@ str CMDscience_bat_cst_##FUNC##_##TYPE## BBPunfix(b->batCacheid); \ throw(MAL, #TYPE, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \ } \ - CANDINIT(b, s, start, end, cnt, cand, candend); \ + canditer_init(&ci, b, s); \ + cnt = BATcount(b); \ bn = COLnew(b->hseqbase, TYPE_##TYPE, cnt, TRANSIENT); \ if (bn == NULL) { \ BBPunfix(b->batCacheid); \ @@ -178,41 +160,28 @@ str CMDscience_bat_cst_##FUNC##_##TYPE## \ const TYPE *restrict src = (const TYPE *) Tloc(b, 0); \ TYPE *restrict dst = (TYPE *) Tloc(bn, 0); \ - CANDLOOP(dst, i, TYPE##_nil, 0, start); \ errno = 0; \ feclearexcept(FE_ALL_EXCEPT); \ - if (b->tnonil && cand == NULL) { \ - for (i = start; i < end; i++) \ + for (i = 0; i < cnt; i++) { \ + x = canditer_next(&ci); \ + if (is_oid_nil(x)) \ + break; \ + x -= b->hseqbase; \ + while (i < x) { \ + dst[i++] = TYPE##_nil; \ + nils++; \ + } \ + if (is_##TYPE##_nil(src[i])) { \ + nils++; \ + dst[i] = TYPE##_nil; \ + } else { \ dst[i] = FUNC##SUFF(src[i], *d); \ - } else { \ - if (cand) { \ - for (i = start; i < end; i++) { \ - if (i < *cand - b->hseqbase) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - continue; \ - } \ - assert(i == *cand - b->hseqbase); \ - if (++cand == candend) \ - end = i + 1; \ - if (is_##TYPE##_nil(src[i])) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - } else { \ - dst[i] = FUNC##SUFF(src[i], *d); \ - } \ - } \ - } else { \ - for (i = start; i < end; i++) { \ - if (is_##TYPE##_nil(src[i])) { \ - nils++; \ - dst[i] = TYPE##_nil; \ - } else { \ - dst[i] = FUNC##SUFF(src[i], *d); \ - } \ - } \ } \ } \ + while (i < cnt) { \ + dst[i++] = TYPE##_nil; \ + nils++; \ + } \ e = errno; \ ex = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW); \ BBPunfix(b->batCacheid); \ @@ -231,7 +200,6 @@ str CMDscience_bat_cst_##FUNC##_##TYPE## err = "Invalid result"; \ throw(MAL, "batmmath." #FUNC, "Math exception: %s", err); \ } \ - CANDLOOP(dst, i, TYPE##_nil, end, cnt); \ BATsetcount(bn, cnt); \ bn->theap.dirty = true; \ \ @@ -254,8 +222,9 @@ str CMDscience_cst_bat_##FUNC##_##TYPE## const bat *bid, const bat *sid) \ { \ BAT *b, *s = NULL, *bn; \ - BUN i, cnt, start, end; \ - const oid *restrict cand = NULL, *candend = NULL; \ + BUN i, cnt; \ + struct canditer ci; \ + oid x; \ BUN nils = 0; \ int e = 0, ex = 0; \ \ @@ -267,7 +236,8 @@ str CMDscience_cst_bat_##FUNC##_##TYPE## BBPunfix(b->batCacheid); \ throw(MAL, #TYPE, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \ } \ - CANDINIT(b, s, start, end, cnt, cand, candend); \ + canditer_init(&ci, b, s); \ + cnt = BATcount(b); \ bn = COLnew(b->hseqbase, TYPE_##TYPE, cnt, TRANSIENT); \ if (bn == NULL) { \ BBPunfix(b->batCacheid); \ @@ -277,41 +247,28 @@ str CMDscience_cst_bat_##FUNC##_##TYPE## \ const TYPE *restrict src = (const TYPE *) Tloc(b, 0); \ TYPE *restrict dst = (TYPE *) Tloc(bn, 0); \ - CANDLOOP(dst, i, TYPE##_nil, 0, start); \ errno = 0; \ feclearexcept(FE_ALL_EXCEPT); \ - if (b->tnonil && cand == NULL) { \ - for (i = start; i < end; i++) \ + for (i = 0; i < cnt; i++) { \ + x = canditer_next(&ci); \ + if (is_oid_nil(x)) \ + break; \ + x -= b->hseqbase; \ + while (i < x) { \ + dst[i++] = TYPE##_nil; \ + nils++; \ + } \ + if (is_##TYPE##_nil(src[i])) { \ + nils++; \ + dst[i] = TYPE##_nil; \ + } else { \ dst[i] = FUNC##SUFF(*d, src[i]); \ - } else { \ - if (cand) { \ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list