Changeset: b3866b36570f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/b3866b36570f Modified Files: clients/Tests/exports.stable.out gdk/gdk.h gdk/gdk_align.c gdk/gdk_bat.c gdk/gdk_batop.c gdk/gdk_private.h monetdb5/modules/atoms/batxml.c monetdb5/modules/mal/iterator.c Branch: default Log Message:
VIEWcreate is now combined with VIEWbounds: create view with bounds. diffs (truncated from 336 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 @@ -451,7 +451,7 @@ gdk_return VARcalcsub(ValPtr ret, const gdk_return VARcalcxor(ValPtr ret, const ValRecord *lft, const ValRecord *rgt); gdk_return VARconvert(ValPtr ret, const ValRecord *v, uint8_t scale1, uint8_t scale2, uint8_t precision); void VIEWbounds(BAT *b, BAT *view, BUN l, BUN h); -BAT *VIEWcreate(oid seq, BAT *b); +BAT *VIEWcreate(oid seq, BAT *b, BUN l, BUN h); size_t _MT_npages; size_t _MT_pagesize; const union _dbl_nil_t _dbl_nil_; diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -2116,7 +2116,7 @@ gdk_export void BATcommit(BAT *b, BUN si * @tab ALIGNrelated (BAT *b1, BAT *b2) * * @item BAT* - * @tab VIEWcreate (oid seq, BAT *b) + * @tab VIEWcreate (oid seq, BAT *b, BUN lo, BUN hi) * @item int * @tab isVIEW (BAT *b) * @item bat @@ -2145,7 +2145,7 @@ gdk_export int ALIGNsynced(BAT *b1, BAT gdk_export void BATassertProps(BAT *b); -gdk_export BAT *VIEWcreate(oid seq, BAT *b); +gdk_export BAT *VIEWcreate(oid seq, BAT *b, BUN l, BUN h); gdk_export void VIEWbounds(BAT *b, BAT *view, BUN l, BUN h); #define ALIGNapp(x, f, e) \ diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c --- a/gdk/gdk_align.c +++ b/gdk/gdk_align.c @@ -82,8 +82,63 @@ ALIGNsynced(BAT *b1, BAT *b2) * cannot physically share the batBuns heap with the parent, as they * need a modified version. */ +static void +VIEWboundsbi(BATiter *bi, BAT *view, BUN l, BUN h) +{ + BUN cnt; + BUN baseoff; + + if (bi == NULL || view == NULL) + return; + if (h > bi->count) + h = bi->count; + baseoff = bi->baseoff; + if (h < l) + h = l; + cnt = h - l; + view->batInserted = 0; + if (view->ttype != TYPE_void) { + view->tbaseoff = baseoff + l; + } + BATsetcount(view, cnt); + BATsetcapacity(view, cnt); + if (view->tnosorted > l && view->tnosorted < l + cnt) + view->tnosorted -= l; + else + view->tnosorted = 0; + if (view->tnorevsorted > l && view->tnorevsorted < l + cnt) + view->tnorevsorted -= l; + else + view->tnorevsorted = 0; + if (view->tnokey[0] >= l && view->tnokey[0] < l + cnt && + view->tnokey[1] >= l && view->tnokey[1] < l + cnt && + view->tnokey[0] != view->tnokey[1]) { + view->tnokey[0] -= l; + view->tnokey[1] -= l; + } else { + view->tnokey[0] = view->tnokey[1] = 0; + } + if (view->tminpos >= l && view->tminpos < l + cnt) + view->tminpos -= l; + else + view->tminpos = BUN_NONE; + if (view->tmaxpos >= l && view->tmaxpos < l + cnt) + view->tmaxpos -= l; + else + view->tmaxpos = BUN_NONE; + view->tkey |= cnt <= 1; +} + +void +VIEWbounds(BAT *b, BAT *view, BUN l, BUN h) +{ + BATiter bi = bat_iterator(b); + VIEWboundsbi(&bi, view, l, h); + bat_iterator_end(&bi); +} + BAT * -VIEWcreate(oid seq, BAT *b) +VIEWcreate(oid seq, BAT *b, BUN l, BUN h) { BAT *bn; bat tp = 0; @@ -92,7 +147,11 @@ VIEWcreate(oid seq, BAT *b) if (b->ttype == TYPE_void) { /* we don't do views on void bats */ - return BATdense(seq, b->tseqbase, b->batCount); + if (h > b->batCount) + h = b->batCount; + if (l > h) + l = h = 0; + return BATdense(seq, b->tseqbase + l, h - l); } bn = BATcreatedesc(seq, b->ttype, false, TRANSIENT, 0); @@ -101,40 +160,43 @@ VIEWcreate(oid seq, BAT *b) assert(bn->theap == NULL); MT_lock_set(&b->theaplock); + BATiter bi = bat_iterator_nolock(b); bn->batInserted = 0; - bn->batCount = b->batCount; + bn->batCount = bi.count; bn->batCapacity = b->batCapacity; bn->batRestricted = BAT_READ; /* the T column descriptor is fully copied except for the * accelerator data. We need copies because in case of a mark, * we are going to override a column with a void. */ - bn->tkey = b->tkey; - bn->tseqbase = b->tseqbase; - bn->tsorted = b->tsorted; - bn->trevsorted = b->trevsorted; - bn->twidth = b->twidth; - bn->tshift = b->tshift; - bn->tnonil = b->tnonil; - bn->tnil = b->tnil; - bn->tnokey[0] = b->tnokey[0]; - bn->tnokey[1] = b->tnokey[1]; - bn->tnosorted = b->tnosorted; - bn->tnorevsorted = b->tnorevsorted; - bn->tminpos = b->tminpos; - bn->tmaxpos = b->tmaxpos; - bn->tunique_est = b->tunique_est; - bn->theap = b->theap; - bn->tbaseoff = b->tbaseoff; - bn->tvheap = b->tvheap; + bn->tkey = bi.key; + bn->tseqbase = bi.tseq; + bn->tsorted = bi.sorted; + bn->trevsorted = bi.revsorted; + bn->twidth = bi.width; + bn->tshift = bi.shift; + bn->tnonil = bi.nonil; + bn->tnil = bi.nil; + bn->tnokey[0] = bi.nokey[0]; + bn->tnokey[1] = bi.nokey[1]; + bn->tnosorted = bi.nosorted; + bn->tnorevsorted = bi.norevsorted; + bn->tminpos = bi.minpos; + bn->tmaxpos = bi.maxpos; + bn->tunique_est = bi.unique_est; + bn->theap = bi.h; + bn->tbaseoff = bi.baseoff; + bn->tvheap = bi.vh; tp = VIEWtparent(b); if (tp == 0 && b->ttype != TYPE_void) tp = b->batCacheid; assert(b->ttype != TYPE_void || !tp); - HEAPincref(b->theap); - if (b->tvheap) - HEAPincref(b->tvheap); + HEAPincref(bi.h); + if (bi.vh) + HEAPincref(bi.vh); + if (l != 0 || h < bi.count) + VIEWboundsbi(&bi, bn, l, h); MT_lock_unset(&b->theaplock); if (BBPcacheit(bn, true) != GDK_SUCCEED) { /* enter in BBP */ @@ -150,8 +212,8 @@ VIEWcreate(oid seq, BAT *b) BBPretain(bn->theap->parentid); if (bn->tvheap) BBPretain(bn->tvheap->parentid); - TRC_DEBUG(ALGO, ALGOBATFMT " -> " ALGOBATFMT "\n", - ALGOBATPAR(b), ALGOBATPAR(bn)); + TRC_DEBUG(ALGO, ALGOBATFMT " " BUNFMT "," BUNFMT " -> " ALGOBATFMT "\n", + ALGOBATPAR(b), l, h, ALGOBATPAR(bn)); return bn; } @@ -273,65 +335,6 @@ BATmaterialize(BAT *b, BUN cap) } /* - * The remainder are utilities to manipulate the BAT view and not to - * forget some details in the process. It expects a position range in - * the underlying BAT and compensates for outliers. - */ -void -VIEWboundsbi(BATiter *bi, BAT *view, BUN l, BUN h) -{ - BUN cnt; - BUN baseoff; - - if (bi == NULL || view == NULL) - return; - if (h > bi->count) - h = bi->count; - baseoff = bi->baseoff; - if (h < l) - h = l; - cnt = h - l; - view->batInserted = 0; - if (view->ttype != TYPE_void) { - view->tbaseoff = baseoff + l; - } - BATsetcount(view, cnt); - BATsetcapacity(view, cnt); - if (view->tnosorted > l && view->tnosorted < l + cnt) - view->tnosorted -= l; - else - view->tnosorted = 0; - if (view->tnorevsorted > l && view->tnorevsorted < l + cnt) - view->tnorevsorted -= l; - else - view->tnorevsorted = 0; - if (view->tnokey[0] >= l && view->tnokey[0] < l + cnt && - view->tnokey[1] >= l && view->tnokey[1] < l + cnt && - view->tnokey[0] != view->tnokey[1]) { - view->tnokey[0] -= l; - view->tnokey[1] -= l; - } else { - view->tnokey[0] = view->tnokey[1] = 0; - } - if (view->tminpos >= l && view->tminpos < l + cnt) - view->tminpos -= l; - else - view->tminpos = BUN_NONE; - if (view->tmaxpos >= l && view->tmaxpos < l + cnt) - view->tmaxpos -= l; - else - view->tmaxpos = BUN_NONE; - view->tkey |= cnt <= 1; -} -void -VIEWbounds(BAT *b, BAT *view, BUN l, BUN h) -{ - BATiter bi = bat_iterator(b); - VIEWboundsbi(&bi, view, l, h); - bat_iterator_end(&bi); -} - -/* * Destroy a view. */ void diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -834,7 +834,7 @@ COLcopy(BAT *b, int tt, bool writable, r (bi.h == NULL || bi.h->parentid == b->batCacheid || BBP_desc(bi.h->parentid)->batRestricted == BAT_READ)) { - bn = VIEWcreate(b->hseqbase, b); + bn = VIEWcreate(b->hseqbase, b, 0, BUN_MAX); if (bn == NULL) { goto bunins_failed; } diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -1883,10 +1883,9 @@ BATslice(BAT *b, BUN l, BUN h) } if (bi.restricted == BAT_READ && (!VIEWtparent(b) || prestricted == BAT_READ)) { - bn = VIEWcreate(b->hseqbase + low, b); + bn = VIEWcreate(b->hseqbase + low, b, l, h); if (bn == NULL) goto doreturn; - VIEWboundsbi(&bi, bn, l, h); } else { /* create a new BAT and put everything into it */ BUN p = l; diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -282,8 +282,6 @@ gdk_return TMcommit(void) gdk_return unshare_varsized_heap(BAT *b) __attribute__((__warn_unused_result__)) __attribute__((__visibility__("hidden"))); -void VIEWboundsbi(BATiter *bi, BAT *view, BUN l, BUN h) - __attribute__((__visibility__("hidden"))); void VIEWdestroy(BAT *b) __attribute__((__visibility__("hidden"))); BAT *virtualize(BAT *bn) diff --git a/monetdb5/modules/atoms/batxml.c b/monetdb5/modules/atoms/batxml.c --- a/monetdb5/modules/atoms/batxml.c +++ b/monetdb5/modules/atoms/batxml.c @@ -1289,7 +1289,7 @@ BATxmlaggr(BAT **bnp, BAT *b, BAT *g, BA _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org