diff options
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r-- | nserver/src/protocol.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index d08eeda..0872bdb 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -76,21 +76,20 @@ int ssdelete(char *key) double sssample(char *key, double s) { - 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"); + // 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. sample! - Stats_sample(st, s); + // 2. Sample! + Stats_sample(rec->st, s); - // 4. get mean. - double m = Stats_mean(st); + // 3. Get mean. + double m = Stats_mean(rec->st); return m; error: |