Arraylist allGraphs(int rank) { Arraylist result = newArraylist(rank); Intstack cand = newIntstack(0, NULL), fg = fullgraph(rank); unsigned long int x, y, ulim = 1 << fg->size; int i; setRank(rank); for (x = 0L; x < ulim; x++) { cand->size = 0; y = x; i = 0; while (y > 0) { if (y % 2 == 1) putint(fg->it[i], cand); y /= 2; i++; } if (portHistDescending(cand)) { putItem((void*) newIntstack(0, cand), result); } } freestack(cand); freestack(fg); sortAndWeedForGraphs(rank, result); return result; }
int main6(int argc, char *argv[]) { Intstack cell, co; int rank, upb, nr = 0; assert(argc > 1); rank = atoi(argv[1]); upb = 1 << rank; co = newIntstack(upb, NULL); cell = readCell(); while (cell) { nr = getCnr(); printCell(nr, cell); complement(upb, cell, co); printf("COM "); printCell(0, co); freestack(cell); printf("\n"); cell = readCell(); } freestack(cell); freestack(co); #if 0 reportTime(); reportCnt(); #endif finalizeScanner(); return 0; }
void luaE_freethread (lua_State *L, lua_State *L1) { luaF_close(L1, L1->stack); /* close all upvalues for this thread */ lua_assert(L1->openupval == NULL); luai_userstatefree(L1); freestack(L, L1); luaM_freemem(L, fromstate(L1), state_size(lua_State)); }
static void close_state (lua_State *L) { global_State globalState; lua_State luaState; luaF_close(L, L->stack); /* close all upvalues for this thread */ luaState.l_G = &globalState; globalState.reallocFunc = G(L)->reallocFunc; globalState.freeFunc = G(L)->freeFunc; globalState.memData = G(L)->memData; if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ #if !LUA_REFCOUNT lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); #endif LUA_REFCOUNT luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { //jj This check doesn't work anymore, because LuaState variables are allocated through the //jj memory interface, too. //jj lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(&luaState, G(L)); } freestate(&luaState, L); }
Datum rtrestrpos(PG_FUNCTION_ARGS) { IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0); RTreeScanOpaque p; RTSTACK *o, *n, *tmp; s->currentItemData = s->currentMarkData; p = (RTreeScanOpaque) s->opaque; if (p->s_flags & RTS_MRKBEFORE) p->s_flags |= RTS_CURBEFORE; else p->s_flags &= ~RTS_CURBEFORE; o = (RTSTACK *) NULL; n = p->s_markstk; /* copy the parent stack from the current item data */ while (n != (RTSTACK *) NULL) { tmp = (RTSTACK *) palloc(sizeof(RTSTACK)); tmp->rts_child = n->rts_child; tmp->rts_blk = n->rts_blk; tmp->rts_parent = o; o = tmp; n = n->rts_parent; } freestack(p->s_stack); p->s_stack = o; PG_RETURN_VOID(); }
void LUAE_freethread (LUA_State *L, LUA_State *L1) { LX *l = fromstate(L1); LUAF_close(L1, L1->stack); /* close all upvalues for this thread */ LUA_assert(L1->openupval == NULL); LUAi_userstatefree(L, L1); freestack(L1); LUAM_free(L, l); }
void killaE_freethread (killa_State *L, killa_State *L1) { LX *l = fromstate(L1); killaF_close(L1, L1->stack); /* close all upvalues for this thread */ killa_assert(L1->openupval == NULL); killai_userstatefree(L, L1); freestack(L1); killaM_free(L, l); }
static void close_state (killa_State *L) { killa_GlobalState *g = KILLA_G(L); killaF_close(L, L->stack); /* close all upvalues for this thread */ killaC_freeallobjects(L); /* collect all objects */ killaM_freearray(L, KILLA_G(L)->strt.hash, KILLA_G(L)->strt.size); killaZ_freebuffer(L, &g->buff); freestack(L); killa_assert(killa_gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ }
Intstack firstVariant(int rank, Intstack cell) { Intstack pe = somePHDvariant(rank, cell) ; Arraylist ar = rawPermVariants(rank, pe) ; int i; freestack(pe) ; pe = ar->it[0]; for (i = 1; i < ar->size; i++) { if (compareL(ar->it[i], pe) < 0) { freestack(pe) ; pe = ar->it[i]; } else { freestack(ar->it[i]) ; } } freeArraylist(ar) ; return pe; }
static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_freeallobjects(L); /* collect all objects */ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); luaZ_freebuffer(L, &g->buff); freestack(L); lua_assert(gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ }
static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_freeallobjects(L); /* collect all objects */ if (g->version) /* closing a fully built state? */ luai_userstateclose(L); luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); freestack(L); lua_assert(gettotalbytes(g) == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ }
Datum rtendscan(PG_FUNCTION_ARGS) { IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0); RTreeScanOpaque p; p = (RTreeScanOpaque) s->opaque; if (p != (RTreeScanOpaque) NULL) { freestack(p->s_stack); freestack(p->s_markstk); pfree(s->opaque); } rtdropscan(s); /* XXX don't unset read lock -- two-phase locking */ PG_RETURN_VOID(); }
static void close_state (lua_State *L) { global_State *g = G(L); luaF_close(L, L->stack); /* close all upvalues for this thread */ luaC_freeall(L); /* collect all objects */ lua_assert(g->rootgc == obj2gco(L)); lua_assert(g->strt.nuse == 0); luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); luaZ_freebuffer(L, &g->buff); freestack(L, L); lua_assert(g->totalbytes == sizeof(LG)); (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); }
Arraylist allMatchedGraphs(int rank) { Arraylist ar = allGraphs(rank); int i; for (i = 0; i < ar->size; i++) { if (! matched(rank, ar->it[i])) { freestack(ar->it[i]); ar->it[i] = NULL; } } removeNulls(ar); return ar; }
Arraylist allVariants(int rank, Intstack cell) { Arraylist ar, result = permVariants(rank, cell) ; Intstack cen = centers(cell), ce0, ce1; int i; for (i = 1; i < cen->size; i++) { ce0 = newIntstack(0, cell) ; translate(cen->it[i], ce0) ; ce1 = somePHDvariant(rank, ce0) ; if (!memberAr(ce1, result, (int(*)(const void*, const void*)) compareL)) { #if 0 printf("Variant occurs.\n"); #endif ar = permVariants(rank, ce1) ; mergeAr(result, ar, (int(*)(const void*, const void*)) compareL) ; } freestack(ce1) ; } freestack(cen) ; return result; }
Intstack somePHDvariant(int rank, Intstack cell) { /* Pre: cell is centered. * Permute cell such that it becomes portHistDescending. * The cell is destroyed. */ int hh[RANKLIM]; Intstack pe = below(rank), pg = newIntstack(rank, NULL) ; int i, p, j, q; setRank(rank) ; portHisto(cell, hh) ; /* insertion sort of hh, invariant: hh[0..i) is sorted */ i = 1; while (i < rank) { j = i; p = hh[i]; q = pe->it[i]; i++; while (j > 0 && hh[j-1] < p) { hh[j] = hh[j-1]; pe->it[j] = pe->it[j-1]; j--; } hh[j] = p; pe->it[j] = q; } pg->size = rank; p = 1; for (i = 0; i < rank; i++) { pg->it[pe->it[i]] = p; p <<= 1; } freestack(pe) ; pe = permuteCell(cell, pg) ; freestack(pg) ; freestack(cell) ; return pe; }
Arraylist rawPermVariants(int rank, Intstack cell) { int i, h[RANKLIM]; Arraylist perms; Arraylist result; portHisto(cell, h) ; perms = specPerm(rank, h) ; result = newArraylist(perms->size) ; for (i = 0; i < perms->size; i++) { putItem(permuteCell(cell, perms->it[i]), result) ; freestack(perms->it[i]) ; } freeArraylist(perms) ; return result; }
static void close_state (lua_State *L) { luaF_close(L, L->stack); /* close all upvalues for this thread */ if (G(L)) { /* close global state */ luaC_sweep(L, 1); /* collect all elements */ lua_assert(G(L)->rootgc == NULL); lua_assert(G(L)->rootudata == NULL); luaS_freeall(L); luaZ_freebuffer(L, &G(L)->buff); } freestack(L, L); if (G(L)) { lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); luaM_freelem(NULL, G(L)); } freestate(NULL, L); }
void luaE_freethread (lua_State *L, lua_State *L1) { luaF_close(L1, L1->stack); /* close all upvalues for this thread */ lua_assert(L1->openupval == NULL); freestack(L, L1); freestate(L, L1); }
Datum rtrescan(PG_FUNCTION_ARGS) { IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0); ScanKey key = (ScanKey) PG_GETARG_POINTER(1); RTreeScanOpaque p; RegProcedure internal_proc; int i; /* * Clear all the pointers. */ ItemPointerSetInvalid(&s->currentItemData); ItemPointerSetInvalid(&s->currentMarkData); p = (RTreeScanOpaque) s->opaque; if (p != (RTreeScanOpaque) NULL) { /* rescan an existing indexscan --- reset state */ freestack(p->s_stack); freestack(p->s_markstk); p->s_stack = p->s_markstk = (RTSTACK *) NULL; p->s_flags = 0x0; } else { /* initialize opaque data */ p = (RTreeScanOpaque) palloc(sizeof(RTreeScanOpaqueData)); p->s_stack = p->s_markstk = (RTSTACK *) NULL; p->s_internalNKey = s->numberOfKeys; p->s_flags = 0x0; s->opaque = p; if (s->numberOfKeys > 0) p->s_internalKey = (ScanKey) palloc(sizeof(ScanKeyData) * s->numberOfKeys); } /* Update scan key, if a new one is given */ if (key && s->numberOfKeys > 0) { memmove(s->keyData, key, s->numberOfKeys * sizeof(ScanKeyData)); /* * Scans on internal pages use different operators than they do on * leaf pages. For example, if the user wants all boxes that * exactly match (x1,y1,x2,y2), then on internal pages we need to * find all boxes that contain (x1,y1,x2,y2). */ for (i = 0; i < s->numberOfKeys; i++) { internal_proc = RTMapOperator(s->indexRelation, s->keyData[i].sk_attno, s->keyData[i].sk_procedure); ScanKeyEntryInitialize(&(p->s_internalKey[i]), s->keyData[i].sk_flags, s->keyData[i].sk_attno, internal_proc, s->keyData[i].sk_argument); } } PG_RETURN_VOID(); }
static void rtdoinsert(Relation r, IndexTuple itup, RTSTATE *rtstate) { Page page; Buffer buffer; BlockNumber blk; IndexTuple which; OffsetNumber l; RTSTACK *stack; RTreePageOpaque opaque; Datum datum; blk = P_ROOT; buffer = InvalidBuffer; stack = NULL; do { /* release the current buffer, read in the next one */ buffer = ReleaseAndReadBuffer(buffer, r, blk); page = (Page) BufferGetPage(buffer); opaque = (RTreePageOpaque) PageGetSpecialPointer(page); if (!(opaque->flags & F_LEAF)) { RTSTACK *n; ItemId iid; n = (RTSTACK *) palloc(sizeof(RTSTACK)); n->rts_parent = stack; n->rts_blk = blk; n->rts_child = choose(r, page, itup, rtstate); stack = n; iid = PageGetItemId(page, n->rts_child); which = (IndexTuple) PageGetItem(page, iid); blk = ItemPointerGetBlockNumber(&(which->t_tid)); } } while (!(opaque->flags & F_LEAF)); if (nospace(page, itup)) { /* need to do a split */ rtdosplit(r, buffer, stack, itup, rtstate); freestack(stack); WriteBuffer(buffer); /* don't forget to release buffer! */ return; } /* add the item and write the buffer */ if (PageIsEmpty(page)) { l = PageAddItem(page, (Item) itup, IndexTupleSize(itup), FirstOffsetNumber, LP_USED); } else { l = PageAddItem(page, (Item) itup, IndexTupleSize(itup), OffsetNumberNext(PageGetMaxOffsetNumber(page)), LP_USED); } if (l == InvalidOffsetNumber) elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(r)); WriteBuffer(buffer); datum = IndexTupleGetDatum(itup); /* now expand the page boundary in the parent to include the new child */ rttighten(r, stack, datum, IndexTupleAttSize(itup), rtstate); freestack(stack); }
int matched(int rank, Intstack gr) { Intstack grc = newIntstack(0, gr); int r = matchedR((1 << rank) - 1, grc); freestack(grc); return r; }