| 432 | } |
| 433 | |
| 434 | static bool seen_set_insert(seen_set_t *s, int64_t node_id) { |
| 435 | if (!s->slots) { |
| 436 | return false; |
| 437 | } |
| 438 | uint32_t idx = (uint32_t)(node_id * KNUTH_MULT) & SEEN_SET_MASK; |
| 439 | for (int probe = 0; probe < SEEN_SET_SIZE; probe++) { |
| 440 | uint32_t slot = (idx + (uint32_t)probe) & SEEN_SET_MASK; |
| 441 | if (s->slots[slot] == 0) { |
| 442 | s->slots[slot] = node_id; |
| 443 | return true; /* inserted (was not present) */ |
| 444 | } |
| 445 | if (s->slots[slot] == node_id) { |
| 446 | return false; /* already present */ |
| 447 | } |
| 448 | } |
| 449 | return false; /* table full */ |
| 450 | } |
| 451 | |
| 452 | static void seen_set_free(seen_set_t *s) { |
| 453 | cbm_free(CBM_MEM_CLASS_SEMANTIC, s->slots); |