]> git.ozlabs.org Git - ccan/commit
htable: fix vanishing entries properly.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Jun 2022 12:18:19 +0000 (21:48 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 13 Jun 2022 12:18:19 +0000 (21:48 +0930)
commite03b68c761b870fd9e4c165bfe2358f5df82e49c
tree5cec79bcb8972a9a4c7b964cd82b9599196171a5
parent9a9d6a03d99f05f3158df8520c5338324fd74c49
htable: fix vanishing entries properly.

A hash table entry consists of the pointer, but we mask out bits which
are common to all pointers, and replace them with hash bits.

The entry values 0 and 1 are special, meaning "empty" and "deleted"
respectively.

However, if a hash has mainly zero bits, and an pointer's non-shared
bits are all zero, we can create an entry which looks empty or
deleted.

The solution in this case is to share another bit (there must be some
bit which is not zero, since we don't allow 0 and 1 as pointers in the
hash table).

It's unusual, so I put this in a cold function: it shares code with
the existing "oh, we need to reduce the common bits, since this new
pointer doesn't look like the previous ones" case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/htable/htable.c
ccan/htable/htable.h
ccan/htable/test/run-clash.c