-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathiblt.h
72 lines (57 loc) · 1.87 KB
/
iblt.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
#ifndef IBLT_H
#define IBLT_H
#include <inttypes.h>
#include <set>
#include <vector>
//
// Invertible Bloom Lookup Table implementation
// References:
//
// "What's the Difference? Efficient Set Reconciliation
// without Prior Context" by Eppstein, Goodrich, Uyeda and
// Varghese
//
// "Invertible Bloom Lookup Tables" by Goodrich and
// Mitzenmacher
//
class IBLT
{
public:
IBLT(size_t _expectedNumEntries, size_t _ValueSize);
IBLT(const IBLT& other);
virtual ~IBLT();
void insert(uint64_t k, const std::vector<uint8_t> v);
void erase(uint64_t k, const std::vector<uint8_t> v);
// Returns true if a result is definitely found or not
// found. If not found, result will be empty.
// Returns false if overloaded and we don't know whether or
// not k is in the table.
bool get(uint64_t k, std::vector<uint8_t>& result) const;
// Adds entries to the given sets:
// positive is all entries that were inserted
// negative is all entreis that were erased but never added (or
// if the IBLT = A-B, all entries in B that are not in A)
// Returns true if all entries could be decoded, false otherwise.
bool listEntries(std::set<std::pair<uint64_t,std::vector<uint8_t> > >& positive,
std::set<std::pair<uint64_t,std::vector<uint8_t> > >& negative) const;
// Subtract two IBLTs
IBLT operator-(const IBLT& other) const;
// For debugging:
std::string DumpTable() const;
private:
void _insert(int plusOrMinus, uint64_t k, const std::vector<uint8_t> v);
size_t valueSize;
class HashTableEntry
{
public:
int32_t count;
uint64_t keySum;
uint32_t keyCheck;
std::vector<uint8_t> valueSum;
bool isPure() const;
bool empty() const;
void addValue(const std::vector<uint8_t> v);
};
std::vector<HashTableEntry> hashTable;
};
#endif /* IBLT_H */