snapshot v2/p5; remove

This commit is contained in:
Gregory Burd 2024-03-23 11:47:11 -04:00
parent 128e134b32
commit cc28920ada

View file

@ -436,35 +436,10 @@
return len; \
} \
\
/* -- __skip_insert_ */ \
static int __skip_insert_##decl(decl##_t *slist, decl##_node_t *n, int flags) \
{ \
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; \
\
/* preserve nodes for snapshots if necessary \
/* -- __skip_preserve_ \
* Preserve nodes for snapshots if necessary. Returns > 0 are \
* errors, 0 means nothing preserved, negative number represents \
* the number of nodes preserved. \
* \
* ALGORITHM: \
* 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 \
* 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++) { \
if (path[i]->field.sle.gen < slist->gen) { \
if (path[i] == slist->slh_head || path[i] == slist->slh_tail) \
continue; \
int rc; \
decl##_node_t *src = node, *dest, *this; \
size_t amt = sizeof(src); \
char *d = NULL; \
@ -516,9 +496,43 @@
dest->field.sle.next[0] = slist->slh_pres; \
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++) { \
path[i + 1] = slist->slh_tail; \
} \
@ -540,7 +554,7 @@
if (SKIPLIST_MAX_HEIGHT == 1) \
free(path); \
} \
return 0; \
return rc; \
} \
\
/* -- skip_insert_ */ \
@ -784,8 +798,9 @@
/* -- skip_remove_node_ */ \
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; \
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
decl##_node_t *node, **path = (decl##_node_t **)&apath; \
\
if (slist == NULL || n == NULL) \
@ -803,6 +818,9 @@
len = __skip_locate_##decl(slist, n, path); \
node = path[0]; \
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; \
for (i = 1; i <= len; i++) { \
if (path[i]->field.sle.next[i - 1] != node) \
@ -818,6 +836,7 @@
} \
if (SKIPLIST_MAX_HEIGHT == 1) \
free(path); \
if (np == 0) \
free_node_blk; \
\
/* Find all levels in the first element in the list that point \