11 #ifndef EASTL_FIXED_MAP_H
12 #define EASTL_FIXED_MAP_H
15 #include <EASTL/map.h>
16 #include <EASTL/fixed_set.h>
18 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
32 #ifndef EASTL_FIXED_MAP_DEFAULT_NAME
33 #define EASTL_FIXED_MAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_map"
36 #ifndef EASTL_FIXED_MULTIMAP_DEFAULT_NAME
37 #define EASTL_FIXED_MULTIMAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_multimap"
44 #ifndef EASTL_FIXED_MAP_DEFAULT_ALLOCATOR
45 #define EASTL_FIXED_MAP_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_MAP_DEFAULT_NAME)
48 #ifndef EASTL_FIXED_MULTIMAP_DEFAULT_ALLOCATOR
49 #define EASTL_FIXED_MULTIMAP_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_MULTIMAP_DEFAULT_NAME)
66 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow = true,
typename Compare = eastl::less<Key>,
typename OverflowAllocator = EASTLAllocatorType>
67 class fixed_map :
public map<Key, T, Compare, fixed_node_allocator<sizeof(typename map<Key, T>::node_type),
68 nodeCount, EASTL_ALIGN_OF(eastl::pair<Key, T>), 0, bEnableOverflow, OverflowAllocator> >
73 typedef typename fixed_allocator_type::overflow_allocator_type overflow_allocator_type;
76 typedef typename base_type::value_type value_type;
78 typedef typename base_type::size_type size_type;
80 enum { kMaxSize = nodeCount };
82 using base_type::insert;
85 char mBuffer[fixed_allocator_type::kBufferSize];
91 explicit fixed_map(
const overflow_allocator_type& overflowAllocator);
92 explicit fixed_map(
const Compare& compare);
98 template <
typename InputIterator>
99 fixed_map(InputIterator first, InputIterator last);
107 void reset_lose_memory();
109 size_type max_size()
const;
111 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
112 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
113 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
131 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow = true,
typename Compare = eastl::less<Key>,
typename OverflowAllocator = EASTLAllocatorType>
132 class fixed_multimap :
public multimap<Key, T, Compare, fixed_node_allocator<sizeof(typename multimap<Key, T>::node_type),
133 nodeCount, EASTL_ALIGN_OF(eastl::pair<Key, T>), 0, bEnableOverflow, OverflowAllocator> >
138 typedef typename fixed_allocator_type::overflow_allocator_type overflow_allocator_type;
141 typedef typename base_type::value_type value_type;
143 typedef typename base_type::size_type size_type;
145 enum { kMaxSize = nodeCount };
147 using base_type::insert;
150 char mBuffer[fixed_allocator_type::kBufferSize];
153 using base_type::get_compare;
164 template <
typename InputIterator>
173 void reset_lose_memory();
175 size_type max_size()
const;
177 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
178 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
179 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
190 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
192 : base_type(fixed_allocator_type(mBuffer))
194 #if EASTL_NAME_ENABLED
195 mAllocator.set_name(EASTL_FIXED_MAP_DEFAULT_NAME);
200 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
201 inline fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(
const overflow_allocator_type& overflowAllocator)
202 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
204 #if EASTL_NAME_ENABLED
205 mAllocator.set_name(EASTL_FIXED_MAP_DEFAULT_NAME);
210 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
211 inline fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(
const Compare& compare)
212 : base_type(compare, fixed_allocator_type(mBuffer))
214 #if EASTL_NAME_ENABLED
215 mAllocator.set_name(EASTL_FIXED_MAP_DEFAULT_NAME);
220 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
221 inline fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(
const this_type& x)
222 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
224 mAllocator.copy_overflow_allocator(x.mAllocator);
226 #if EASTL_NAME_ENABLED
230 base_type::operator=(x);
234 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
235 inline fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(this_type&& x)
236 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
238 mAllocator.copy_overflow_allocator(x.mAllocator);
240 #if EASTL_NAME_ENABLED
244 base_type::operator=(x);
248 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
249 inline fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(this_type&& x,
const overflow_allocator_type& overflowAllocator)
250 : base_type(x.get_compare(), fixed_allocator_type(mBuffer, overflowAllocator))
252 mAllocator.copy_overflow_allocator(x.mAllocator);
254 #if EASTL_NAME_ENABLED
258 base_type::operator=(x);
262 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
263 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(
std::initializer_list<value_type> ilist,
const overflow_allocator_type& overflowAllocator)
264 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
266 #if EASTL_NAME_ENABLED
267 mAllocator.set_name(EASTL_FIXED_MAP_DEFAULT_NAME);
270 insert(ilist.begin(), ilist.end());
274 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
275 template <
typename InputIterator>
276 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_map(InputIterator first, InputIterator last)
277 : base_type(fixed_allocator_type(mBuffer))
279 #if EASTL_NAME_ENABLED
280 mAllocator.set_name(EASTL_FIXED_MAP_DEFAULT_NAME);
287 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
288 inline typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
289 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(
const this_type& x)
291 base_type::operator=(x);
296 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
297 inline typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
301 insert(ilist.begin(), ilist.end());
306 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
307 inline typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
308 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(this_type&& x)
310 base_type::operator=(x);
315 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
316 inline void fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::swap(this_type& x)
319 eastl::fixed_swap(*
this, x);
323 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
324 inline void fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::reset_lose_memory()
326 base_type::reset_lose_memory();
327 base_type::get_allocator().reset(mBuffer);
331 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
332 inline typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::size_type
333 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::max_size()
const
339 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
340 inline const typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
341 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
343 return mAllocator.get_overflow_allocator();
347 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
348 inline typename fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
349 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
351 return mAllocator.get_overflow_allocator();
355 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
357 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
359 mAllocator.set_overflow_allocator(allocator);
366 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
367 inline void swap(fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& a,
368 fixed_map<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& b)
371 eastl::fixed_swap(a, b);
381 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
382 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap()
383 : base_type(fixed_allocator_type(mBuffer))
385 #if EASTL_NAME_ENABLED
386 mAllocator.set_name(EASTL_FIXED_MULTIMAP_DEFAULT_NAME);
391 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
392 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(
const overflow_allocator_type& overflowAllocator)
393 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
395 #if EASTL_NAME_ENABLED
396 mAllocator.set_name(EASTL_FIXED_MULTIMAP_DEFAULT_NAME);
401 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
402 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(
const Compare& compare)
403 : base_type(compare, fixed_allocator_type(mBuffer))
405 #if EASTL_NAME_ENABLED
406 mAllocator.set_name(EASTL_FIXED_MULTIMAP_DEFAULT_NAME);
411 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
412 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(
const this_type& x)
413 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
415 mAllocator.copy_overflow_allocator(x.mAllocator);
417 #if EASTL_NAME_ENABLED
421 base_type::operator=(x);
425 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
426 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(this_type&& x)
427 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
429 mAllocator.copy_overflow_allocator(x.mAllocator);
431 #if EASTL_NAME_ENABLED
435 base_type::operator=(x);
439 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
440 inline fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(this_type&& x,
const overflow_allocator_type& overflowAllocator)
441 : base_type(x.get_compare(), fixed_allocator_type(mBuffer, overflowAllocator))
443 mAllocator.copy_overflow_allocator(x.mAllocator);
445 #if EASTL_NAME_ENABLED
449 base_type::operator=(x);
453 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
454 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multimap(
std::initializer_list<value_type> ilist,
const overflow_allocator_type& overflowAllocator)
455 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
457 #if EASTL_NAME_ENABLED
458 mAllocator.set_name(EASTL_FIXED_MULTIMAP_DEFAULT_NAME);
461 insert(ilist.begin(), ilist.end());
465 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
466 template <
typename InputIterator>
467 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::
468 fixed_multimap(InputIterator first, InputIterator last)
469 : base_type(fixed_allocator_type(mBuffer))
471 #if EASTL_NAME_ENABLED
472 mAllocator.set_name(EASTL_FIXED_MULTIMAP_DEFAULT_NAME);
479 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
480 inline typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
481 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(
const this_type& x)
483 base_type::operator=(x);
488 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
489 inline typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
493 insert(ilist.begin(), ilist.end());
498 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
499 inline typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
500 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(this_type&& x)
502 base_type::operator=(x);
507 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
508 inline void fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::swap(this_type& x)
511 eastl::fixed_swap(*
this, x);
515 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
516 inline void fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::reset_lose_memory()
518 base_type::reset_lose_memory();
519 base_type::get_allocator().reset(mBuffer);
523 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
524 inline typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::size_type
525 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::max_size()
const
531 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
532 inline const typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
533 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
535 return mAllocator.get_overflow_allocator();
539 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
540 inline typename fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
541 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
543 return mAllocator.get_overflow_allocator();
547 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
549 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
551 mAllocator.set_overflow_allocator(allocator);
559 template <
typename Key,
typename T,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
560 inline void swap(fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& a,
561 fixed_multimap<Key, T, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& b)
564 eastl::fixed_swap(a, b);
Definition: allocator.h:52
Definition: fixed_map.h:69
Definition: fixed_map.h:134
insert_return_type insert(const Key &key)
Definition: map.h:556
Definition: fixed_pool.h:607
allocator_type mAllocator
Stores the count of nodes in the tree (not counting the anchor node).
Definition: red_black_tree.h:422
Definition: initializer_list.h:38
EA Standard Template Library.
Definition: algorithm.h:288
Definition: utility.h:371
Definition: red_black_tree.h:108