Unverified Commit cf1d49ad authored by ZhaolongLi's avatar ZhaolongLi Committed by GitHub
Browse files

Simplify logic in raxSeek, eliminate it->key reassembly on gt and lt (#9115)



In the original version, the operation of traversing the stack only seems to
reconstruct the key that does not contain the current node.

But in fact We have got the matched length and splitpos in the key in the
raxlowwalk, so I think we can simplify the logic of this part.
Co-authored-by: default avatarlizhaolong.lzl <lizhaolong.lzl@B-54MPMD6R-0221.local>
parent 5d8ea4b3
...@@ -1576,30 +1576,8 @@ int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len) { ...@@ -1576,30 +1576,8 @@ int raxSeek(raxIterator *it, const char *op, unsigned char *ele, size_t len) {
} else if (lt || gt) { } else if (lt || gt) {
/* Exact key not found or eq flag not set. We have to set as current /* Exact key not found or eq flag not set. We have to set as current
* key the one represented by the node we stopped at, and perform * key the one represented by the node we stopped at, and perform
* a next/prev operation to seek. To reconstruct the key at this node * a next/prev operation to seek. */
* we start from the parent and go to the current node, accumulating raxIteratorAddChars(it, ele, i-splitpos);
* the characters found along the way. */
if (!raxStackPush(&it->stack,it->node)) return 0;
for (size_t j = 1; j < it->stack.items; j++) {
raxNode *parent = it->stack.stack[j-1];
raxNode *child = it->stack.stack[j];
if (parent->iscompr) {
if (!raxIteratorAddChars(it,parent->data,parent->size))
return 0;
} else {
raxNode **cp = raxNodeFirstChildPtr(parent);
unsigned char *p = parent->data;
while(1) {
raxNode *aux;
memcpy(&aux,cp,sizeof(aux));
if (aux == child) break;
cp++;
p++;
}
if (!raxIteratorAddChars(it,p,1)) return 0;
}
}
raxStackPop(&it->stack);
/* We need to set the iterator in the correct state to call next/prev /* We need to set the iterator in the correct state to call next/prev
* step in order to seek the desired element. */ * step in order to seek the desired element. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment