grpc
third_party
abseil-cpp
absl
container
internal
abseil-cpp/absl/container/internal/raw_hash_set.cc
Go to the documentation of this file.
1
// Copyright 2018 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "absl/container/internal/raw_hash_set.h"
16
17
#include <atomic>
18
#include <cstddef>
19
20
#include "absl/base/config.h"
21
22
namespace
absl
{
23
ABSL_NAMESPACE_BEGIN
24
namespace
container_internal {
25
26
// A single block of empty control bytes for tables without any slots allocated.
27
// This enables removing a branch in the hot path of find().
28
alignas
(16)
ABSL_CONST_INIT
ABSL_DLL
const
ctrl_t
kEmptyGroup
[16] = {
29
ctrl_t::kSentinel
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
30
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
31
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
32
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
,
ctrl_t::kEmpty
};
33
34
#ifdef ABSL_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
35
constexpr
size_t
Group::kWidth
;
36
#endif
37
38
// Returns "random" seed.
39
inline
size_t
RandomSeed
() {
40
#ifdef ABSL_HAVE_THREAD_LOCAL
41
static
thread_local
size_t
counter
= 0;
42
size_t
value
= ++
counter
;
43
#else // ABSL_HAVE_THREAD_LOCAL
44
static
std::atomic<size_t>
counter
(0);
45
size_t
value
=
counter
.fetch_add(1, std::memory_order_relaxed);
46
#endif // ABSL_HAVE_THREAD_LOCAL
47
return
value
^
static_cast<
size_t
>
(
reinterpret_cast<
uintptr_t
>
(&
counter
));
48
}
49
50
bool
ShouldInsertBackwards
(
size_t
hash
,
const
ctrl_t
* ctrl) {
51
// To avoid problems with weak hashes and single bit tests, we use % 13.
52
// TODO(kfm,sbenza): revisit after we do unconditional mixing
53
return
(
H1
(
hash
, ctrl) ^
RandomSeed
()) % 13 > 6;
54
}
55
56
void
ConvertDeletedToEmptyAndFullToDeleted
(
ctrl_t
* ctrl,
size_t
capacity
) {
57
assert(ctrl[
capacity
] ==
ctrl_t::kSentinel
);
58
assert(
IsValidCapacity
(
capacity
));
59
for
(
ctrl_t
*
pos
= ctrl;
pos
< ctrl +
capacity
;
pos
+=
Group::kWidth
) {
60
Group
{
pos
}.ConvertSpecialToEmptyAndFullToDeleted(
pos
);
61
}
62
// Copy the cloned ctrl bytes.
63
std::memcpy
(ctrl +
capacity
+ 1, ctrl,
NumClonedBytes
());
64
ctrl[
capacity
] =
ctrl_t::kSentinel
;
65
}
66
// Extern template instantiotion for inline function.
67
template
FindInfo
find_first_non_full
(
const
ctrl_t
*,
size_t
,
size_t
);
68
69
}
// namespace container_internal
70
ABSL_NAMESPACE_END
71
}
// namespace absl
pos
int pos
Definition:
libuv/docs/code/tty-gravity/main.c:11
ABSL_CONST_INIT
#define ABSL_CONST_INIT
Definition:
abseil-cpp/absl/base/attributes.h:716
capacity
uint16_t capacity
Definition:
protobuf/src/google/protobuf/descriptor.cc:948
absl::container_internal::GroupPortableImpl
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:654
absl::container_internal::kEmpty
@ kEmpty
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition:
third_party/abseil-cpp/absl/base/config.h:171
hash
uint64_t hash
Definition:
ring_hash.cc:284
absl::container_internal::find_first_non_full
template FindInfo find_first_non_full(const ctrl_t *, size_t, size_t)
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:842
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition:
third_party/abseil-cpp/absl/base/config.h:170
absl::container_internal::ctrl_t
ctrl_t
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:422
counter
static int counter
Definition:
abseil-cpp/absl/flags/reflection_test.cc:131
absl::container_internal::NumClonedBytes
constexpr size_t NumClonedBytes()
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:723
absl::container_internal::ShouldInsertBackwards
bool ShouldInsertBackwards(size_t hash, const ctrl_t *ctrl)
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.cc:50
uintptr_t
_W64 unsigned int uintptr_t
Definition:
stdint-msvc2008.h:119
absl::container_internal::H1
size_t H1(size_t hash, const ctrl_t *ctrl)
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:479
absl::container_internal::GroupPortableImpl::kWidth
static constexpr size_t kWidth
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:655
ABSL_DLL
#define ABSL_DLL
Definition:
third_party/abseil-cpp/absl/base/config.h:746
absl::container_internal::kSentinel
@ kSentinel
Definition:
bloaty/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h:263
value
const char * value
Definition:
hpack_parser_table.cc:165
absl::container_internal::RandomSeed
size_t RandomSeed()
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.cc:39
absl::container_internal::ConvertDeletedToEmptyAndFullToDeleted
void ConvertDeletedToEmptyAndFullToDeleted(ctrl_t *ctrl, size_t capacity)
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.cc:56
absl
Definition:
abseil-cpp/absl/algorithm/algorithm.h:31
absl::container_internal::kEmptyGroup
ABSL_CONST_INIT const ABSL_DLL ctrl_t kEmptyGroup[16]
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.cc:28
absl::container_internal::IsValidCapacity
bool IsValidCapacity(size_t n)
Definition:
abseil-cpp/absl/container/internal/raw_hash_set.h:731
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:51