-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLDSketch.hpp
103 lines (82 loc) · 2.7 KB
/
LDSketch.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* LDSketch.h
* - heavy hitter random partition
*/
#include "dyn_tbl.hpp"
/// Sketch structure
typedef struct LDSketch_s {
/// bucket array
dyn_tbl_t** tbl;
/*********************************************************
* read only variables
********************************************************/
/// # of rows
int h;
/// # of buckets per row
int w;
/// init # of counters in each tbl (will grow later)
int l;
/// total number of buckets
// int size;
/// length of keys (in bits)
int lgn;
/// detection threshold
double thresh_abs;
/// id of detectors (detectors have different hash functions)
unsigned int tbl_id;
} LDSketch_t;
/*************************************************************
* create and destroy
************************************************************/
/// init sketch
// @return the pointer to the created sketch
LDSketch_t* LDSketch_init(int w, int h, int l, int lgn, long long thresh_abs, unsigned int tbl_id);
/// free scketch
void LDSketch_destroy(LDSketch_t* LDSketch);
/*************************************************************
* read functions
************************************************************/
/// print out the sketch to file
// @param sk target sketch
// @param output name of output file
void LDSketch_write_plaintext(LDSketch_t* sk, const char* output);
/// identify heavy keys
// @param sk target sketch
// @param thresh threshold for heavy keys
// @param keys results of detected keys
// @param vals results of detected key sizes
// @param num_key number of detected keys
void LDSketch_get_heavy_keys(LDSketch_t* sk, long long thresh, unsigned char* keys, long long* vals, int* num_key);
/// estimate the lower sum of a key
// @param sk target sketch
// @param key
// @return the estimated lower sum
long long LDSketch_low_estimate(LDSketch_t* sk, unsigned char* key);
/// estimate the upper sum of a key
// @param sk target sketch
// @param key
// @return the estimated upper sum
long long LDSketch_up_estimate(LDSketch_t* sk, unsigned char* key);
/*************************************************************
* write functions
************************************************************/
/**
* update the sketch with an data item
* @param sk the target sketch
* @param key key of the data item
* @param val value of the data item
* @param T expansion parameter
*/
void LDSketch_update(LDSketch_t* sk, unsigned char* key, long long val);
/**
* copy sketch
* @param from source sketch
* @param to target sketch
*/
void LDSketch_copy(LDSketch_t* from, LDSketch_t* to);
/**
* reset sketch
* @param sk the target sketch
* @param output filename of the output file
*/
void LDSketch_reset(LDSketch_t* sk);