-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearCounting.cpp
More file actions
59 lines (41 loc) · 1.06 KB
/
LinearCounting.cpp
File metadata and controls
59 lines (41 loc) · 1.06 KB
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
#ifndef LC_H
#define LC_H
#include "hash.h"
class LinearCounting{
typedef struct BUCKET_type {
int32_t bsize;
} Bucket;
struct LC_type {
int width;
uint64_t seed =541;
Bucket* lc_table;//定义一个指针,用来存储二维数组
};
private:
LC_type lc;
public:
LinearCounting(int width){
lc.width = width;
lc.lc_table = new Bucket[width];
memset(lc.lc_table, 0, width*sizeof(Bucket));
}
~LinearCounting(){
delete lc.lc_table;
}
void insert(unsigned char* key, int32_t pkt_size){
int index = 0;
index = MurmurHash64A(key, 13, lc.seed)% lc.width;
lc.lc_table[index].bsize += pkt_size;
}
uint32_t getCardinality() {
uint32_t card =0;
uint32_t countZero=0;
for (int j = 0; j < lc.width; j++){
if(lc.lc_table[j].bsize == 0){
countZero++;
}
}
card = (uint32_t)(-lc.width*std::log(countZero*1.0/lc.width));
return card;
}
};
#endif