snapshot v2/p5; remove
This commit is contained in:
parent
128e134b32
commit
cc28920ada
1 changed files with 78 additions and 59 deletions
83
include/sl.h
83
include/sl.h
|
@ -436,35 +436,10 @@
|
||||||
return len; \
|
return len; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* -- __skip_insert_ */ \
|
/* -- __skip_preserve_ \
|
||||||
static int __skip_insert_##decl(decl##_t *slist, decl##_node_t *n, int flags) \
|
* Preserve nodes for snapshots if necessary. Returns > 0 are \
|
||||||
{ \
|
* errors, 0 means nothing preserved, negative number represents \
|
||||||
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
* the number of nodes preserved. \
|
||||||
size_t i, len, level; \
|
|
||||||
decl##_node_t *node, **path = (decl##_node_t **)&apath; \
|
|
||||||
\
|
|
||||||
if (slist == NULL || n == NULL) \
|
|
||||||
return ENOENT; \
|
|
||||||
\
|
|
||||||
/* Allocate a buffer */ \
|
|
||||||
if (SKIPLIST_MAX_HEIGHT == 1) { \
|
|
||||||
path = malloc(sizeof(decl##_node_t *) * slist->max + 1); \
|
|
||||||
if (path == NULL) \
|
|
||||||
return ENOMEM; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
len = __skip_locate_##decl(slist, n, path); \
|
|
||||||
node = path[0]; \
|
|
||||||
if (len > 0) { \
|
|
||||||
if ((node != NULL) && (flags == 0)) { \
|
|
||||||
/* Don't insert, duplicate flag not set. */ \
|
|
||||||
return -1; \
|
|
||||||
} \
|
|
||||||
level = __skip_toss_##decl(slist->max - 1); \
|
|
||||||
n->field.sle.gen = slist->gen; \
|
|
||||||
n->field.sle.height = level; \
|
|
||||||
\
|
|
||||||
/* preserve nodes for snapshots if necessary \
|
|
||||||
* \
|
* \
|
||||||
* ALGORITHM: \
|
* ALGORITHM: \
|
||||||
* Foreach node in `path`, if the generation in that element \
|
* Foreach node in `path`, if the generation in that element \
|
||||||
|
@ -483,11 +458,16 @@
|
||||||
* Meanwhile, don't duplicate head and the tail nodes if they \
|
* Meanwhile, don't duplicate head and the tail nodes if they \
|
||||||
* are in the path[]. \
|
* are in the path[]. \
|
||||||
*/ \
|
*/ \
|
||||||
|
static int __skip_preserve_##decl(decl##_t *slist, decl##_node_t **path, size_t len) \
|
||||||
|
{ \
|
||||||
|
int rc = 0, n = 0; \
|
||||||
|
size_t i; \
|
||||||
|
decl##_node_t *node = path[0]; \
|
||||||
|
\
|
||||||
for (i = 0; i < len; i++) { \
|
for (i = 0; i < len; i++) { \
|
||||||
if (path[i]->field.sle.gen < slist->gen) { \
|
if (path[i]->field.sle.gen < slist->gen) { \
|
||||||
if (path[i] == slist->slh_head || path[i] == slist->slh_tail) \
|
if (path[i] == slist->slh_head || path[i] == slist->slh_tail) \
|
||||||
continue; \
|
continue; \
|
||||||
int rc; \
|
|
||||||
decl##_node_t *src = node, *dest, *this; \
|
decl##_node_t *src = node, *dest, *this; \
|
||||||
size_t amt = sizeof(src); \
|
size_t amt = sizeof(src); \
|
||||||
char *d = NULL; \
|
char *d = NULL; \
|
||||||
|
@ -516,9 +496,43 @@
|
||||||
dest->field.sle.next[0] = slist->slh_pres; \
|
dest->field.sle.next[0] = slist->slh_pres; \
|
||||||
slist->slh_pres = dest; \
|
slist->slh_pres = dest; \
|
||||||
} \
|
} \
|
||||||
|
n++; \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
|
return -n; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
/* -- __skip_insert_ */ \
|
||||||
|
static int __skip_insert_##decl(decl##_t *slist, decl##_node_t *n, int flags) \
|
||||||
|
{ \
|
||||||
|
int rc = 0; \
|
||||||
|
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
||||||
|
size_t i, len, level; \
|
||||||
|
decl##_node_t *node, **path = (decl##_node_t **)&apath; \
|
||||||
|
\
|
||||||
|
if (slist == NULL || n == NULL) \
|
||||||
|
return ENOENT; \
|
||||||
|
\
|
||||||
|
/* Allocate a buffer */ \
|
||||||
|
if (SKIPLIST_MAX_HEIGHT == 1) { \
|
||||||
|
path = malloc(sizeof(decl##_node_t *) * slist->max + 1); \
|
||||||
|
if (path == NULL) \
|
||||||
|
return ENOMEM; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
len = __skip_locate_##decl(slist, n, path); \
|
||||||
|
node = path[0]; \
|
||||||
|
if (len > 0) { \
|
||||||
|
if ((node != NULL) && (flags == 0)) { \
|
||||||
|
/* Don't insert, duplicate flag not set. */ \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
level = __skip_toss_##decl(slist->max - 1); \
|
||||||
|
n->field.sle.gen = slist->gen; \
|
||||||
|
n->field.sle.height = level; \
|
||||||
|
rc = __skip_preserve_##decl(slist, path, len); \
|
||||||
|
if (rc > 0) \
|
||||||
|
return rc; \
|
||||||
for (i = slist->slh_head->field.sle.height + 1; i < n->field.sle.height + 1; i++) { \
|
for (i = slist->slh_head->field.sle.height + 1; i < n->field.sle.height + 1; i++) { \
|
||||||
path[i + 1] = slist->slh_tail; \
|
path[i + 1] = slist->slh_tail; \
|
||||||
} \
|
} \
|
||||||
|
@ -540,7 +554,7 @@
|
||||||
if (SKIPLIST_MAX_HEIGHT == 1) \
|
if (SKIPLIST_MAX_HEIGHT == 1) \
|
||||||
free(path); \
|
free(path); \
|
||||||
} \
|
} \
|
||||||
return 0; \
|
return rc; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* -- skip_insert_ */ \
|
/* -- skip_insert_ */ \
|
||||||
|
@ -784,8 +798,9 @@
|
||||||
/* -- skip_remove_node_ */ \
|
/* -- skip_remove_node_ */ \
|
||||||
int prefix##skip_remove_node_##decl(decl##_t *slist, decl##_node_t *n) \
|
int prefix##skip_remove_node_##decl(decl##_t *slist, decl##_node_t *n) \
|
||||||
{ \
|
{ \
|
||||||
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
int np = 0; \
|
||||||
size_t i, len, level; \
|
size_t i, len, level; \
|
||||||
|
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
||||||
decl##_node_t *node, **path = (decl##_node_t **)&apath; \
|
decl##_node_t *node, **path = (decl##_node_t **)&apath; \
|
||||||
\
|
\
|
||||||
if (slist == NULL || n == NULL) \
|
if (slist == NULL || n == NULL) \
|
||||||
|
@ -803,6 +818,9 @@
|
||||||
len = __skip_locate_##decl(slist, n, path); \
|
len = __skip_locate_##decl(slist, n, path); \
|
||||||
node = path[0]; \
|
node = path[0]; \
|
||||||
if (node) { \
|
if (node) { \
|
||||||
|
np = __skip_preserve_##decl(slist, path, len); \
|
||||||
|
if (np > 0) \
|
||||||
|
return np; \
|
||||||
node->field.sle.next[0]->field.sle.prev = node->field.sle.prev; \
|
node->field.sle.next[0]->field.sle.prev = node->field.sle.prev; \
|
||||||
for (i = 1; i <= len; i++) { \
|
for (i = 1; i <= len; i++) { \
|
||||||
if (path[i]->field.sle.next[i - 1] != node) \
|
if (path[i]->field.sle.next[i - 1] != node) \
|
||||||
|
@ -818,6 +836,7 @@
|
||||||
} \
|
} \
|
||||||
if (SKIPLIST_MAX_HEIGHT == 1) \
|
if (SKIPLIST_MAX_HEIGHT == 1) \
|
||||||
free(path); \
|
free(path); \
|
||||||
|
if (np == 0) \
|
||||||
free_node_blk; \
|
free_node_blk; \
|
||||||
\
|
\
|
||||||
/* Find all levels in the first element in the list that point \
|
/* Find all levels in the first element in the list that point \
|
||||||
|
|
Loading…
Reference in a new issue