[libc-commits] [libc] [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (PR #73469)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Nov 28 13:26:32 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);
----------------
nickdesaulniers wrote:

Yeah, that's better than nothing IMO. Please add.

https://github.com/llvm/llvm-project/pull/73469


More information about the libc-commits mailing list