Skip to content

Commit 5ac09e4

Browse files
committed
Succinct counting blocked Bloom using rank instead of select: bugfix
1 parent c95e162 commit 5ac09e4

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

src/bloom/counting_bloom.h

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ class SuccinctCountingBlockedBloomFilter {
516516
void Increment(size_t group, int bit);
517517
void Decrement(size_t group, int bit);
518518
int ReadCount(size_t group, int bit);
519+
#ifdef VERIFY_COUNT
520+
void VerifyCount(size_t group, int bit, int line);
521+
#endif
519522

520523
public:
521524
explicit SuccinctCountingBlockedBloomFilter(const int capacity);
@@ -642,13 +645,24 @@ void SuccinctCountingBlockedBloomFilter<ItemType, bits_per_item, HashFamily, k>:
642645
counts[group] = c;
643646
}
644647
#ifdef VERIFY_COUNT
648+
VerifyCount(group, bit, __LINE__);
649+
#endif
650+
}
651+
652+
#ifdef VERIFY_COUNT
653+
template <typename ItemType, size_t bits_per_item, typename HashFamily, int k>
654+
void SuccinctCountingBlockedBloomFilter<ItemType, bits_per_item, HashFamily, k>::
655+
VerifyCount(size_t group, int bit, int line) {
645656
for(int b = 0; b < 64; b++) {
646657
if (realCount[(group << 6) + b] != ReadCount(group, b)) {
647-
::std::cout << "group " << group << "/" << b << " of " << bit << "\n";
658+
::std::cout << "group " << group << " bit " << b <<
659+
" expected " << (int) realCount[(group << 6) + b] <<
660+
" got " << ReadCount(group, b) <<
661+
" at bit " << bit << " at line " << line << "\n";
648662
}
649663
}
650-
#endif
651664
}
665+
#endif
652666

653667
template <typename ItemType, size_t bits_per_item, typename HashFamily, int k>
654668
int SuccinctCountingBlockedBloomFilter<ItemType, bits_per_item, HashFamily, k>::
@@ -737,11 +751,7 @@ void SuccinctCountingBlockedBloomFilter<ItemType, bits_per_item, HashFamily, k>:
737751
data[group] = m & ~(removed << bit);
738752
}
739753
#ifdef VERIFY_COUNT
740-
for(int b = 0; b < 64; b++) {
741-
if (realCount[(group << 6) + b] != ReadCount(group, b)) {
742-
::std::cout << "group- " << group << "/" << b << " of " << bit << "\n";
743-
}
744-
}
754+
VerifyCount(group, bit, __LINE__);
745755
#endif
746756
}
747757

@@ -794,6 +804,9 @@ class SuccinctCountingBlockedBloomRankFilter {
794804
void Increment(size_t group, int bit);
795805
void Decrement(size_t group, int bit);
796806
int ReadCount(size_t group, int bit);
807+
#ifdef VERIFY_COUNT
808+
void VerifyCount(size_t group, int bit, int line);
809+
#endif
797810

798811
public:
799812
explicit SuccinctCountingBlockedBloomRankFilter(const int capacity);
@@ -879,6 +892,9 @@ void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
879892
size_t bitIndex = x & 63;
880893
overflow[index + bitIndex / 8] += getBit(bitIndex);
881894
data[group] |= (1L << x);
895+
#ifdef VERIFY_COUNT
896+
VerifyCount(group, x, __LINE__);
897+
#endif
882898
return;
883899
}
884900
uint64_t d = (m >> x) & 1;
@@ -941,24 +957,31 @@ void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
941957
int bitIndex = x & 63;
942958
overflow[index + bitIndex / 8] += getBit(bitIndex);
943959
#ifdef VERIFY_COUNT
944-
for(int b = 0; b < 64; b++) {
945-
if (realCount[(group << 6) + b] != ReadCount(group, b)) {
946-
::std::cout << "group " << group << "/" << b << " of " << x << "\n";
947-
}
948-
}
960+
VerifyCount(group, x, __LINE__);
949961
#endif
950962
return;
951963
}
952964
data[group] |= 1L << x;
953965
counts[group] = c;
954966
#ifdef VERIFY_COUNT
967+
VerifyCount(group, x, __LINE__);
968+
#endif
969+
}
970+
971+
#ifdef VERIFY_COUNT
972+
template <typename ItemType, size_t bits_per_item, typename HashFamily, int k>
973+
void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily, k>::
974+
VerifyCount(size_t group, int bit, int line) {
955975
for(int b = 0; b < 64; b++) {
956976
if (realCount[(group << 6) + b] != ReadCount(group, b)) {
957-
::std::cout << "group " << group << "/" << b << " of " << x << "\n";
977+
::std::cout << "group " << group << " bit " << b <<
978+
" expected " << (int) realCount[(group << 6) + b] <<
979+
" got " << ReadCount(group, b) <<
980+
" at bit " << bit << " at line " << line << "\n";
958981
}
959982
}
960-
#endif
961983
}
984+
#endif
962985

963986
template <typename ItemType, size_t bits_per_item, typename HashFamily, int k>
964987
int SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily, k>::
@@ -1000,7 +1023,7 @@ int SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
10001023
break;
10011024
}
10021025
if (count > 16) {
1003-
// not supported
1026+
// unexpected
10041027
::std::cout << "group- " << group << " count " << count << "\n";
10051028
}
10061029
}
@@ -1048,12 +1071,12 @@ void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
10481071
}
10491072
if (count < 64) {
10501073
// convert back to an inline entry, and free up the overflow entry
1051-
int count2 = 0;
10521074
int temp[64];
1053-
for(int j = 63; j >= 0; j--) {
1054-
int cj = (int) ((overflow[index + j / 8] >> (8 * j)) & 0xff);
1055-
temp[j] = cj;
1075+
int count2 = 0;
1076+
for(int j = 0; j < 64; j++) {
1077+
int cj = (int) ((overflow[index + j / 8] >> (8 * (j & 7))) & 0xff);
10561078
count2 += cj;
1079+
temp[j] = cj;
10571080
}
10581081
uint64_t c2 = 0;
10591082
int off = 0;
@@ -1072,11 +1095,9 @@ void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
10721095
// freeOverflow(index);
10731096
overflow[index] = nextFreeOverflow;
10741097
nextFreeOverflow = index;
1075-
/*
1076-
if (VERIFY_COUNTS) {
1077-
verifyCounts((group << 6), ((group + 1) << 6));
1078-
}
1079-
*/
1098+
#ifdef VERIFY_COUNT
1099+
VerifyCount(group, x, __LINE__);
1100+
#endif
10801101
}
10811102
return;
10821103
}
@@ -1123,12 +1144,7 @@ void SuccinctCountingBlockedBloomRankFilter<ItemType, bits_per_item, HashFamily,
11231144
// possibly reset the data bit
11241145
data[group] = m & ~((d==0?1L:0L) << x);
11251146
#ifdef VERIFY_COUNT
1126-
// TODO something wrong here
1127-
for(int b = 0; b < 64; b++) {
1128-
if (realCount[(group << 6) + b] != ReadCount(group, b)) {
1129-
::std::cout << "group- " << group << "/" << b << " of " << x << "\n";
1130-
}
1131-
}
1147+
VerifyCount(group, x, __LINE__);
11321148
#endif
11331149
}
11341150

0 commit comments

Comments
 (0)