pos gt/lt working; added dup put kv api

This commit is contained in:
Gregory Burd 2024-03-21 17:34:34 -04:00
parent 307d817ee0
commit 744acee09a
2 changed files with 40 additions and 15 deletions

View file

@ -203,6 +203,8 @@ main()
char *v = api_skip_get_slex(list, array[i]);
api_skip_set_slex(list, array[i], to_upper(v));
}
api_skip_dup_slex(list, -1, int_to_roman_numeral(-1));
api_skip_dup_slex(list, 1, int_to_roman_numeral(1));
api_skip_del_slex(list, 0);
@ -213,13 +215,25 @@ main()
api_skip_destroy_slex(restored);
#endif
assert(strcmp(api_skip_pos_slex(list, SKIP_GTE, -(TEST_ARRAY_SIZE) -1)->value, int_to_roman_numeral(-(TEST_ARRAY_SIZE))) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GTE, -(TEST_ARRAY_SIZE)-1)->value, int_to_roman_numeral(-(TEST_ARRAY_SIZE))) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GTE, -2)->value, int_to_roman_numeral(-2)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GTE, 0)->value, int_to_roman_numeral(1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GTE, 2)->value, int_to_roman_numeral(2)) == 0);
assert(api_skip_pos_slex(list, SKIP_GTE, (TEST_ARRAY_SIZE + 1)) == NULL);
assert(api_skip_pos_slex(list, SKIP_LTE, -(TEST_ARRAY_SIZE) - 1) == NULL);
assert(strcmp(api_skip_pos_slex(list, SKIP_GT, -(TEST_ARRAY_SIZE)-1)->value, int_to_roman_numeral(-(TEST_ARRAY_SIZE))) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GT, -2)->value, int_to_roman_numeral(-1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GT, 0)->value, int_to_roman_numeral(1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_GT, 1)->value, int_to_roman_numeral(2)) == 0);
assert(api_skip_pos_slex(list, SKIP_GT, TEST_ARRAY_SIZE) == NULL);
assert(api_skip_pos_slex(list, SKIP_LT, -(TEST_ARRAY_SIZE)) == NULL);
assert(strcmp(api_skip_pos_slex(list, SKIP_LT, -1)->value, int_to_roman_numeral(-2)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_LT, 0)->value, int_to_roman_numeral(-1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_LT, 2)->value, int_to_roman_numeral(1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_LT, (TEST_ARRAY_SIZE + 1))->value, int_to_roman_numeral(TEST_ARRAY_SIZE)) == 0);
assert(api_skip_pos_slex(list, SKIP_LTE, -(TEST_ARRAY_SIZE)-1) == NULL);
assert(strcmp(api_skip_pos_slex(list, SKIP_LTE, -2)->value, int_to_roman_numeral(-2)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_LTE, 0)->value, int_to_roman_numeral(-1)) == 0);
assert(strcmp(api_skip_pos_slex(list, SKIP_LTE, 2)->value, int_to_roman_numeral(2)) == 0);

View file

@ -483,7 +483,7 @@
return elm; \
} \
\
/* -- skip_position_gt TODO \
/* -- skip_position_gt_ \
* Position and return a cursor at the first node that is greater than \
* the provided node `n`. If the largestkey is less than the key in `n` \
* return NULL. \
@ -509,7 +509,7 @@
do { \
elm = elm->field.sle.next[0]; \
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
} while (cmp < 0); \
} while (cmp <= 0); \
return elm; \
} \
\
@ -543,12 +543,12 @@
do { \
elm = elm->field.sle.prev; \
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
} while (cmp > 0); \
} while (cmp >= 0); \
} \
return elm; \
} \
\
/* -- skip_position_lt TODO \
/* -- skip_position_lt_ \
* Position and return a cursor at the last node that is less than \
* to the node `n`. Return NULL if nothing is less than or equal. \
* \
@ -571,14 +571,10 @@
elm = elm->field.sle.next[i]; \
} while (i--); \
elm = elm->field.sle.next[0]; \
if (__skip_key_compare_##decl(slist, elm, n, slist->aux) == 0) { \
return elm; \
} else { \
do { \
elm = elm->field.sle.prev; \
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
} while (cmp > 0); \
} \
do { \
elm = elm->field.sle.prev; \
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
} while (cmp >= 0); \
return elm; \
} \
\
@ -634,7 +630,7 @@
return -1; \
} \
\
/* -- skip_remove_ */ \
/* -- skip_remove_ BUG: prev pointer wrong!*/ \
int prefix##skip_remove_##decl(decl##_t *slist, decl##_node_t *n) \
{ \
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
@ -967,6 +963,21 @@
return rc; \
} \
\
int prefix##skip_dup_##decl(decl##_t *slist, ktype key, vtype value) \
{ \
int rc; \
decl##_node_t *node; \
rc = prefix##skip_alloc_node_##decl(slist, &node); \
if (rc) \
return rc; \
node->key = key; \
node->value = value; \
rc = prefix##skip_insert_dup_##decl(slist, node); \
if (rc) \
prefix##skip_free_node_##decl(node); \
return rc; \
} \
\
int prefix##skip_set_##decl(decl##_t *slist, ktype key, vtype value) \
{ \
decl##_node_t node; \