nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 3132ac2798d17de720a653068c968b5b4ed148e8
parent 09339f341bd467f3f44458bd130c301fe7ccce4a
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 17 Feb 2020 20:26:38 -0500

nserver/src/protocol.c: Updat ssdelete.

* nserver/src/protocol.c (ssdelete): Refactor to use TSTree.
(hash): Remove static variable. No longer used.
* nserver/tests/protocol_tests.c (all_tests): Uncomment test_ssdelete.

Diffstat:
nserver/src/protocol.c | 31+++++++++++--------------------
nserver/tests/protocol_tests.c | 2+-
2 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c @@ -1,6 +1,5 @@ #include <protocol.h> -static Hashmap *hash; static TSTree *tst; int sscreate(char *key) @@ -49,29 +48,21 @@ int sscreate(char *key) int ssdelete(char *key) { - check(hash != NULL, "hash not initialized"); + check(key != NULL || strlen(key) < 1, "key invalid"); + check(tst != NULL, "tstree not initialized"); - // 1. create bstring from 'key'. - bstring k = bfromcstr(key); - check(k != NULL, "key creation failed"); + Record *rec = (Record *) TSTree_search_prefix(tst, key, strlen(key)); + if (rec == NULL) { + // key does not exists. + return 0; + } - // 2. check if key exists. - Stats *st = (Stats *) Hashmap_get(hash, k); - if (st == NULL) { - // key does not exists. - return 0; - } + // Mark as deleted. + rec->deleted = 1; - // 3. delete key. - st = (Stats *) Hashmap_delete(hash, k); - check(st != NULL, "hash key delete failed"); - - // 4. clean up the stats for this key. - free(st); - - return 0; + return 0; error: - return -1; + return -1; } int sssample_parent(char *key, double s) diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c @@ -134,7 +134,7 @@ char *all_tests() mu_run_test(test_ssmean); mu_run_test(test_ssdump); mu_run_test(test_sslist); - /*mu_run_test(test_ssdelete);*/ + mu_run_test(test_ssdelete); return NULL; }