71 : m_compressionScheme(scheme)
74 size_t nEntries = expectedNumEntries + expectedNumEntries / 2;
76 size_t remainder = nEntries %
N_HASH;
78 nEntries += (
N_HASH - remainder);
81 m_hashTable.resize(nEntries);
89 if (3 * m_hashTable.size() != values.size()) {
90 BOOST_THROW_EXCEPTION(
Error(
"Received IBF cannot be decoded!"));
93 for (
size_t i = 0; i < m_hashTable.size(); i++) {
95 if (values[i * 3] != 0) {
96 entry.
count = values[i * 3];
97 entry.
keySum = values[(i * 3) + 1];
98 entry.
keyCheck = values[(i * 3) + 2];
104 IBLT::update(
int plusOrMinus, uint32_t key)
106 size_t bucketsPerHash = m_hashTable.size() /
N_HASH;
108 for (
size_t i = 0; i <
N_HASH; i++) {
109 size_t startEntry = i * bucketsPerHash;
111 HashTableEntry& entry = m_hashTable.at(startEntry + (h % bucketsPerHash));
112 entry.
count += plusOrMinus;
138 for (
const auto& entry : peeled.m_hashTable) {
139 if (entry.isPure()) {
140 if (entry.count == 1) {
141 positive.insert(entry.keySum);
144 negative.insert(entry.keySum);
146 peeled.update(-entry.count, entry.keySum);
150 }
while (nErased > 0);
154 for (
const auto& entry : peeled.m_hashTable) {
155 if (entry.isEmpty() !=
true) {
166 BOOST_ASSERT(m_hashTable.size() == other.m_hashTable.size());
169 for (
size_t i = 0; i < m_hashTable.size(); i++) {
185 if (iblt1HashTable.size() != iblt2HashTable.size()) {
189 size_t N = iblt1HashTable.size();
191 for (
size_t i = 0; i < N; i++) {
192 if (iblt1HashTable[i].count != iblt2HashTable[i].count ||
193 iblt1HashTable[i].keySum != iblt2HashTable[i].keySum ||
194 iblt1HashTable[i].keyCheck != iblt2HashTable[i].keyCheck)
204 return !(iblt1 == iblt2);
210 out <<
"count keySum keyCheckMatch\n";
212 out << entry.count <<
" " << entry.keySum <<
" ";
214 (entry.isEmpty())?
"true" :
"false");
224 constexpr
size_t unitSize = (
sizeof(m_hashTable[0].count) +
225 sizeof(m_hashTable[0].keySum) +
226 sizeof(m_hashTable[0].keyCheck));
228 size_t tableSize = unitSize * m_hashTable.size();
229 std::vector<uint8_t> table(tableSize);
231 for (
size_t i = 0; i < m_hashTable.size(); i++) {
234 table[(i * unitSize)] = 0xFF & m_hashTable[i].count;
235 table[(i * unitSize) + 1] = 0xFF & (m_hashTable[i].count >> 8);
236 table[(i * unitSize) + 2] = 0xFF & (m_hashTable[i].count >> 16);
237 table[(i * unitSize) + 3] = 0xFF & (m_hashTable[i].count >> 24);
241 table[(i * unitSize) + 4] = 0xFF & m_hashTable[i].keySum;
242 table[(i * unitSize) + 5] = 0xFF & (m_hashTable[i].keySum >> 8);
243 table[(i * unitSize) + 6] = 0xFF & (m_hashTable[i].keySum >> 16);
244 table[(i * unitSize) + 7] = 0xFF & (m_hashTable[i].keySum >> 24);
248 table[(i * unitSize) + 8] = 0xFF & m_hashTable[i].keyCheck;
249 table[(i * unitSize) + 9] = 0xFF & (m_hashTable[i].keyCheck >> 8);
250 table[(i * unitSize) + 10] = 0xFF & (m_hashTable[i].keyCheck >> 16);
251 table[(i * unitSize) + 11] = 0xFF & (m_hashTable[i].keyCheck >> 24);
254 auto compressed =
compress(m_compressionScheme, table.data(), table.size());
255 name.append(ndn::name::Component(std::move(compressed)));
258 std::vector<uint32_t>
261 auto decompressedBuf =
decompress(m_compressionScheme, ibltName.value(), ibltName.value_size());
263 size_t n = decompressedBuf->size() / 4;
265 std::vector<uint32_t> values(n, 0);
267 for (
size_t i = 0; i < 4 * n; i += 4) {
268 uint32_t t = ((*decompressedBuf)[i + 3] << 24) +
269 ((*decompressedBuf)[i + 2] << 16) +
270 ((*decompressedBuf)[i + 1] << 8) +
271 (*decompressedBuf)[i];
void initialize(const ndn::name::Component &ibltName)
Populate the hash table using the vector representation of IBLT.
uint32_t murmurHash3(uint32_t nHashSeed, const std::vector< unsigned char > &vDataToHash)
IBLT(size_t expectedNumEntries, CompressionScheme scheme=CompressionScheme::ZLIB)
constructor
Invertible Bloom Lookup Table (Invertible Bloom Filter)
bool operator==(const BloomFilter &bf1, const BloomFilter &bf2)
const std::vector< HashTableEntry > & getHashTable() const
std::shared_ptr< ndn::Buffer > decompress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
bool operator!=(const IBLT &iblt1, const IBLT &iblt2)
void insert(uint32_t key)
std::ostream & operator<<(std::ostream &out, const BloomFilter &bf)
std::shared_ptr< ndn::Buffer > compress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
bool listEntries(std::set< uint32_t > &positive, std::set< uint32_t > &negative) const
List all the entries in the IBLT.
IBLT operator-(const IBLT &other) const
std::vector< uint32_t > extractValueFromName(const ndn::name::Component &ibltName) const
Extracts IBLT from name component.
void appendToName(ndn::Name &name) const
Appends self to name.