[libc-commits] [libc] [libc] [search] improve hsearch robustness (PR #73896)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Dec 5 08:43:38 PST 2023
================
@@ -128,6 +147,107 @@ struct HashTable {
control(index2) = value;
}
+ LIBC_INLINE size_t find(const char *key, uint64_t primary) {
+ uint8_t secondary = secondary_hash(primary);
+ ProbeSequence sequence{static_cast<size_t>(primary), 0, entries_mask};
+ while (true) {
+ size_t pos = sequence.next();
+ Group ctrls = Group::load(&control(pos));
+ IteratableBitMask masks = ctrls.match_byte(secondary);
+ for (size_t i : masks) {
+ size_t index = (pos + i) & entries_mask;
+ ENTRY &entry = this->entry(index);
+ if (LIBC_LIKELY(entry.key != nullptr && strcmp(entry.key, key) == 0))
----------------
nickdesaulniers wrote:
Maybe worth an assert if entry.key or key is not nul terminated?
https://github.com/llvm/llvm-project/pull/73896
More information about the libc-commits
mailing list