1 //===-- Implementation of hsearch_r -----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/search/hsearch_r.h"
10 #include "src/__support/HashTable/table.h"
11 #include "src/__support/macros/config.h"
12 #include "src/errno/libc_errno.h"
14 namespace LIBC_NAMESPACE_DECL
{
15 LLVM_LIBC_FUNCTION(int, hsearch_r
,
16 (ENTRY item
, ACTION action
, ENTRY
**retval
,
17 struct hsearch_data
*htab
)) {
18 if (htab
== nullptr) {
22 internal::HashTable
*table
=
23 static_cast<internal::HashTable
*>(htab
->__opaque
);
26 *retval
= table
->find(item
.key
);
27 if (*retval
== nullptr) {
33 *retval
= internal::HashTable::insert(table
, item
);
34 htab
->__opaque
= table
;
35 if (*retval
== nullptr) {
44 } // namespace LIBC_NAMESPACE_DECL