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))
225 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
226 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
231 const pointer search_start = searchStart(key);
232 for (
pointer p = search_start; p != pend; ++p)
236 if (Clearer::isClear(*p))
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 &)");
243 for (
pointer p = search_start-1; p >= pstart; --p)
247 if (Clearer::isClear(*p))
249 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
250 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
253 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap::at!");
254 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &)");
256 const T &
at(
const Key &key)
const
260 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
261 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
271 if (Clearer::isClear(*p))
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");
282 if (Clearer::isClear(*p))
284 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
285 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
288 UT_ASSERT_MSG(0,
"WARNING! An exception is about to be thrown in UT::ArrayMap!");
289 throw std::out_of_range(
"Key not found in UT::ArrayMap::at(const Key &) const");
314 if (Clearer::isClear(*p))
315 return MULTI ? count : 0;
326 if (Clearer::isClear(*p))
327 return MULTI ? count : 0;
329 return MULTI ? count : 0;
348 if (Clearer::isClear(*p))
356 if (Clearer::isClear(*p))
381 *dest = std::move(value);
382 ++*((
size_type*)(myBuckets+myNumBuckets));
405 *dest = std::move(value);
406 ++*((
size_type*)(myBuckets+myNumBuckets));
413 std::pair<const_iterator,const_iterator>
equal_range(
const Key &key)
const
429 if (Clearer::isClear(*p))
437 if (Clearer::isClear(*p))
453 else if (first_found)
455 if (first_found != search_start)
461 else if (Clearer::isClear(*p))
485 return std::make_pair(
iterator(
nullptr,
nullptr,
false),
iterator(
nullptr,
nullptr,
false));
487 const pointer search_start = searchStart(key);
490 for (
pointer p = search_start; p != pend; ++p)
494 if (Clearer::isClear(*p))
495 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
498 for (
pointer p = search_start-1; p >= pstart; --p)
502 if (Clearer::isClear(*p))
503 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
505 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
511 for (
pointer p = search_start; p != pend; ++p)
518 else if (first_found)
520 if (first_found != search_start)
521 return std::make_pair(
iterator(first_found,pend,
false),
iterator(p,pend,
true));
526 else if (Clearer::isClear(*p))
529 return std::make_pair(
iterator(pend,pend,
false),
iterator(pend,pend,
false));
534 for (
pointer p = search_start-1; p >= pstart; --p)
538 return std::make_pair(
iterator(p+1,pend,
false),
iterator(end_found,pend,
true));
541 return std::make_pair(
iterator(pstart,pend,
false),
iterator(end_found,pend,
true));
576 template<
typename FUNCTOR>
582 for (; p != pend; ++p)
584 if (!Clearer::isClear(*p))
589 template<
typename FUNCTOR>
595 for (; p != pend; ++p)
597 if (!Clearer::isClear(*p))
602 template<
bool constant_type>
613 template<
typename COMPARATOR>
619 map.forEachKey([
this](
const Key &key) {
622 myKeys.
sort(comparator);
626 , myKeys(std::move(that.myKeys))
631 return *myMap.find(myKeys[myI]);
635 return &*myMap.find(myKeys[myI]);
639 return &*myMap.find(myKeys[myI]);
647 return myI >= myKeys.
size();
659 template<
typename COMPARATOR>
662 return ordered_iterator_t<true>(*
this, comparator);
665 template<
typename COMPARATOR>
668 return ordered_iterator_t<true>(*
this, comparator);
671 template<
typename COMPARATOR>
674 return ordered_iterator_t<false>(*
this, comparator);
678 template<
typename VIT,
typename VT>
683 template<
typename VIT,
typename VT>
689 template<
typename IT,
typename VT,
typename DR>
701 template<
typename EIT,
typename EDR>
709 {
return it == o.it; }
712 {
return it != o.it; }
730 deref_pair_first<const_iterator, const key_type>>;
732 deref_pair_second<iterator, mapped_type>>;
734 deref_pair_second<const_iterator, const mapped_type>>;
766 pointer searchStart(
const Key &key)
782 std::size_t MAX_LOAD_FACTOR_256,
788 :
public DefaultClearer<typename ArrayMap<Key,T,MULTI,MAX_LOAD_FACTOR_256,Clearer,Hash,KeyEqual>::set_type>
793 template<
typename Key,
796 int MAX_LOAD_FACTOR_256 = 128,
798 class Hash = hboost::hash<Key>,
799 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