13 #ifndef __UT_ArrayMap__
14 #define __UT_ArrayMap__
20 #include <hboost/functional/hash.hpp>
28 template<
class KeyEqual,
typename Key,
typename T>
31 bool operator()(
const std::pair<Key,T> &
a,
const std::pair<Key,T> &
b)
const
33 return KeyEqual()(a.first, b.first);
37 template<
typename Hash,
typename Key,
typename T>
42 return Hash()(a.first);
46 template<
typename S0,
typename S1>
80 std::size_t MAX_LOAD_FACTOR_256=128,
81 typename Clearer=MapKeyClearer<Key,T>,
82 class Hash=hboost::hash<Key>,
83 class KeyEqual=std::equal_to<Key>
85 class ArrayMap :
public ArraySet<std::pair<Key,T>,MULTI,MAX_LOAD_FACTOR_256,Clearer,MapKeyHash<Hash,Key,T>,MapKeyEqual<KeyEqual,Key,T> >
88 typedef ArraySet<std::pair<Key,T>,MULTI,MAX_LOAD_FACTOR_256,Clearer,
MapKeyHash<Hash,Key,T>,
MapKeyEqual<KeyEqual,Key,T> >
set_type;
104 template<
bool constant_type>
117 std::pair<iterator, bool>
insert(
const Key &key,
const T &
val)
119 return insert(std::pair<Key,T>(key, val));
123 return insert(std::make_pair(std::forward<Key>(key),
124 std::forward<T>(
val)));
139 if (Clearer::isClear(*p))
152 return !(*
this == that);
164 return iterator(
nullptr,
nullptr,
false);
168 const pointer search_start = searchStart(key);
169 for (
pointer p = search_start; p != pend; ++p)
173 if (Clearer::isClear(*p))
177 for (
pointer p = search_start-1; p >= pstart; --p)
181 if (Clearer::isClear(*p))
201 if (Clearer::isClear(*p))
209 if (Clearer::isClear(*p))
223 auto it = this->
find(key);
224 if (it == this->
end())
238 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
239 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
244 const pointer search_start = searchStart(key);
245 for (
pointer p = search_start; p != pend; ++p)
249 if (Clearer::isClear(*p))
251 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
252 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
256 for (
pointer p = search_start-1; p >= pstart; --p)
260 if (Clearer::isClear(*p))
262 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
263 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
266 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
267 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
269 const T &
at(
const Key &key)
const
273 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
274 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
284 if (Clearer::isClear(*p))
286 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
287 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
295 if (Clearer::isClear(*p))
297 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
298 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
301 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
302 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
327 if (Clearer::isClear(*p))
328 return MULTI ? count : 0;
339 if (Clearer::isClear(*p))
340 return MULTI ? count : 0;
342 return MULTI ? count : 0;
361 if (Clearer::isClear(*p))
369 if (Clearer::isClear(*p))
394 *dest = std::move(value);
395 ++*((
size_type*)(myBuckets+myNumBuckets));
418 *dest = std::move(value);
419 ++*((
size_type*)(myBuckets+myNumBuckets));
426 std::pair<const_iterator,const_iterator>
equal_range(
const Key &key)
const
442 if (Clearer::isClear(*p))
450 if (Clearer::isClear(*p))
466 else if (first_found)
468 if (first_found != search_start)
474 else if (Clearer::isClear(*p))
498 return std::make_pair(
iterator(
nullptr,
nullptr,
false),
iterator(
nullptr,
nullptr,
false));
500 const pointer search_start = searchStart(key);
503 for (
pointer p = search_start; p != pend; ++p)
507 if (Clearer::isClear(*p))
508 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
511 for (
pointer p = search_start-1; p >= pstart; --p)
515 if (Clearer::isClear(*p))
516 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
518 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
524 for (
pointer p = search_start; p != pend; ++p)
531 else if (first_found)
533 if (first_found != search_start)
534 return std::make_pair(
iterator(first_found,pend,
false),
iterator(p,pend,
true));
539 else if (Clearer::isClear(*p))
542 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
547 for (
pointer p = search_start-1; p >= pstart; --p)
551 return std::make_pair(
iterator(p+1,pend,
false),
iterator(end_found,pend,
true));
554 return std::make_pair(
iterator(pstart,pend,
false),
iterator(end_found,pend,
true));
589 template<
typename FUNCTOR>
595 for (; p != pend; ++p)
597 if (!Clearer::isClear(*p))
602 template<
typename FUNCTOR>
608 for (; p != pend; ++p)
610 if (!Clearer::isClear(*p))
615 template<
bool constant_type>
626 template<
typename COMPARATOR>
632 map.forEachKey([
this](
const Key &key) {
635 myKeys.
sort(comparator);
639 , myKeys(std::move(that.myKeys))
644 return *myMap.find(myKeys[myI]);
648 return &*myMap.find(myKeys[myI]);
652 return &*myMap.find(myKeys[myI]);
660 return myI >= myKeys.
size();
672 template<
typename COMPARATOR>
675 return ordered_iterator_t<true>(*
this, comparator);
678 template<
typename COMPARATOR>
681 return ordered_iterator_t<true>(*
this, comparator);
684 template<
typename COMPARATOR>
687 return ordered_iterator_t<false>(*
this, comparator);
691 template<
typename VIT,
typename VT>
696 template<
typename VIT,
typename VT>
702 template<
typename IT,
typename VT,
typename DR>
714 template<
typename EIT,
typename EDR>
722 {
return it == o.it; }
725 {
return it != o.it; }
743 deref_pair_first<const_iterator, const key_type>>;
745 deref_pair_second<iterator, mapped_type>>;
747 deref_pair_second<const_iterator, const mapped_type>>;
779 pointer searchStart(
const Key &key)
795 std::size_t MAX_LOAD_FACTOR_256,
801 :
public DefaultClearer<typename ArrayMap<Key,T,MULTI,MAX_LOAD_FACTOR_256,Clearer,Hash,KeyEqual>::set_type>
806 template<
typename Key,
809 int MAX_LOAD_FACTOR_256 = 128,
811 class Hash = hboost::hash<Key>,
812 class KeyEqual = std::equal_to<Key> >
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::myBuckets pointer myBuckets
UT_IteratorRange< const_mapped_iterator > mapped_range() const
ArrayMap< Key, T, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > map_type
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::insert std::pair< iterator, bool > insert(const value_type &value)
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::size size_type size() const
Returns the number of items in the set.
bool contains(const Key &key) const
STATIC_INLINE size_t Hash(const char *s, size_t len)
SYS_FORCE_INLINE void forEachValue(FUNCTOR &&functor) const
ordered_iterator_t< true > ordered_cbegin(const COMPARATOR &comparator) const
ordered_iterator_t(map_type &map, const COMPARATOR &comparator)
bool operator==(const map_type &that) const
GLsizei const GLfloat * value
T & operator[](Key &&key)
std::conditional< constant_type, typename set_type::const_pointer, typename set_type::pointer >::type pointer
UT_IteratorRange< IterT > UTmakeRange(IterT &&b, IterT &&e)
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
SYS_FORCE_INLINE void forEachKey(FUNCTOR &&functor) const
bool operator==(const partial_iterator_base< IT, VT, DR > &o) const
GLboolean GLboolean GLboolean GLboolean a
partial_iterator_base & operator++()
partial_iterator_base< const_iterator, const mapped_type, deref_pair_second< const_iterator, const mapped_type >> const_mapped_iterator
const T & at(const Key &key) const
void setCapacity(exint new_capacity)
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::end iterator end()
Returns a non-const end iterator for the set.
#define UT_ASSERT_MSG_P(ZZ,...)
std::forward_iterator_tag iterator_category
ordered_iterator_t< true > ordered_begin(const COMPARATOR &comparator) const
pointer operator->() const
reference operator*() const
iterator find(const Key &key)
T & operator[](const Key &key)
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::set_type ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > > set_type
std::conditional< constant_type, const typename ArrayMap::map_type, typename ArrayMap::map_type >::type map_type
#define UT_ASSERT_MSG(ZZ,...)
std::conditional< constant_type, const value_type, value_type >::type & reference
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::erase iterator erase(iterator iter)
bool operator()(const std::pair< Key, T > &a, const std::pair< Key, T > &b) const
typename set_type::const_pointer const_pointer
std::ptrdiff_t difference_type
typename set_type::size_type size_type
partial_iterator_base< const_iterator, const key_type, deref_pair_first< const_iterator, const key_type >> const_key_iterator
static void clearConstruct(std::pair< S0, S1 > *p)
std::pair< iterator, iterator > equal_range(const Key &key)
void sort(ComparatorBool is_less={})
Sort using std::sort with bool comparator. Defaults to operator<().
size_t operator()(const std::pair< Key, T > &a) const
std::pair< iterator, bool > insert(const Key &key, const T &val)
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::begin iterator begin()
Returns a non-const iterator for the beginning of the set.
pointer operator->() const
partial_iterator_base(const partial_iterator_base< EIT, VT, EDR > &src)
ordered_iterator_t(ordered_iterator_t< constant_type > &&that)
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::myNumBuckets size_type myNumBuckets
static const bool clearNeedsDestruction
size_type erase(const Key &key)
GLboolean GLboolean GLboolean b
static bool isClear(const std::pair< S0, S1 > &v)
std::ptrdiff_t difference_type
partial_iterator_base< iterator, mapped_type, deref_pair_second< iterator, mapped_type >> mapped_iterator
ordered_iterator_t< false > ordered_begin(const COMPARATOR &comparator)
std::conditional< constant_type, const typename ArrayMap::value_type, typename ArrayMap::value_type >::type value_type
const_iterator find(const Key &key) const
size_type count(const Key &key) const
static bool isClear(const S0 &v)
An overload for when there's only a key.
bool operator!=(const map_type &that) const
bool operator!=(const partial_iterator_base< IT, VT, DR > &o) const
typename set_type::iterator iterator
Inherit iterator and const_iterator.
VT & operator()(const VIT &v) const
const value_type * const_pointer
partial_iterator_base(IT it)
static void clear(std::pair< S0, S1 > &v)
typename set_type::template iterator_t< constant_type > iterator_t
UT::ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > >::iterator iterator_t< false > iterator
Iterator type for iterating over non-constant elements.
reference operator*() const
std::pair< iterator, bool > insert(Key &&key, T &&val)
VT & operator()(const VIT &v) const
std::forward_iterator_tag iterator_category
UT_IteratorRange< const_key_iterator > key_range() const
typename set_type::const_iterator const_iterator
UT_IteratorRange< mapped_iterator > mapped_range()
ArraySet< std::pair< Key, T >, MULTI, MAX_LOAD_FACTOR_256, Clearer, MapKeyHash< Hash, Key, T >, MapKeyEqual< KeyEqual, Key, T > > set_type