summaryrefslogtreecommitdiffstats
path: root/nserver/src/protocol.c
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-02-11 17:05:52 -0500
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:36 -0400
commit15dec3eb3ef393ba514faf2ab3e2c6806e9d95ea (patch)
treed478c4fb4f1a757b3f2e195f9005581267223cc2 /nserver/src/protocol.c
parent01448c7f44bf38a3b2a39d2888721ac8b232d6a1 (diff)
nserver: Update ssmean.
* nserver/src/protocol.c (ssmean): Rewrite to use TSTree instead of Hashmap. * nserver/tests/protocol_tests.c (test_ssmean): Update test.
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r--nserver/src/protocol.c16
1 files changed, 8 insertions, 8 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: