1 //===-- Implementation of hcreate_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/hcreate_r.h"
10 #include "src/__support/HashTable/randomness.h"
11 #include "src/__support/HashTable/table.h"
12 #include "src/__support/macros/config.h"
13 #include "src/errno/libc_errno.h"
15 namespace LIBC_NAMESPACE_DECL
{
16 LLVM_LIBC_FUNCTION(int, hcreate_r
,
17 (size_t capacity
, struct hsearch_data
*htab
)) {
18 if (htab
== nullptr) {
22 uint64_t randomness
= internal::randomness::next_random_seed();
23 internal::HashTable
*table
=
24 internal::HashTable::allocate(capacity
, randomness
);
25 if (table
== nullptr) {
29 htab
->__opaque
= table
;
33 } // namespace LIBC_NAMESPACE_DECL