Insert a trigram hash: UNIQ_NEW, UNIQ_PRESENT, or UNIQ_FULL (not counted). */
| 202 | |
| 203 | /* Insert a trigram hash: UNIQ_NEW, UNIQ_PRESENT, or UNIQ_FULL (not counted). */ |
| 204 | static int uniq_trig_insert(uniq_trig_set_t *s, uint64_t trig_hash) { |
| 205 | uint64_t val = trig_hash | SKIP_ONE; /* ensure non-zero */ |
| 206 | uint32_t slot = (uint32_t)(trig_hash & s->mask); |
| 207 | for (uint32_t probe = 0; probe <= s->mask; probe++) { |
| 208 | uint32_t idx = (slot + probe) & s->mask; |
| 209 | if (s->slots[idx] == 0) { |
| 210 | s->slots[idx] = val; |
| 211 | s->count++; |
| 212 | return UNIQ_NEW; |
| 213 | } |
| 214 | if (s->slots[idx] == val) { |
| 215 | return UNIQ_PRESENT; |
| 216 | } |
| 217 | } |
| 218 | return UNIQ_FULL; |
| 219 | } |
| 220 | |
| 221 | /* Apply weighted MinHash for one trigram: hash w times per seed. */ |
| 222 | static void weighted_minhash_update(cbm_minhash_t *out, const char *trigram, int len, int w) { |