[FoldingSet] Switch to linear probing and Algorithm R deletion (#218190)
FoldingSet uses an inefficient chaining hash table. Switch to
linear-probing open addressing: the bucket array holds node pointers,
with null marking an empty slot. Deletion uses Knuth TAOCP 6.4 Algorithm
R, as DenseMap/StringMap do, so erase invalidates iterators while
leaving pointers to nodes valid.
The next-in-bucket pointer becomes a cached 32-bit hash, halving
FoldingSetNode. A probe compares it before the profile compare, and
FindNodeOrInsertPos returns it instead of a bucket address, so an
InsertPos survives intervening insertions.
https://discourse.llvm.org/t/rfc-modernizing-llvms-foldingset-open-addressing-with-swiss-table-and-algorithm-r/91637
LLM-aided
Co-authored-by: Kazu Hirata <kazu@google.com>