20 #ifndef GALOIS_FLATMAP_H
21 #define GALOIS_FLATMAP_H
25 #include <type_traits>
28 #include "galois/config.h"
33 template <
class _Key,
class _Tp,
class _Compare = std::less<_Key>,
34 class _Alloc = std::allocator<std::pair<_Key, _Tp>>,
35 class _Store = std::vector<std::pair<_Key, _Tp>, _Alloc>>
45 :
public std::binary_function<value_type, value_type, bool> {
46 friend class flat_map<_Key, _Tp, _Compare, _Alloc, _Store>;
55 return comp(__x.first, __y.first);
61 typedef typename _Alloc::template rebind<value_type>::other _Pair_alloc_type;
63 typedef _Store _VectTy;
67 class value_key_compare
68 :
public std::binary_function<value_type, key_type, bool> {
69 friend class flat_map<_Key, _Tp, _Compare, _Alloc, _Store>;
74 value_key_compare(_Compare __c) : comp(__c) {}
78 return comp(__x.first, __y);
82 value_key_compare value_key_comp()
const {
83 return value_key_compare(
key_comp());
93 typedef typename _Pair_alloc_type::pointer
pointer;
95 typedef typename _Pair_alloc_type::reference
reference;
109 : _data(), _comp(__comp) {}
115 : _data(std::move(__x._data)), _comp(std::move(__x._comp)) {}
124 template <
typename _InputIterator>
125 flat_map(_InputIterator __first, _InputIterator __last)
126 : _data(__first, __last), _comp() {
130 template <
typename _InputIterator>
131 flat_map(_InputIterator __first, _InputIterator __last,
const _Compare&,
133 : _data(__first, __last, _Pair_alloc_type(__a)) {
169 return _data.rbegin();
176 return _data.rbegin();
180 bool empty() const {
return _data.empty(); }
184 template <
typename... Args>
185 std::pair<iterator, bool>
emplace(Args&&... args) {
190 _data.emplace_back(std::forward<Args>(args)...);
192 auto ee = _data.end();
194 auto __i = std::lower_bound(_data.begin(), ee, v.first, value_key_comp());
196 bool retval = __i == ee ||
key_comp()(v.first, (*__i).first);
200 __i = _data.emplace(__i, std::move(tmp));
207 return std::make_pair(__i, retval);
214 __i = _data.emplace(__i, std::piecewise_construct,
215 std::forward_as_tuple(__k), std::tuple<>());
216 return (*__i).second;
224 _data.emplace(__i, std::piecewise_construct,
225 std::forward_as_tuple(std::move(__k)), std::tuple<>());
226 return (*__i).second;
232 throw std::out_of_range(
"flat_map::at");
233 return (*__i).second;
239 throw std::out_of_range(
"flat_map::at");
240 return (*__i).second;
243 template <
typename PairTy,
244 typename =
typename std::enable_if<
245 std::is_constructible<value_type, PairTy&&>::value>::type>
246 std::pair<iterator, bool>
insert(PairTy&& __x) {
247 return emplace(std::forward<PairTy>(__x));
256 template <
typename _InputIterator>
257 void insert(_InputIterator __first, _InputIterator __last) {
258 while (__first != __last)
275 return _data.erase(__first, __last);
279 _data.swap(__x._data);
280 std::swap(_comp, __x._comp);
290 if (i !=
end() && key_eq(i->first, __x))
297 if (i !=
end() && key_eq(i->first, __x))
303 return find(__x) ==
end() ? 0 : 1;
307 return std::lower_bound(_data.begin(), _data.end(), __x, value_key_comp());
310 return std::lower_bound(_data.begin(), _data.end(), __x, value_key_comp());
314 return std::upper_bound(_data.begin(), _data.end(), __x, value_key_comp());
317 return std::upper_bound(_data.begin(), _data.end(), __x, value_key_comp());
324 std::pair<const_iterator, const_iterator>
330 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
333 return __x._data == __y._data;
336 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
337 inline bool operator<(const flat_map<_Key, _Tp, _Compare, _Alloc>& __x,
339 return __x._data < __y._data;
343 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
346 return !(__x == __y);
350 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
357 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
358 inline bool operator<=(const flat_map<_Key, _Tp, _Compare, _Alloc>& __x,
364 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
375 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
const_iterator cbegin() const
Definition: FlatMap.h:173
flat_map(_InputIterator __first, _InputIterator __last, const _Compare &, const allocator_type &__a=allocator_type())
Definition: FlatMap.h:131
size_type count(const key_type &__x) const
Definition: FlatMap.h:302
void clear()
Definition: FlatMap.h:283
std::pair< iterator, bool > emplace(Args &&...args)
Definition: FlatMap.h:185
flat_map(const _Compare &__comp, const allocator_type &=allocator_type())
Definition: FlatMap.h:106
_Key key_type
Definition: FlatMap.h:38
_VectTy::const_iterator const_iterator
Definition: FlatMap.h:98
const_iterator begin() const
Definition: FlatMap.h:164
const_iterator end() const
Definition: FlatMap.h:166
const_iterator upper_bound(const key_type &__x) const
Definition: FlatMap.h:316
const_iterator find(const key_type &__x) const
Definition: FlatMap.h:295
flat_map & operator=(const flat_map &__x)
Definition: FlatMap.h:137
std::pair< _Key, _Tp > value_type
Definition: FlatMap.h:40
_Alloc allocator_type
Definition: FlatMap.h:42
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Definition: FlatMap.h:325
mapped_type & operator[](const key_type &__k)
Definition: FlatMap.h:210
value_compare value_comp() const
Definition: FlatMap.h:286
bool operator!=(const flat_map< _Key, _Tp, _Compare, _Alloc > &__x, const flat_map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
Definition: FlatMap.h:344
const_iterator cend() const
Definition: FlatMap.h:174
void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp)
Definition: ParallelSTL.h:247
value_compare(_Compare __c)
Definition: FlatMap.h:51
bool operator()(const value_type &__x, const value_type &__y) const
Definition: FlatMap.h:54
std::pair< iterator, bool > insert(PairTy &&__x)
Definition: FlatMap.h:246
std::pair< iterator, iterator > equal_range(const key_type &__x)
Definition: FlatMap.h:320
const_reverse_iterator rend() const
Definition: FlatMap.h:172
iterator lower_bound(const key_type &__x)
Definition: FlatMap.h:306
iterator upper_bound(const key_type &__x)
Definition: FlatMap.h:313
_Pair_alloc_type::const_reference const_reference
Definition: FlatMap.h:96
_Pair_alloc_type::reference reference
Definition: FlatMap.h:95
_Pair_alloc_type::pointer pointer
Definition: FlatMap.h:93
_Compare key_compare
Definition: FlatMap.h:41
Simple map data structure, based off a single array.
Definition: FlatMap.h:36
const_reverse_iterator rbegin() const
Definition: FlatMap.h:168
iterator erase(const_iterator __first, const_iterator __last)
Definition: FlatMap.h:274
key_compare key_comp() const
Definition: FlatMap.h:285
_VectTy::size_type size_type
Definition: FlatMap.h:99
flat_map()
Definition: FlatMap.h:104
_VectTy::const_reverse_iterator const_reverse_iterator
Definition: FlatMap.h:102
void operator()(void)
Definition: Executor_ParaMeter.h:417
const mapped_type & at(const key_type &__k) const
Definition: FlatMap.h:236
_Pair_alloc_type::const_pointer const_pointer
Definition: FlatMap.h:94
size_type erase(const key_type &__x)
Definition: FlatMap.h:265
const_reverse_iterator crend() const
Definition: FlatMap.h:178
size_type size() const
Definition: FlatMap.h:181
_VectTy::iterator iterator
Definition: FlatMap.h:97
bool operator>=(const flat_map< _Key, _Tp, _Compare, _Alloc > &__x, const flat_map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: FlatMap.h:365
void insert(_InputIterator __first, _InputIterator __last)
Definition: FlatMap.h:257
const_iterator lower_bound(const key_type &__x) const
Definition: FlatMap.h:309
bool operator==(const flat_map< _Key, _Tp, _Compare, _Alloc > &__x, const flat_map< _Key, _Tp, _Compare, _Alloc > &__y)
Definition: FlatMap.h:331
_VectTy::reverse_iterator reverse_iterator
Definition: FlatMap.h:101
bool operator>(const flat_map< _Key, _Tp, _Compare, _Alloc > &__x, const flat_map< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
Definition: FlatMap.h:351
iterator find(const key_type &__x)
Definition: FlatMap.h:288
reverse_iterator rbegin()
Definition: FlatMap.h:167
mapped_type & operator[](key_type &&__k)
Definition: FlatMap.h:219
size_type max_size() const
Definition: FlatMap.h:182
iterator erase(const_iterator __position)
Definition: FlatMap.h:262
_Compare comp
Definition: FlatMap.h:49
mapped_type & at(const key_type &__k)
Definition: FlatMap.h:229
_VectTy::difference_type difference_type
Definition: FlatMap.h:100
allocator_type get_allocator() const
Definition: FlatMap.h:157
flat_map(_InputIterator __first, _InputIterator __last)
Definition: FlatMap.h:125
iterator end()
Definition: FlatMap.h:165
flat_map & operator=(flat_map &&__x)
Definition: FlatMap.h:143
T value_type
Definition: Executor_ParaMeter.h:111
const_reverse_iterator crbegin() const
Definition: FlatMap.h:175
_Tp mapped_type
Definition: FlatMap.h:39
reverse_iterator rend()
Definition: FlatMap.h:171
iterator erase(iterator __position)
Definition: FlatMap.h:263
bool empty() const
Definition: FlatMap.h:180
void swap(flat_map &__x)
Definition: FlatMap.h:278
flat_map(const flat_map &__x)
Definition: FlatMap.h:111
iterator begin()
Definition: FlatMap.h:163