📄 gdk_align.mx
字号:
bm->dims.tailloc = b->dims.headloc; bm->dims.headkey = b->dims.tailkey; bm->dims.tailkey = b->dims.headkey; bm->dims.headvarsized = b->dims.tailvarsized; bm->dims.tailvarsized = b->dims.headvarsized; bm->dims.bunwidth = b->dims.bunwidth; bm->dims.bunshift = b->dims.bunshift; bm->dims.hseq = b->dims.tseq; bm->dims.tseq = b->dims.hseq; bm->hhash = b->thash; bm->thash = b->hhash; /* set the correct dense info */ if (vid & 1) b->hdense = TRUE; if (vid & 2) b->tdense = TRUE; if (vid == 1) { oid h = b->hseqbase; BUN r = BUNlast(b); if (!b->tvarsized) { for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, p + tlc, newbw); } else if (tt == TYPE_void) { for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, NULL, newbw); } else { char *tbase = th->base; for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, tbase + (*(var_t *) (p + tlc)), newbw); } } else if (vid == 2) { oid t = b->tseqbase; BUN r = BUNlast(b); if (!b->hvarsized) { for (; p < q; p += bunwidth, t++, r += newbw) bunfastins_nocheck(b, r, p + hlc, (ptr) &t, newbw); } else if (ht == TYPE_void) { for (; p < q; p += bunwidth, t++, r += newbw) bunfastins_nocheck(b, r, NULL, (ptr) &t, newbw); } else { char *hbase = hh->base; for (; p < q; p += bunwidth, t++, r += newbw) bunfastins_nocheck(b, r, hbase + (*(var_t *) (p + hlc)), (ptr) &t, newbw); } } else { /* void, void case */ oid h = b->hseqbase; oid t = b->tseqbase; size_t f; BUN r = BUNlast(b); for (f = 0; f < oldsize; f++, h++, t++) bunfastins_nocheck(b, r, (ptr) &h, (ptr) &t, newbw); } ret = b; bunins_failed: /* cleanup the old heaps */ /* if X.priv exists and X not, move it to X (X must be the stable image) */ if (!vv) HEAPfree(&buns); if (committed && buns.storage != STORE_MEM) GDKmove(BATDIR, nme, "buns.priv", BATDIR, nme, "buns"); if (hh) { HEAPfree(hh); if (committed && hh->storage != STORE_MEM) GDKmove(BATDIR, nme, "hheap.priv", BATDIR, nme, "hheap"); GDKfree(hh); } if (th) { HEAPfree(th); if (committed && th->storage != STORE_MEM) GDKmove(BATDIR, nme, "theap.priv", BATDIR, nme, "theap"); GDKfree(th); } } return ret;}/* only materialize the head */BAT *BATmaterializeh(BAT *b, size_t size){ BAT *bm, *ret = NULL; int ht = b->htype, tt = b->ttype; int vv = (!ht && !tt); size_t oldsize = BATcount(b); size_t cnt = MAX(oldsize, size); Heap buns = *b->batBuns, *hh = b->hheap, *th = b->theap; int bunwidth = b->dims.bunwidth, tlc = b->tloc; int newbw = 0; BUN p = BUNfirst(b), q = BUNlast(b); char *nme = BBP_physical(b->batCacheid); int committed = BBP_status(b->batCacheid) & BBPEXISTING; oid h; BUN r; BATcheck(b, "BATmaterialize: bat required"); ALGODEBUG THRprintf(GDKout, "#BATmaterialize(%d," SZFMT ");\n", (int) b->batCacheid, size); if (!BAThdense(b) || ht != TYPE_void) { /* no voids */ return b; } ht = TYPE_oid; /* cleanup possible ACC's */ HASHdestroy(b); /* guess new bunwidth before setting the new dimensions, +3 to allow chr-on-int alignment */ b->batBuns->filename = NULL; if (HEAPalloc(b->batBuns, cnt + 3, 2 * MAX(sizeof(oid), b->dims.bunwidth)) < 0) { *b->batBuns = buns; return NULL; } if (hh) { b->hheap = (Heap*)GDKmalloc(sizeof(Heap)); *b->hheap = *hh; b->hheap->filename = NULL; if (ATOMheap(ht, b->hheap, cnt) < 0) { HEAPfree(b->batBuns); *b->batBuns = buns; b->hheap = hh; return NULL; } } if (th) { b->theap = (Heap*)GDKmalloc(sizeof(Heap)); *b->theap = *th; b->theap->filename = NULL; if (ATOMheap(tt, b->theap, cnt) < 0) { HEAPfree(b->batBuns); HEAPfree(b->hheap); GDKfree(b->hheap); *b->batBuns = buns; b->hheap = hh; b->theap = th; return NULL; } } /* point of no return */ b->htype = ht; b->ttype = tt; BATsetdims(b); DELTAinit(b); newbw = BUNsize(b); b->batDirty = TRUE; b->batDirtydesc = TRUE; b->batDirtybuns = TRUE; bm = BATmirror(b); bm->dims.headtype = b->dims.tailtype; bm->dims.tailtype = b->dims.headtype; bm->dims.headloc = b->dims.tailloc; bm->dims.tailloc = b->dims.headloc; bm->dims.headkey = b->dims.tailkey; bm->dims.tailkey = b->dims.headkey; bm->dims.headvarsized = b->dims.tailvarsized; bm->dims.tailvarsized = b->dims.headvarsized; bm->dims.bunwidth = b->dims.bunwidth; bm->dims.bunshift = b->dims.bunshift; bm->dims.hseq = b->dims.tseq; bm->dims.tseq = b->dims.hseq; bm->hhash = b->thash; bm->thash = b->hhash; /* set the correct dense info */ b->hdense = TRUE; h = b->hseqbase; r = BUNlast(b); if (!b->tvarsized) { for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, p + tlc, newbw); } else if (tt == TYPE_void) { for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, NULL, newbw); } else { char *tbase = th->base; for (; p < q; p += bunwidth, h++, r += newbw) bunfastins_nocheck(b, r, (ptr) &h, tbase + (*(var_t *) (p + tlc)), newbw); } ret = b; bunins_failed: /* cleanup the old heaps */ /* if X.priv exists and X not, move it to X (X must be the stable image) */ if (!vv) HEAPfree(&buns); if (committed && buns.storage != STORE_MEM) GDKmove(BATDIR, nme, "buns.priv", BATDIR, nme, "buns"); if (hh) { HEAPfree(hh); if (committed && hh->storage != STORE_MEM) GDKmove(BATDIR, nme, "hheap.priv", BATDIR, nme, "hheap"); GDKfree(hh); } if (th) { HEAPfree(th); if (committed && th->storage != STORE_MEM) GDKmove(BATDIR, nme, "theap.priv", BATDIR, nme, "theap"); GDKfree(th); } return ret;}/* only materialize the tail */BAT *BATmaterializet(BAT *b, size_t size){ return BATmirror(BATmaterializeh(BATmirror(b), size));}@-The @#VIEWunlink@ routine cuts a reference to the parent. Part of the viewdestroy sequence.@c voidVIEWunlink(BAT *b){ if (b) { BAT *p = BBP_cache(VIEWparent(b)); BAT *m = BATmirror(b); if (p == NULL) return; /* unlink heaps shared with parent */ if (b->hheap && (b->hheap == p->hheap || b->hheap == p->theap)){ b->hheap = m->theap = NULL; } if (b->theap && (b->theap == p->hheap || b->theap == p->theap)){ b->theap = m->hheap = NULL; } /* unlink properties shared with parent */ if (b->H->props && (b->H->props == p->H->props || b->H->props == p->T->props)){ b->H->props = m->T->props = NULL; } if (b->T->props && (b->T->props == p->H->props || b->T->props == p->T->props)){ b->T->props = m->H->props = NULL; } /* unlink hash accelerators shared with parent */ if (b->hhash && (b->hhash == p->hhash || b->hhash == p->thash)){ b->hhash = m->thash = NULL; } if (b->thash && (b->thash == p->hhash || b->thash == p->thash)){ b->thash = m->hhash = NULL; } }}@-Materialize a view into a normal BAT. If it is a slice, we reallywant to reduce storage of the new BAT.@cBAT *VIEWreset(BAT *b){ bat parent = VIEWparent(b); if (b && parent) { Heap buns, hh, th; BAT *n = ((b) = BBP_cache(ABS((b)->batCacheid))); BAT *m = BATmirror(n); BAT *v; BATstore *bs = (BATstore *) n; var_t cnt = BATcount(b); int ht = (n->htype == TYPE_void && n->ttype == TYPE_void) ? TYPE_oid : n->htype; str nme = BBP_physical(n->batCacheid); /* alloc heaps */ memset(&buns, 0, sizeof(Heap)); buns.filename = (str) GDKmalloc(strlen(nme) + 12); sprintf(buns.filename, "%s.buns", nme); if (HEAPalloc(&buns, cnt + 1, BUNsize(n)) < 0) { GDKfree(buns.filename); buns.filename = NULL; return NULL; } memset(&hh, 0, sizeof(Heap)); if (n->hheap) { hh.filename = (str) GDKmalloc(strlen(nme) + 12); sprintf(hh.filename, "%s.hheap", nme); if (ATOMheap(ht, &hh, cnt) < 0) { HEAPfree(&buns); GDKfree(hh.filename); return NULL; } } memset(&th, 0, sizeof(Heap)); if (n->theap) { th.filename = (str) GDKmalloc(strlen(nme) + 12); sprintf(th.filename, "%s.theap", nme); if (ATOMheap(n->ttype, &th, cnt) < 0) { HEAPfree(&buns); HEAPfree(&hh); GDKfree(th.filename); return NULL; } } v = VIEWcreate(b); /* cut the link to your parents */ VIEWunlink(n); BBPunshare(parent); n->batParentid = 0; n->batRestricted = BAT_WRITE; /* make sure everything points there */ m->U = n->U = &(bs->U); m->P = n->P = &(bs->P); m->T = n->H = &(bs->H); m->H = n->T = &(bs->T); n->batBuns = m->batBuns = &n->U->buns; n->GDKversion = m->GDKversion = GDKLIBRARY; /* copy the heaps */ *n->batBuns = buns; /* unshare from parents heap */ if (hh.base) { n->hheap = (Heap*)GDKmalloc(sizeof(Heap)); *n->hheap = hh; } if (th.base) { n->theap = (Heap*)GDKmalloc(sizeof(Heap)); *n->theap = th; } /* modify dimensions to let disappear projected out columns */ m->ttype = n->htype = ht; BATsetdims(n); m->dims.tailtype = n->dims.headtype; m->dims.headtype = n->dims.tailtype; m->dims.tailloc = n->dims.headloc; m->dims.headloc = n->dims.tailloc; m->dims.tailvarsized = n->dims.headvarsized; m->dims.headvarsized = n->dims.tailvarsized; m->dims.bunshift = n->dims.bunshift; m->dims.bunwidth = n->dims.bunwidth; m->dims.hseq = n->dims.tseq; m->dims.tseq = n->dims.hseq; n->batSharecnt = 0; n->batCopiedtodisk = 0; n->batDirty = 1; /* make the BAT empty and insert all again */ DELTAinit(n); /* insert all of v in b, and quit */ BATins(b, v, FALSE); BBPreclaim(v); } return b;}@-The remainder are utilities to manipulate the BAT view andnot to forget some details in the process.It expects a position range in the underlying BAT andcompensates for outliers.@cvoidVIEWbounds(BAT *view, size_t l, size_t h){ bat bid = VIEWparent(view); BAT *b = BBP_cache(bid); if (view == NULL || bid == 0) { GDKerror("VIEWbounds: bat required"); return; } if (l < BUNindex(b, BUNfirst(b))) l = BUNindex(b, BUNfirst(b)); view->batBuns->base = BUNptr(b, l); view->batFirst = view->batDeleted = view->batInserted = view->batBuns->base; if (BUNlast(b) < BUNptr(b, h + 1)) h = BUNindex(b, BUNlast(b))-1; view->batBuns->maxsize = view->batBuns->size = view->batBuns->free = BUNptr(b, h + 1) - view->batBuns->base; BATsetcount(view, h + 1 - l); view->hsorted = BAThordered(b); view->tsorted = BATtordered(b); BATkey(view, BAThkey(b)); BATkey(BATmirror(view), BATtkey(b)); if (BAThdense(b)) { BATseqbase(view, b->hseqbase + l); } if (BATtdense(b)) { BATseqbase(BATmirror(view), b->tseqbase + l); }}@-Destroy a view.@cvoidVIEWdestroy(BAT *b){ VIEWunlink(b); b->batBuns->base = NULL; b->batBuns->filename = NULL; b->hheap = NULL; b->theap = NULL; BATfree(b);}@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -