pos gt/lt working; added dup put kv api
This commit is contained in:
parent
307d817ee0
commit
744acee09a
2 changed files with 40 additions and 15 deletions
|
@ -203,6 +203,8 @@ main()
|
||||||
char *v = api_skip_get_slex(list, array[i]);
|
char *v = api_skip_get_slex(list, array[i]);
|
||||||
api_skip_set_slex(list, array[i], to_upper(v));
|
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);
|
api_skip_del_slex(list, 0);
|
||||||
|
|
||||||
|
@ -213,13 +215,25 @@ main()
|
||||||
api_skip_destroy_slex(restored);
|
api_skip_destroy_slex(restored);
|
||||||
#endif
|
#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, -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, 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(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_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, -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, 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);
|
assert(strcmp(api_skip_pos_slex(list, SKIP_LTE, 2)->value, int_to_roman_numeral(2)) == 0);
|
||||||
|
|
31
include/sl.h
31
include/sl.h
|
@ -483,7 +483,7 @@
|
||||||
return elm; \
|
return elm; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* -- skip_position_gt TODO \
|
/* -- skip_position_gt_ \
|
||||||
* Position and return a cursor at the first node that is greater than \
|
* 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` \
|
* the provided node `n`. If the largestkey is less than the key in `n` \
|
||||||
* return NULL. \
|
* return NULL. \
|
||||||
|
@ -509,7 +509,7 @@
|
||||||
do { \
|
do { \
|
||||||
elm = elm->field.sle.next[0]; \
|
elm = elm->field.sle.next[0]; \
|
||||||
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
||||||
} while (cmp < 0); \
|
} while (cmp <= 0); \
|
||||||
return elm; \
|
return elm; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -543,12 +543,12 @@
|
||||||
do { \
|
do { \
|
||||||
elm = elm->field.sle.prev; \
|
elm = elm->field.sle.prev; \
|
||||||
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
||||||
} while (cmp > 0); \
|
} while (cmp >= 0); \
|
||||||
} \
|
} \
|
||||||
return elm; \
|
return elm; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* -- skip_position_lt TODO \
|
/* -- skip_position_lt_ \
|
||||||
* Position and return a cursor at the last node that is less than \
|
* 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. \
|
* to the node `n`. Return NULL if nothing is less than or equal. \
|
||||||
* \
|
* \
|
||||||
|
@ -571,14 +571,10 @@
|
||||||
elm = elm->field.sle.next[i]; \
|
elm = elm->field.sle.next[i]; \
|
||||||
} while (i--); \
|
} while (i--); \
|
||||||
elm = elm->field.sle.next[0]; \
|
elm = elm->field.sle.next[0]; \
|
||||||
if (__skip_key_compare_##decl(slist, elm, n, slist->aux) == 0) { \
|
|
||||||
return elm; \
|
|
||||||
} else { \
|
|
||||||
do { \
|
do { \
|
||||||
elm = elm->field.sle.prev; \
|
elm = elm->field.sle.prev; \
|
||||||
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
cmp = __skip_key_compare_##decl(slist, elm, n, slist->aux); \
|
||||||
} while (cmp > 0); \
|
} while (cmp >= 0); \
|
||||||
} \
|
|
||||||
return elm; \
|
return elm; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -634,7 +630,7 @@
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* -- skip_remove_ */ \
|
/* -- skip_remove_ BUG: prev pointer wrong!*/ \
|
||||||
int prefix##skip_remove_##decl(decl##_t *slist, decl##_node_t *n) \
|
int prefix##skip_remove_##decl(decl##_t *slist, decl##_node_t *n) \
|
||||||
{ \
|
{ \
|
||||||
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
static decl##_node_t apath[SKIPLIST_MAX_HEIGHT + 1]; \
|
||||||
|
@ -967,6 +963,21 @@
|
||||||
return rc; \
|
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) \
|
int prefix##skip_set_##decl(decl##_t *slist, ktype key, vtype value) \
|
||||||
{ \
|
{ \
|
||||||
decl##_node_t node; \
|
decl##_node_t node; \
|
||||||
|
|
Loading…
Reference in a new issue