Skip to content

Commit

Permalink
Remove the has_element function and use FindElement instead.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 557920808
Change-Id: I1eb0ca1ea9e9de542321fbc23d82218c5d449fbf
  • Loading branch information
ezbr authored and copybara-github committed Aug 17, 2023
1 parent 88ed183 commit 76af164
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,8 +2453,10 @@ class raw_hash_set {
const raw_hash_set* outer = &a;
const raw_hash_set* inner = &b;
if (outer->capacity() > inner->capacity()) std::swap(outer, inner);
for (const value_type& elem : *outer)
if (!inner->has_element(elem)) return false;
for (const value_type& elem : *outer) {
auto it = PolicyTraits::apply(FindElement{*inner}, elem);
if (it == inner->end() || !(*it == elem)) return false;
}
return true;
}

Expand Down Expand Up @@ -2659,24 +2661,6 @@ class raw_hash_set {
}
}

bool has_element(const value_type& elem) const {
size_t hash = PolicyTraits::apply(HashElement{hash_ref()}, elem);
auto seq = probe(common(), hash);
const ctrl_t* ctrl = control();
while (true) {
Group g{ctrl + seq.offset()};
for (uint32_t i : g.Match(H2(hash))) {
if (ABSL_PREDICT_TRUE(
PolicyTraits::element(slot_array() + seq.offset(i)) == elem))
return true;
}
if (ABSL_PREDICT_TRUE(g.MaskEmpty())) return false;
seq.next();
assert(seq.index() <= capacity() && "full table!");
}
return false;
}

// TODO(alkis): Optimize this assuming *this and that don't overlap.
raw_hash_set& move_assign(raw_hash_set&& that, std::true_type) {
raw_hash_set tmp(std::move(that));
Expand Down

0 comments on commit 76af164

Please sign in to comment.