uniq_skiplist_grow set prev link correctly

pull/37/head
YuQing 2020-04-27 14:16:00 +08:00
parent e4a5cadfe1
commit 73dba84e82
2 changed files with 13 additions and 5 deletions

View File

@ -228,15 +228,18 @@ static void test_reverse_iterator()
{ {
UniqSkiplistNode *node; UniqSkiplistNode *node;
int v; int v;
int count;
int *value; int *value;
v = 21; printf("test_reverse_iterator\n");
count = 0;
v = 2;
node = uniq_skiplist_find_ge_node(sl, &v); node = uniq_skiplist_find_ge_node(sl, &v);
if (node != NULL) { if (node != NULL) {
while (node != sl->top) { while (node != sl->top) {
value = (int *)node->data; value = (int *)node->data;
printf("value: %d\n", *value); printf("value[%d]: %d\n", count++, *value);
node = (UniqSkiplistNode *)LEVEL0_DOUBLE_CHAIN_PREV_LINK(node); node = UNIQ_SKIPLIST_LEVEL0_PREV_NODE(node);
} }
} }
} }

View File

@ -236,8 +236,13 @@ static int uniq_skiplist_grow(UniqSkiplist *sl)
sl->top_level_index = top_level_index; sl->top_level_index = top_level_index;
if (sl->factory->bidirection) { if (sl->factory->bidirection) {
LEVEL0_DOUBLE_CHAIN_TAIL(sl) = if (top->links[0] != sl->factory->tail) { //not empty
LEVEL0_DOUBLE_CHAIN_PREV_LINK(old_top); LEVEL0_DOUBLE_CHAIN_PREV_LINK(top->links[0]) = top;
LEVEL0_DOUBLE_CHAIN_TAIL(sl) =
LEVEL0_DOUBLE_CHAIN_PREV_LINK(old_top);
} else {
LEVEL0_DOUBLE_CHAIN_TAIL(sl) = sl->top;
}
} }
UNIQ_SKIPLIST_FREE_MBLOCK_OBJECT(sl, old_top_level_index, old_top); UNIQ_SKIPLIST_FREE_MBLOCK_OBJECT(sl, old_top_level_index, old_top);