5#ifndef V8_ZONE_ZONE_COMPACT_SET_H_
6#define V8_ZONE_ZONE_COMPACT_SET_H_
9#include <initializer_list>
22template <
typename T,
typename Enable =
void>
53 static_assert(std::is_trivially_copyable_v<T>);
54 static_assert(std::is_trivially_destructible_v<T>);
73 typename =
typename std::iterator_traits<It>::iterator_category>
75 auto size = last - first;
78 }
else if (size == 1) {
84 for (
auto it = first; it != last; ++it) {
85 *list_it = Traits::HandleToPointer(*it);
109 return Traits::PointerToHandle(
singleton());
111 return Traits::PointerToHandle(
list()->
at(
static_cast<int>(
i)));
134 std::lower_bound(current_list->
begin(), current_list->
end(), value);
135 if (it != current_list->
end() && *it == value) {
141 DCHECK(it == current_list->
end() || *it > value);
147 auto new_it = new_list->
begin();
148 new_it = std::copy(current_list->
begin(), it, new_it);
150 new_it = std::copy(it, current_list->
end(), new_it);
158 for (
size_t i = 0;
i < other.
size(); ++
i) {
164 if (
data_ == other.data_)
return true;
166 if (other.is_empty())
return true;
173 if (other.is_singleton()) {
177 DCHECK(std::is_sorted(other.list()->begin(), other.list()->end()));
183 for (
const data_type* pointer : *other.list()) {
184 it = std::lower_bound(it,
list->
end(), pointer);
185 if (it ==
list->
end() || *it != pointer)
return false;
212 std::lower_bound(current_list->
begin(), current_list->
end(), pointer);
213 if (found_it == current_list->
end() || *found_it != pointer) {
223 if (current_list->
size() == 2) {
225 if (found_it == current_list->
begin()) {
226 other_value = current_list->
at(1);
228 other_value = current_list->
at(0);
237 auto new_it = new_list->
begin();
238 new_it = std::copy(current_list->
begin(), found_it, new_it);
239 new_it = std::copy(found_it + 1, current_list->
end(), new_it);
251 List const*
const lhs_list = lhs.
list();
252 List const*
const rhs_list = rhs.
list();
253 return std::equal(lhs_list->
begin(), lhs_list->
end(), rhs_list->
begin(),
261 return !(lhs == rhs);
265 return set.data_.raw();
268 class const_iterator;
269 inline const_iterator
begin()
const;
270 inline const_iterator
end()
const;
307 for (
size_t i = 0;
i < set.
size(); ++
i) {
308 if (
i > 0) os <<
", ";
328 return set_ == other.set_ &&
current_ == other.current_;
331 return !(*
this == other);
V8_INLINE PointerType * GetPointerWithKnownPayload(PayloadType payload) const
V8_INLINE PayloadType GetPayload() const
constexpr size_t size() const
const T & at(size_t index) const
constexpr T * begin() const
constexpr T * end() const
bool operator!=(const const_iterator &other) const
const_iterator(const const_iterator &other)=default
std::ptrdiff_t difference_type
const_iterator & operator=(const const_iterator &other)=default
difference_type operator-(const const_iterator &other) const
bool operator==(const const_iterator &other) const
reference operator*() const
const ZoneCompactSet< T > * set_
const_iterator operator++(int)
std::forward_iterator_tag iterator_category
const_iterator & operator++()
const_iterator(const ZoneCompactSet< T > *set, size_t current)
void Union(ZoneCompactSet< T > const &other, Zone *zone)
void remove(T handle, Zone *zone)
ZoneCompactSet(const ZoneCompactSet &other) V8_NOEXCEPT=default
friend bool operator==(ZoneCompactSet< T > const &lhs, ZoneCompactSet< T > const &rhs)
void insert(T handle, Zone *zone)
data_type * singleton() const
ZoneCompactSet(std::initializer_list< T > handles, Zone *zone)
static PointerWithPayload EmptyValue()
base::PointerWithPayload< void, Tag, 2 > PointerWithPayload
friend bool operator!=(ZoneCompactSet< T > const &lhs, ZoneCompactSet< T > const &rhs)
List * NewList(size_t size, Zone *zone)
ZoneCompactSet & operator=(ZoneCompactSet &&other) V8_NOEXCEPT=default
friend uintptr_t hash_value(ZoneCompactSet< T > const &set)
List const * list() const
const_iterator begin() const
typename Traits::handle_type handle_type
ZoneCompactSet & operator=(const ZoneCompactSet &other) V8_NOEXCEPT=default
ZoneCompactSet< T > Clone(Zone *zone) const
ZoneCompactSet(ZoneCompactSet &&other) V8_NOEXCEPT=default
bool contains(ZoneCompactSet< T > const &other) const
ZoneCompactSet(It first, It last, Zone *zone)
bool contains(T handle) const
typename Traits::data_type data_type
T operator[](size_t i) const
bool is_singleton() const
const_iterator end() const
T * AllocateArray(size_t length)
ZoneVector< InstructionOperand > * set_
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
static handle_type PointerToHandle(data_type *ptr)
static data_type * HandleToPointer(handle_type handle)