From a89b692e370e65b0fb087a2f843faf9ce1d5a6ae Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 2 Nov 2019 11:05:54 -0400 Subject: nserver: protocol: Define ssdelete. * nserver/src/protocol.c (ssdelete): New function. * nserver/tests/protocol_tests.c (test_ssdelete): New test. (all_tests): Add test_ssdelete. --- nserver/src/protocol.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'nserver/src/protocol.c') diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 3c09733..adcfc21 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -37,6 +37,33 @@ int sscreate(char *key) return -1; } +int ssdelete(char *key) +{ + check(hash != NULL, "hash not initialized"); + + // 1. create bstring from 'key'. + bstring k = bfromcstr(key); + check(k != NULL, "key creation failed"); + + // 2. check if key exists. + Stats *st = (Stats *) Hashmap_get(hash, k); + if (st == NULL) { + // key does not exists. + return 0; + } + + // 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; + error: + return -1; +} + int sssample(char *key, double s) { check(hash != NULL, "hash not initialized"); -- cgit v1.2.3