void Trie_Put(TTrie *hTrie, unsigned long key, unsigned long value) { LOG("[%s():%d] key=%08X value=%d\n", __func__, __LINE__, key, value); assert(hTrie->isDead == false); TNode *root = hTrie->root; const unsigned int dir = key & 0x1; if (root->childNode[dir] == NULL) { LOG(" [%s():%d] create root child[dir=%d]\n", __func__, __LINE__, dir); root->childNode[dir] = CreateChildNode(key, value, KEY_LEN); root->nChild++; return; } PutNode(root, root->childNode[dir], key, value, KEY_LEN); }
/* get the frame from the existing cache, return NULL if it is missing */ bool LFUCache::GetNode(int frameid, int& result) { /* if hit some node*/ if (LFUHash.find(frameid)!=LFUHash.end()) { /* update the cache */ LFUListNode* listnode = LFUHash[frameid]; /* hit LFU list node */ UpdateNode(listnode); result = listnode->Value; return true; } /* if not hit any node */ else { PutNode(frameid, DB[frameid][VALUE]); return false; } }
static void PutNode(TNode *parentNode, TNode *node, const unsigned long key, const unsigned long value, const unsigned short len) { LOG(" [%s():%d] key=%08X(len=%d) val=%d\n", __func__, __LINE__, key, len, value); if ((len == 1) || (key == node->label)) { /* replace */ node->label = key; node->value = value; return; } const unsigned long filter = 0xffffffff >> (KEY_LEN - node->labellen); const unsigned long diff = (key & filter) ^ node->label; if (diff) { ForkNode(parentNode, node, key, value, len, diff); TNode *pnode = parentNode->childNode[key&0x1]; LOG(" [%s():%d] pnode:%08X, cnode1:%08X, cnode2:%08X\n", __func__, __LINE__, (unsigned int)pnode, (unsigned int)pnode->childNode[0], (unsigned int)pnode->childNode[1]); return; } const unsigned long nextKey = key >> node->labellen; const unsigned int dir = nextKey & 0x1; PutNode(node, node->childNode[dir], nextKey, value, (len - node->labellen)); }
int LibSixel_LSImageToSixel(sixel_image_t *im, sixel_output_t *context) { int x, y, i, n, c; int maxPalet; int width, height; int len, pix, skip; int back = (-1); int ret; unsigned char *map; sixel_node_t *np; unsigned char list[SIXEL_PALETTE_MAX]; char buf[256]; int nwrite; width = im->sx; height = im->sy; context->pos = 0; maxPalet = im->dither->ncolors; if (maxPalet < 1) { return (-1); } back = im->dither->keycolor; len = maxPalet * width; context->active_palette = (-1); #if HAVE_CALLOC if ((map = (unsigned char *)calloc(len, sizeof(unsigned char))) == NULL) { return (-1); } #else if ((map = (unsigned char *)malloc(len)) == NULL) { return (-1); } memset(map, 0, len); #endif for (n = 0; n < maxPalet; n++) { context->conv_palette[n] = list[n] = n; } if (context->has_8bit_control) { nwrite = sprintf((char *)context->buffer, "\x90" "0;0;0" "q"); } else { nwrite = sprintf((char *)context->buffer, "\x1bP" "0;0;0" "q"); } if (nwrite <= 0) { return (-1); } advance(context, nwrite); nwrite = sprintf((char *)context->buffer + context->pos, "\"1;1;%d;%d", width, height); if (nwrite <= 0) { return (-1); } advance(context, nwrite); if (maxPalet != 2 || back == -1) { for (n = 0; n < maxPalet; n++) { /* DECGCI Graphics Color Introducer # Pc ; Pu; Px; Py; Pz */ nwrite = sprintf((char *)context->buffer + context->pos, "#%d;2;%d;%d;%d", context->conv_palette[n], (im->dither->palette[n * 3 + 0] * 100 + 127) / 255, (im->dither->palette[n * 3 + 1] * 100 + 127) / 255, (im->dither->palette[n * 3 + 2] * 100 + 127) / 255); if (nwrite <= 0) { return (-1); } advance(context, nwrite); if (nwrite <= 0) { return (-1); } } context->buffer[context->pos] = '\n'; advance(context, 1); } for (y = i = 0; y < height; y++) { for (x = 0; x < width; x++) { pix = im->pixels[y * width + x]; if (pix >= 0 && pix < maxPalet && pix != back) { map[pix * width + x] |= (1 << i); } } if (++i < 6 && (y + 1) < height) { continue; } for (n = 0; n < maxPalet; n++) { ret = NodeLine(context, n, width, map + n * width); if (ret != 0) { return ret; } } for (x = 0; (np = context->node_top) != NULL;) { if (x > np->sx) { /* DECGCR Graphics Carriage Return */ context->buffer[context->pos] = '$'; advance(context, 1); x = 0; } x = PutNode(context, im, x, np, maxPalet, back); NodeDel(context, np); np = context->node_top; while (np != NULL) { if (np->sx < x) { np = np->next; continue; } x = PutNode(context, im, x, np, maxPalet, back); NodeDel(context, np); np = context->node_top; } } /* DECGNL Graphics Next Line */ context->buffer[context->pos] = '-'; advance(context, 1); if (nwrite <= 0) { return (-1); } i = 0; memset(map, 0, len); } if (context->has_8bit_control) { context->buffer[context->pos] = '\x9c'; advance(context, 1); } else { context->buffer[context->pos] = '\x1b'; context->buffer[context->pos + 1] = '\\'; advance(context, 2); } if (nwrite <= 0) { return (-1); } /* flush buffer */ if (context->pos > 0) { context->fn_write((char *)context->buffer, context->pos, context->priv); } NodeFree(context); free(map); return 0; }
static void Split(RSTREE R, typentry *newentry, int *depth, int M, int m) { refparameters par; refcount c; int pagenr; boolean isdata; int i; par= &(*R).parameters._; if (*depth == (*par).height) { if (M == 1) { UnDistributData(R,&(*newentry).DATA); } else { SplitAndDistributData(R,*depth,&(*newentry).DATA,M,m); } } else { SplitAndDistributDir(R,*depth,&(*newentry).DIR,M,m); } if (*depth == 1) { (*par).height++; *depth= 2; for (i= (*par).height; i >= 2; i--) { (*R).N[i]= (*R).N[i-1]; (*R).NDel[i]= (*R).NDel[i-1]; /* for ReInsert */ (*R).ReInsert[i]= (*R).ReInsert[i-1]; /* for ReInsert */ /* following assignments not necessary for i=2: */ (*R).P[i]= (*R).P[i-1]; /* set(i=2) */ (*R).Nmodified[i]= (*R).Nmodified[i-1]; /* set(i=2) */ (*par).pagecountarr[i]= (*par).pagecountarr[i-1]; } (*R).N[1]= (refnode)malloc((*R).dirnodelen); /* R->P[1] is RSTBase.rootblocknumb forever */ /* R->Nmodified[1] set inserting the sibling */ (*R).NDel[1]= NULL; /* for ReInsert */ (*R).ReInsert[1]= FALSE; /* for ReInsert */ /* initiate first root entry: */ (*(*R).N[1]).DIR.nofentries= 1; (*R).E[1]= 0; GetPageNr(R,&pagenr,*depth); (*(*R).N[1]).DIR.entries[0].ptrtosub= pagenr; (*R).P[2]= pagenr; } isdata= *depth == (*par).height; (*R).Nmodified[*depth]= TRUE; GetPageNr(R,&pagenr,*depth); (*newentry).DIR.ptrtosub= pagenr; if (isdata) { EvalDataEnclRect(R,&(*(*R).Nsibling).DATA,(*newentry).DIR.rect); EvalDataEnclRect(R,&(*(*R).N[*depth]).DATA, (*(*R).N[*depth-1]).DIR.entries[(*R).E[*depth-1]].rect); c= &(*R).count; if ((*c).countflag) { (*c).datamodifycount+= 2; } } else { EvalDirEnclRect(R,&(*(*R).Nsibling).DIR,(*newentry).DIR.rect); EvalDirEnclRect(R,&(*(*R).N[*depth]).DIR, (*(*R).N[*depth-1]).DIR.entries[(*R).E[*depth-1]].rect); c= &(*R).count; if ((*c).countflag) { (*c).dirmodifycount+= 2; } } PutNode(R,(*R).Nsibling,pagenr,*depth); (*depth)--; }