MCPcopy Create free account
hub / github.com/antirez/ds4 / raxCompressNodeNoAlloc

Function raxCompressNodeNoAlloc

rax.c:488–512  ·  view source on GitHub ↗

Turn the node 'n', that must be a node without any children, into a * compressed node representing a set of nodes linked one after the other * and having exactly one child each. The node can be a key or not: this * property and the associated value if any will be preserved. * * The function also returns a child node, since the last node of the * compressed chain cannot be part of the chain:

Source from the content-addressed store, hash-verified

486 * compressed chain cannot be part of the chain: it has zero children while
487 * we can only compress inner nodes with exactly one child each. */
488static inline raxNode *raxCompressNodeNoAlloc(raxNode *n, unsigned char *s,
489 size_t len)
490{
491 assert(n->size == 0 && n->iscompr == 0);
492 void *data = NULL; /* Initialized only to avoid warnings. */
493 size_t newsize;
494
495 debugf("Compress node: %.*s\n", (int)len,s);
496
497 /* Make space in the parent node. */
498 newsize = sizeof(raxNode)+len+raxPadding(len)+sizeof(raxNode*);
499 if (n->iskey) {
500 data = raxGetData(n); /* To restore it later. */
501 if (!n->isnull) newsize += sizeof(void*);
502 }
503 raxNode *newn = rax_realloc(n,newsize);
504 if (newn == NULL) return NULL;
505 n = newn;
506
507 n->iscompr = 1;
508 n->size = len;
509 memcpy(n->data,s,len);
510 if (n->iskey) raxSetData(n,data);
511 return n;
512}
513
514raxNode *raxCompressNode(raxNode *n, unsigned char *s, size_t len, raxNode **child) {
515 /* Allocate the child to link to this node. */

Callers 2

raxCompressNodeFunction · 0.85
raxGenericInsertFunction · 0.85

Calls 2

raxGetDataFunction · 0.85
raxSetDataFunction · 0.85

Tested by

no test coverage detected