14 #ifndef STXXL_MAP_HEADER
15 #define STXXL_MAP_HEADER
17 #include <stxxl/bits/noncopyable.h>
18 #include <stxxl/bits/containers/btree/btree.h>
21 __STXXL_BEGIN_NAMESPACE
25 template <
class KeyType,
73 template <
class KeyType,
76 unsigned RawNodeSize = 16 * 1024,
77 unsigned RawLeafSize = 128 * 1024,
78 class PDAllocStrategy = stxxl::SR
80 class map :
private noncopyable
82 typedef btree::btree<KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy> impl_type;
90 typedef typename impl_type::key_type key_type;
91 typedef typename impl_type::data_type data_type;
92 typedef typename impl_type::data_type mapped_type;
93 typedef typename impl_type::value_type value_type;
94 typedef typename impl_type::key_compare key_compare;
95 typedef typename impl_type::value_compare value_compare;
96 typedef typename impl_type::pointer pointer;
97 typedef typename impl_type::const_pointer const_pointer;
98 typedef typename impl_type::reference reference;
99 typedef typename impl_type::const_reference const_reference;
100 typedef typename impl_type::size_type size_type;
101 typedef typename impl_type::difference_type difference_type;
102 typedef typename impl_type::iterator iterator;
103 typedef typename impl_type::const_iterator const_iterator;
104 typedef std::reverse_iterator<iterator> reverse_iterator;
105 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
107 iterator begin() {
return Impl.begin(); }
108 iterator end() {
return Impl.end(); }
109 const_iterator begin()
const {
return Impl.begin(); }
110 const_iterator end()
const {
return Impl.end(); }
111 const_iterator cbegin()
const {
return begin(); }
112 const_iterator cend()
const {
return end(); }
114 reverse_iterator rbegin()
116 return reverse_iterator(end());
118 const_reverse_iterator rbegin()
const
120 return const_reverse_iterator(end());
122 const_reverse_iterator crbegin()
const
124 return const_reverse_iterator(end());
126 reverse_iterator rend()
128 return reverse_iterator(begin());
130 const_reverse_iterator rend()
const
132 return const_reverse_iterator(begin());
134 const_reverse_iterator crend()
const
136 return const_reverse_iterator(begin());
139 size_type size()
const {
return Impl.size(); }
140 size_type max_size()
const {
return Impl.max_size(); }
141 bool empty()
const {
return Impl.empty(); }
142 key_compare key_comp()
const {
return Impl.key_comp(); }
143 value_compare value_comp()
const {
return Impl.value_comp(); }
148 map(unsigned_type node_cache_size_in_bytes,
149 unsigned_type leaf_cache_size_in_bytes
150 ) : Impl(node_cache_size_in_bytes, leaf_cache_size_in_bytes)
157 map(
const key_compare & c_,
158 unsigned_type node_cache_size_in_bytes,
159 unsigned_type leaf_cache_size_in_bytes
160 ) : Impl(c_, node_cache_size_in_bytes, leaf_cache_size_in_bytes)
172 template <
class InputIterator>
175 unsigned_type node_cache_size_in_bytes,
176 unsigned_type leaf_cache_size_in_bytes,
177 bool range_sorted =
false,
178 double node_fill_factor = 0.75,
179 double leaf_fill_factor = 0.6
180 ) : Impl(b, e, node_cache_size_in_bytes, leaf_cache_size_in_bytes,
181 range_sorted, node_fill_factor, leaf_fill_factor)
194 template <
class InputIterator>
197 const key_compare & c_,
198 unsigned_type node_cache_size_in_bytes,
199 unsigned_type leaf_cache_size_in_bytes,
200 bool range_sorted =
false,
201 double node_fill_factor = 0.75,
202 double leaf_fill_factor = 0.6
203 ) : Impl(b, e, c_, node_cache_size_in_bytes, leaf_cache_size_in_bytes,
204 range_sorted, node_fill_factor, leaf_fill_factor)
207 void swap(
map & obj) { std::swap(Impl, obj.Impl); }
208 std::pair<iterator, bool> insert(
const value_type & x)
210 return Impl.insert(x);
212 iterator insert(iterator pos,
const value_type & x)
214 return Impl.insert(pos, x);
216 template <
class InputIterator>
217 void insert(InputIterator b, InputIterator e)
221 void erase(iterator pos)
225 size_type erase(
const key_type & k)
227 return Impl.erase(k);
229 void erase(iterator first, iterator last)
231 Impl.erase(first, last);
237 iterator find(
const key_type & k)
241 const_iterator find(
const key_type & k)
const
245 size_type count(
const key_type & k)
247 return Impl.count(k);
249 iterator lower_bound(
const key_type & k)
251 return Impl.lower_bound(k);
253 const_iterator lower_bound(
const key_type & k)
const
255 return Impl.lower_bound(k);
257 iterator upper_bound(
const key_type & k)
259 return Impl.upper_bound(k);
261 const_iterator upper_bound(
const key_type & k)
const
263 return Impl.upper_bound(k);
265 std::pair<iterator, iterator> equal_range(
const key_type & k)
267 return Impl.equal_range(k);
269 std::pair<const_iterator, const_iterator> equal_range(
const key_type & k)
const
271 return Impl.equal_range(k);
273 data_type & operator [] (
const key_type & k)
281 Impl.enable_prefetching();
287 Impl.disable_prefetching();
293 return Impl.prefetching_enabled();
299 Impl.print_statistics(o);
305 Impl.reset_statistics();
309 template <
class KeyType_,
312 unsigned RawNodeSize_,
313 unsigned RawLeafSize_,
314 class PDAllocStrategy_>
318 template <
class KeyType_,
321 unsigned RawNodeSize_,
322 unsigned RawLeafSize_,
323 class PDAllocStrategy_>
324 friend bool operator < (const map<KeyType_, DataType_, CompareType_, RawNodeSize_, RawLeafSize_, PDAllocStrategy_> & a,
327 template <
class KeyType_,
330 unsigned RawNodeSize_,
331 unsigned RawLeafSize_,
332 class PDAllocStrategy_>
336 template <
class KeyType_,
339 unsigned RawNodeSize_,
340 unsigned RawLeafSize_,
341 class PDAllocStrategy_>
345 template <
class KeyType_,
348 unsigned RawNodeSize_,
349 unsigned RawLeafSize_,
350 class PDAllocStrategy_>
351 friend bool operator <= (const map<KeyType_, DataType_, CompareType_, RawNodeSize_, RawLeafSize_, PDAllocStrategy_> & a,
354 template <
class KeyType_,
357 unsigned RawNodeSize_,
358 unsigned RawLeafSize_,
359 class PDAllocStrategy_>
365 template <
class KeyType,
368 unsigned RawNodeSize,
369 unsigned RawLeafSize,
370 class PDAllocStrategy
375 return a.Impl == b.Impl;
378 template <
class KeyType,
381 unsigned RawNodeSize,
382 unsigned RawLeafSize,
383 class PDAllocStrategy
385 inline bool operator < (const map<KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy> & a,
388 return a.Impl < b.Impl;
391 template <
class KeyType,
394 unsigned RawNodeSize,
395 unsigned RawLeafSize,
396 class PDAllocStrategy
401 return a.Impl > b.Impl;
404 template <
class KeyType,
407 unsigned RawNodeSize,
408 unsigned RawLeafSize,
409 class PDAllocStrategy
414 return a.Impl != b.Impl;
417 template <
class KeyType,
420 unsigned RawNodeSize,
421 unsigned RawLeafSize,
422 class PDAllocStrategy
424 inline bool operator <= (const map<KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy> & a,
427 return a.Impl <= b.Impl;
430 template <
class KeyType,
433 unsigned RawNodeSize,
434 unsigned RawLeafSize,
435 class PDAllocStrategy
440 return a.Impl >= b.Impl;
445 __STXXL_END_NAMESPACE
449 template <
class KeyType,
452 unsigned RawNodeSize,
453 unsigned RawLeafSize,
454 class PDAllocStrategy
456 void swap(stxxl::map<KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy> & a,
457 stxxl::map<KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy> & b
464 #endif // !STXXL_MAP_HEADER
void print_statistics(std::ostream &o) const
Prints cache statistics.
Definition: map.h:297
Block containing elements of fixed length.
Definition: typed_block.h:223
bool prefetching_enabled()
Returns the status of leaf prefetching during scanning.
Definition: map.h:291
void enable_prefetching()
Enables leaf prefetching during scanning.
Definition: map.h:279
External associative container.
Definition: map.h:80
map(unsigned_type node_cache_size_in_bytes, unsigned_type leaf_cache_size_in_bytes)
A constructor.
Definition: map.h:148
map(InputIterator b, InputIterator e, unsigned_type node_cache_size_in_bytes, unsigned_type leaf_cache_size_in_bytes, bool range_sorted=false, double node_fill_factor=0.75, double leaf_fill_factor=0.6)
Constructs a map from a given input range.
Definition: map.h:173
void reset_statistics()
Resets cache statistics.
Definition: map.h:303
void disable_prefetching()
Disables leaf prefetching during scanning.
Definition: map.h:285
map(InputIterator b, InputIterator e, const key_compare &c_, unsigned_type node_cache_size_in_bytes, unsigned_type leaf_cache_size_in_bytes, bool range_sorted=false, double node_fill_factor=0.75, double leaf_fill_factor=0.6)
Constructs a map from a given input range.
Definition: map.h:195
map(const key_compare &c_, unsigned_type node_cache_size_in_bytes, unsigned_type leaf_cache_size_in_bytes)
A constructor.
Definition: map.h:157