[libc-commits] [libc] [libc] [search] improve hsearch robustness (PR #73896)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Tue Dec 5 08:53:51 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))
----------------
SchrodingerZhu wrote:
I suppose that may not be needed. For one thing, it is not that trivial to check nul termination. For the other thing, if we get to this point, both `entry.key` and `key` has been passed into `strlen` for hash somewhere. (Though the user can change the string in some wrong way as we only record the pointers)
https://github.com/llvm/llvm-project/pull/73896
More information about the libc-commits
mailing list