From 15dec3eb3ef393ba514faf2ab3e2c6806e9d95ea Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Tue, 11 Feb 2020 17:05:52 -0500 Subject: nserver: Update ssmean. * nserver/src/protocol.c (ssmean): Rewrite to use TSTree instead of Hashmap. * nserver/tests/protocol_tests.c (test_ssmean): Update test. --- nserver/src/protocol.c | 16 ++++++++-------- nserver/tests/protocol_tests.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 6043dcf..da4141a 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -124,17 +124,17 @@ double sssample(char *key, double s) double ssmean(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); + // 1. Try to get Record for key. + Record *rec = (Record *) TSTree_search(tst, key, strlen(key)); - // 2. try to get Stats for key. - Stats *st = (Stats *) Hashmap_get(hash, k); - check(st != NULL, "stats not found for key"); + check(rec != NULL, "record not found"); + check(rec->st != NULL, "record's st invalid"); - // 3. get mean. - double m = Stats_mean(st); + // 2. Get mean. + double m = Stats_mean(rec->st); return m; error: diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c index 6e03816..6e50ee5 100644 --- a/nserver/tests/protocol_tests.c +++ b/nserver/tests/protocol_tests.c @@ -58,8 +58,8 @@ char *test_ssmean() { double m = 0; - m = ssmean("crimson"); - mu_assert(m == 8, "ssmean failed 0"); + m = ssmean("/crimson"); + mu_assert(m == 15.20, "ssmean failed 0"); m = ssmean("/vermilion"); mu_assert(m == 17, "ssmean failed 1"); -- cgit v1.2.3