diff options
author | rsiddharth <s@ricketyspace.net> | 2020-02-03 23:23:37 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-04-17 20:56:36 -0400 |
commit | aacbbb88ab9adade60b3b2c18be191add9a1c065 (patch) | |
tree | 31e66a7962ad58e0dc5570c063348cd7418e60d2 | |
parent | e6f4ddb3eba6e475df7796b7a4e2fa2b07df755e (diff) |
nserver/src/protocol.c: Add ssample_parent.
* nserver/src/protocol.c (ssample_parent): New function.
-rw-r--r-- | nserver/src/protocol.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 0872bdb..213179a 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -74,6 +74,28 @@ int ssdelete(char *key) return -1; } +int ssample_parent(char *key, double s) +{ + check(key != NULL || strlen(key) < 1, "key invalid"); + check(tst != NULL, "tstree not initialized"); + + // 1. Try to get Record with key prefix. + Record *rec = (Record *) TSTree_search_prefix(tst, key, strlen(key)); + + if (rec == NULL) { + // No record with key prefix. + return 0; + } + check(rec->st != NULL, "record's st invalid"); + + // 2. Sample! + Stats_sample(rec->st, s); + + return 1; + error: + return -1; +} + double sssample(char *key, double s) { check(key != NULL || strlen(key) < 1, "key invalid"); |