diff options
author | rsiddharth <s@ricketyspace.net> | 2019-11-02 10:43:43 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-04-17 20:56:34 -0400 |
commit | 64ab0153238cd3d06296cd31bd9bc09ba8545f33 (patch) | |
tree | 73ccdd6ca99c39800e48f5904292f8490999a63b /nserver/src/protocol.c | |
parent | 71768c6233d8249425e2a3ae34993be84f245e0a (diff) |
nserver: protocol: Define ssmean.
* nserver/src/protocol.c (ssmean): New function.
* nserver/tests/protocol_tests.c (test_ssmean): New test.
(all_tests): ADd test_ssmean.
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r-- | nserver/src/protocol.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index a174caf..3c09733 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -57,3 +57,22 @@ int sssample(char *key, double s) return -1; } +double ssmean(char *key) +{ + check(hash != NULL, "hash not initialized"); + + // 1. create bstring from 'key'. + bstring k = bfromcstr(key); + + // 2. try to Stats for key. + Stats *st = (Stats *) Hashmap_get(hash, k); + check(st != NULL, "stats not found for key"); + + // 3. get mean. + double m = Stats_mean(st); + + return m; + error: + return -1; +} + |