-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.h
90 lines (79 loc) · 1.74 KB
/
data.h
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
#ifndef DATA_H
#define DATA_H
#include <unordered_map>
#include <functional>
#include <cstring>
#include "hash_class.cpp"
#include "hash.h"
using namespace std;
class Data{
public:
unsigned char str[DATA_LEN];
Data& operator = (Data an);
uint Hash(uint num = 0) const{
return Hash::BOBHash32(str, DATA_LEN, num);
} //the hash num of the data
};
struct Packet{
Data dat;
ts_t timestamp;
bool operator < (const Packet&b) const {
return timestamp < b.timestamp;
}
};
bool operator < (Data bn, Data an);
bool operator == (Data bn, Data an);
class My_Hash{
public:
size_t operator()(const Data dat) const{
return RSHash(dat.str, DATA_LEN);
}
};
size_t packet_hash( const Data & p )
{
string s((const char*)p.str);
return hash<string>()(s) ;
}
Data& Data::operator = (Data an){
for(int i = 0;i < DATA_LEN;++i){
str[i] = an.str[i];
}
return *this;
}
bool operator < (Data bn, Data an){
for(int i = 0;i < DATA_LEN;++i){
if(bn.str[i] < an.str[i])
return true;
else if(bn.str[i] > an.str[i])
return false;
}
return false;
}
bool operator == (Data bn, Data an){
for(int i = 0;i < DATA_LEN;++i){
if(bn.str[i] != an.str[i])
return false;
}
return true;
}
struct Element{
Data item;
int w;
int window_number;
bool operator < (Element b)const{
return w < b.w || (w == b.w && item < b.item);
}
bool operator == (const Element&b)const{
return w == b.w && item == b.item;
}
bool operator > (Element b)const{
return w > b.w || (w == b.w && b.item < item );
}
};
struct HashRet{
int*ret;
HashRet(int k){
ret = new int[k];
}
};
#endif// DATA_H