| 136 | } |
| 137 | |
| 138 | int oldbloom_check(struct oldbloom * bloom, const void * buffer, int len) |
| 139 | { |
| 140 | if (bloom->ready == 0) { |
| 141 | printf("bloom at %p not initialized!\n", (void *)bloom); |
| 142 | return -1; |
| 143 | } |
| 144 | uint8_t hits = 0; |
| 145 | uint64_t a = XXH64(buffer, len, 0x59f2815b16f81798); |
| 146 | uint64_t b = XXH64(buffer, len, a); |
| 147 | uint64_t x; |
| 148 | uint8_t i; |
| 149 | for (i = 0; i < bloom->hashes; i++) { |
| 150 | x = (a + b*i) % bloom->bits; |
| 151 | if (oldtest_bit(bloom->bf, x)) { |
| 152 | hits++; |
| 153 | } else { |
| 154 | return 0; |
| 155 | } |
| 156 | } |
| 157 | if (hits == bloom->hashes) { |
| 158 | return 1; // 1 == element already in (or collision) |
| 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | int oldbloom_add(struct oldbloom * bloom, const void * buffer, int len) |
nothing calls this directly
no test coverage detected