[all-commits] [llvm/llvm-project] 86e99e: [libc] [search] improve hsearch robustness (#73896)

Schrodinger ZHU Yifan via All-commits all-commits at lists.llvm.org
Tue Dec 5 09:07:01 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 86e99e11e50da254ddaf73fbb9ea24028756bdd7
      https://github.com/llvm/llvm-project/commit/86e99e11e50da254ddaf73fbb9ea24028756bdd7
  Author: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
  Date:   2023-12-05 (Tue, 05 Dec 2023)

  Changed paths:
    M libc/docs/dev/undefined_behavior.rst
    M libc/src/__support/HashTable/CMakeLists.txt
    M libc/src/__support/HashTable/bitmask.h
    M libc/src/__support/HashTable/generic/bitmask_impl.inc
    M libc/src/__support/HashTable/sse2/bitmask_impl.inc
    M libc/src/__support/HashTable/table.h
    M libc/src/search/CMakeLists.txt
    M libc/src/search/hcreate.cpp
    M libc/src/search/hdestroy.cpp
    M libc/src/search/hsearch.cpp
    M libc/src/search/hsearch_r.cpp
    M libc/test/src/__support/HashTable/bitmask_test.cpp
    M libc/test/src/__support/HashTable/table_test.cpp
    M libc/test/src/search/hsearch_test.cpp

  Log Message:
  -----------
  [libc] [search] improve hsearch robustness  (#73896)

Following up the discussion at
https://github.com/llvm/llvm-project/pull/73469#discussion_r1409593911
by @nickdesaulniers.

According to FreeBSD implementation
(https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/upstream-freebsd/lib/libc/stdlib/hcreate.c),
`hsearch` is able to handle the cases where the global table is not
properly initialized. To do this, FreeBSD actually allows hash table to
be dynamically resized. If the global table is uninitialized at the
first call, the table will be initialized with a minimal size; hence
subsequent insertion will be reasonable as the table grows
automatically.

This patch mimic such behaviors. More precisely, this patch introduces:

1. a full table iterator that scans each element in the table,
2. a resize routine that is automatically triggered whenever the load
factor is reached where it iterates the old table and insert the entries
into a new one,
3. more tests that cover the growth of the table.




More information about the All-commits mailing list