[libc-commits] [libc] [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (PR #73469)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Wed Nov 29 12:49:24 PST 2023
================
@@ -0,0 +1,35 @@
+//===-- Implementation of hsearch -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/search/hsearch.h"
+#include "src/__support/HashTable/table.h"
+#include "src/errno/libc_errno.h"
+#include "src/search/hsearch/global.h"
+
+namespace LIBC_NAMESPACE {
+LLVM_LIBC_FUNCTION(ENTRY *, hsearch, (ENTRY item, ACTION action)) {
+ ENTRY *result;
+
+ switch (action) {
+ case FIND:
+ result = internal::global_hash_table->find(item.key);
+ if (result == nullptr) {
+ libc_errno = ESRCH;
+ }
+ break;
+ case ENTER:
+ result = internal::global_hash_table->insert(item);
----------------
SchrodingerZhu wrote:
@nickdesaulniers sure. Looking into the code, they are actually doing resizing and merely regard the maximum number as a hint. In that way, if a global hashtable is not initialized, they will just create a minimal table and resize it during insertion.
It requires some modifications but will not be too painful to add such features. I will be forming a patch by next Monday.
https://github.com/llvm/llvm-project/pull/73469
More information about the libc-commits
mailing list