OpenSDN source code
tdigest.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015 Loïc Séguin-Charbonneau
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 /*
24  * This is an implementation of the t-digest algorithm by Ted Dunning and Otmar
25  * Ertl. The algorithm is detailed in https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf
26  * and a reference implementation in Java is available at https://github.com/tdunning/t-digest.
27  *
28  * The current implementation has also been inspired by the work of Cam
29  * Davidson-Pilon: https://github.com/CamDavidsonPilon/tdigest.
30  */
31 
32 #ifndef TDIGEST_H
33 #define TDIGEST_H
34 
35 #define DEFAULT_DELTA 0.01
36 #define DEFAULT_K 100
37 
38 typedef struct TDigest TDigest;
39 typedef struct Centroid Centroid;
40 
41 TDigest *TDigest_create(double delta, unsigned int K);
42 void TDigest_destroy(TDigest* digest);
43 TDigest * TDigest_add(TDigest *pdigest, double x, size_t w);
44 Centroid *TDigest_find_closest_centroid(TDigest *digest, double x, size_t w);
46 double TDigest_percentile(TDigest *digest, double q);
50 size_t TDigest_get_count(TDigest *digest);
51 double Centroid_quantile(Centroid *c, TDigest *digest);
52 Centroid* Centroid_create(double x, size_t w);
53 void Centroid_add(Centroid *c, double x, size_t w);
56 
57 #endif
double TDigest_percentile(TDigest *digest, double q)
double Centroid_quantile(Centroid *c, TDigest *digest)
size_t TDigest_get_ncentroids(TDigest *digest)
Centroid * Centroid_create(double x, size_t w)
TDigest * TDigest_create(double delta, unsigned int K)
TDigest * TDigest_compress(TDigest *digest)
struct TDigest TDigest
Definition: tdigest.h:38
struct Centroid Centroid
Definition: tdigest.h:39
void Centroid_add(Centroid *c, double x, size_t w)
size_t TDigest_get_count(TDigest *digest)
double Centroid_get_mean(Centroid *c)
Centroid * TDigest_find_closest_centroid(TDigest *digest, double x, size_t w)
TDigest * TDigest_add(TDigest *pdigest, double x, size_t w)
size_t Centroid_get_count(Centroid *c)
void TDigest_destroy(TDigest *digest)
size_t TDigest_get_ncompressions(TDigest *digest)
Centroid * TDigest_get_centroid(TDigest *digest, size_t i)