9#ifndef V8_BASE_SMALL_MAP_H_
10#define V8_BASE_SMALL_MAP_H_
81template <
typename NormalMap>
104 static const bool value = (
sizeof(
test<M>(0)) ==
sizeof(
big));
116template <
typename M,
bool has_key_equal_value>
120 const typename M::key_type& right) {
122 typename M::key_compare comp;
123 return !comp(left, right) && !comp(right, left);
137template <
typename NormalMap,
size_t kArraySize = 4,
143 std::numeric_limits<size_t>::max();
145 static_assert(kArraySize > 0,
"Initial size must be greater than 0");
147 "Initial size out of range");
167 if (&src ==
this)
return;
179 class const_iterator;
186 typedef typename NormalMap::iterator::pointer
pointer;
187 typedef typename NormalMap::iterator::reference
reference;
233 return other.array_iter_ ==
nullptr &&
map_iter_ == other.map_iter_;
238 return !(*
this == other);
256 typedef typename NormalMap::const_iterator::value_type
value_type;
258 typedef typename NormalMap::const_iterator::pointer
pointer;
259 typedef typename NormalMap::const_iterator::reference
reference;
310 return other.array_iter_ ==
nullptr &&
map_iter_ == other.map_iter_;
314 return !(*
this == other);
322 const typename NormalMap::const_iterator& init)
336 for (
size_t i = 0;
i <
size_; ++
i) {
351 for (
size_t i = 0;
i <
size_; ++
i) {
368 for (
size_t i =
size_;
i > 0; --
i) {
369 const size_t index =
i - 1;
390 std::pair<typename NormalMap::iterator, bool> ret =
map_.insert(
x);
391 return std::make_pair(
iterator(ret.first), ret.second);
394 for (
size_t i = 0;
i <
size_; ++
i) {
402 std::pair<typename NormalMap::iterator, bool> ret =
map_.insert(
x);
403 return std::make_pair(
iterator(ret.first), ret.second);
412 template <
class InputIterator>
413 void insert(InputIterator f, InputIterator l) {
421 template <
typename... Args>
426 std::pair<typename NormalMap::iterator, bool> ret =
427 map_.emplace(std::forward<Args>(
args)...);
428 return std::make_pair(
iterator(ret.first), ret.second);
432 for (
size_t i = 0;
i <
size_; ++
i) {
440 std::pair<typename NormalMap::iterator, bool> ret =
441 map_.emplace(std::move(
x));
442 return std::make_pair(
iterator(ret.first), ret.second);
451 template <
typename... Args>
456 std::pair<typename NormalMap::iterator, bool> ret =
457 map_.try_emplace(
key, std::forward<Args>(
args)...);
458 return std::make_pair(
iterator(ret.first), ret.second);
461 for (
size_t i = 0;
i <
size_; ++
i) {
469 std::pair<typename NormalMap::iterator, bool> ret =
470 map_.try_emplace(
key, std::forward<Args>(
args)...);
471 return std::make_pair(
iterator(ret.first), ret.second);
501 for (
size_t i = 0;
i <
size_; ++
i) {
586 for (
size_t i = 0;
i < kArraySize; ++
i) {
596 for (
size_t i = 0;
i < kArraySize; ++
i) {
597 map_.insert(std::move(temp.array[
i]));
598 temp.array[
i].~value_type();
606 if (src.UsingFullMap()) {
610 for (
size_t i = 0;
i <
size_; ++
i) {
620 for (
size_t i = 0;
i <
size_; ++
i) {
V8_INLINE const_iterator()
NormalMap::const_iterator::reference reference
V8_INLINE bool operator!=(const const_iterator &other) const
V8_INLINE const value_type * operator->() const
V8_INLINE bool operator==(const const_iterator &other) const
const value_type * array_iter_
NormalMap::const_iterator::pointer pointer
V8_INLINE const value_type & operator*() const
NormalMap::const_iterator::iterator_category iterator_category
V8_INLINE const_iterator(const iterator &other)
V8_INLINE const_iterator operator++(int)
V8_INLINE const_iterator & operator++()
V8_INLINE const_iterator(const value_type *init)
NormalMap::const_iterator::value_type value_type
NormalMap::const_iterator::difference_type difference_type
NormalMap::const_iterator map_iter_
V8_INLINE const_iterator operator--(int)
V8_INLINE const_iterator(const typename NormalMap::const_iterator &init)
V8_INLINE const_iterator & operator--()
V8_INLINE iterator(value_type *init)
V8_INLINE iterator operator++(int)
V8_INLINE iterator & operator--()
V8_INLINE iterator & operator++()
NormalMap::iterator::difference_type difference_type
V8_INLINE bool operator==(const iterator &other) const
V8_INLINE iterator(const typename NormalMap::iterator &init)
V8_INLINE value_type * operator->() const
NormalMap::iterator::value_type value_type
V8_INLINE value_type & operator*() const
NormalMap::iterator::pointer pointer
NormalMap::iterator::reference reference
NormalMap::iterator::iterator_category iterator_category
V8_INLINE iterator operator--(int)
NormalMap::iterator map_iter_
V8_INLINE bool operator!=(const iterator &other) const
value_type array_[kArraySize]
void insert(InputIterator f, InputIterator l)
void InitFrom(const SmallMap &src)
const_iterator find(const key_type &key) const
SmallMap(const SmallMap &src) V8_NOEXCEPT
SmallMap(const MapInit &functor)
V8_NOINLINE V8_PRESERVE_MOST void ConvertToRealMap()
data_type & operator[](const key_type &key)
size_t erase(const key_type &key)
NormalMap::value_type value_type
bool UsingFullMap() const
std::pair< iterator, bool > emplace(Args &&... args)
V8_INLINE NormalMap * map()
iterator erase(const iterator &position)
const_iterator begin() const
const_iterator end() const
size_t count(const key_type &key) const
void operator=(const SmallMap &src) V8_NOEXCEPT
NormalMap::key_type key_type
NormalMap::mapped_type mapped_type
static constexpr size_t kUsingFullMapSentinel
std::pair< iterator, bool > try_emplace(const key_type &key, Args &&... args)
V8_INLINE const NormalMap * map() const
NormalMap::mapped_type data_type
iterator find(const key_type &key)
std::pair< iterator, bool > insert(const value_type &x)
void operator()(NormalMap *map) const
ZoneVector< RpoNumber > & result
V8_BASE_EXPORT int const char va_list args
#define CHECK_LE(lhs, rhs)
#define DCHECK(condition)
static big test(typename U::key_equal *)
bool operator()(const typename M::key_type &left, const typename M::key_type &right)
#define V8_UNLIKELY(condition)
std::unique_ptr< ValueMirror > key