Skip to content

Commit c952a1d

Browse files
ezbrcopybara-github
authored andcommitted
Change skip_empty_or_deleted to not use groups.
Motivation: this makes it simpler to change the iteration algorithm to allow for random iteration order for single group tables using aligned groups. PiperOrigin-RevId: 783881315 Change-Id: I29d9d9584f677b2a809303c464dad093dd131746
1 parent a4e1324 commit c952a1d

2 files changed

Lines changed: 6 additions & 24 deletions

File tree

absl/container/internal/raw_hash_set.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ constexpr ctrl_t ZeroCtrlT() { return static_cast<ctrl_t>(0); }
4545
// uninitialized because reading this memory is a bug.
4646
ABSL_DLL ctrl_t kDefaultIterControl;
4747

48-
// We need one full byte followed by a sentinel byte for iterator::operator++ to
49-
// work. We have a full group after kSentinel to be safe (in case operator++ is
50-
// changed to read a full group).
51-
ABSL_CONST_INIT ABSL_DLL const ctrl_t kSooControl[17] = {
52-
ZeroCtrlT(), ctrl_t::kSentinel, ZeroCtrlT(), ctrl_t::kEmpty,
53-
ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
54-
ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
55-
ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
56-
ctrl_t::kEmpty};
48+
// We need one full byte followed by a sentinel byte for iterator::operator++.
49+
ABSL_CONST_INIT ABSL_DLL const ctrl_t kSooControl[2] = {ZeroCtrlT(),
50+
ctrl_t::kSentinel};
5751

5852
namespace {
5953

absl/container/internal/raw_hash_set.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ inline ctrl_t* DefaultIterControl() { return &kDefaultIterControl; }
389389
// For use in SOO iterators.
390390
// TODO(b/289225379): we could potentially get rid of this by adding an is_soo
391391
// bit in iterators. This would add branches but reduce cache misses.
392-
ABSL_DLL extern const ctrl_t kSooControl[17];
392+
ABSL_DLL extern const ctrl_t kSooControl[2];
393393

394394
// Returns a pointer to a full byte followed by a sentinel byte.
395395
inline ctrl_t* SooControl() {
@@ -2052,20 +2052,8 @@ class raw_hash_set {
20522052
// `slot_` until they reach one.
20532053
void skip_empty_or_deleted() {
20542054
while (IsEmptyOrDeleted(*ctrl_)) {
2055-
auto mask = GroupFullEmptyOrDeleted{ctrl_}.MaskFullOrSentinel();
2056-
// Generally it is possible to compute `shift` branchless.
2057-
// This branch is useful to:
2058-
// 1. Avoid checking `IsEmptyOrDeleted` after the shift for the most
2059-
// common dense table case.
2060-
// 2. Avoid the cost of `LowestBitSet` for extremely sparse tables.
2061-
if (ABSL_PREDICT_TRUE(mask)) {
2062-
auto shift = mask.LowestBitSet();
2063-
ctrl_ += shift;
2064-
slot_ += shift;
2065-
return;
2066-
}
2067-
ctrl_ += Group::kWidth;
2068-
slot_ += Group::kWidth;
2055+
++ctrl_;
2056+
++slot_;
20692057
}
20702058
}
20712059

0 commit comments

Comments
 (0)