11 #ifndef EASTL_FIXED_SET_H
12 #define EASTL_FIXED_SET_H
15 #include <EASTL/set.h>
16 #include <EASTL/internal/fixed_pool.h>
18 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
32 #ifndef EASTL_FIXED_SET_DEFAULT_NAME
33 #define EASTL_FIXED_SET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_set"
36 #ifndef EASTL_FIXED_MULTISET_DEFAULT_NAME
37 #define EASTL_FIXED_MULTISET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixed_multiset"
44 #ifndef EASTL_FIXED_SET_DEFAULT_ALLOCATOR
45 #define EASTL_FIXED_SET_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_SET_DEFAULT_NAME)
48 #ifndef EASTL_FIXED_MULTISET_DEFAULT_ALLOCATOR
49 #define EASTL_FIXED_MULTISET_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_MULTISET_DEFAULT_NAME)
66 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow = true,
typename Compare = eastl::less<Key>,
typename OverflowAllocator = EASTLAllocatorType>
67 class fixed_set :
public set<Key, Compare, fixed_node_allocator<sizeof(typename set<Key>::node_type),
68 nodeCount, EASTL_ALIGN_OF(Key), 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];
88 using base_type::get_compare;
92 fixed_set(
const overflow_allocator_type& overflowAllocator);
93 explicit fixed_set(
const Compare& compare);
99 template <
typename InputIterator>
100 fixed_set(InputIterator first, InputIterator last);
108 void reset_lose_memory();
110 size_type max_size()
const;
112 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
113 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
114 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
133 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow = true,
typename Compare = eastl::less<Key>,
typename OverflowAllocator = EASTLAllocatorType>
135 nodeCount, EASTL_ALIGN_OF(Key), 0, bEnableOverflow, OverflowAllocator> >
140 typedef typename fixed_allocator_type::overflow_allocator_type overflow_allocator_type;
143 typedef typename base_type::value_type value_type;
145 typedef typename base_type::size_type size_type;
147 enum { kMaxSize = nodeCount };
149 using base_type::insert;
152 char mBuffer[fixed_allocator_type::kBufferSize];
165 template <
typename InputIterator>
174 void reset_lose_memory();
176 size_type max_size()
const;
178 const overflow_allocator_type& get_overflow_allocator()
const EA_NOEXCEPT;
179 overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
180 void set_overflow_allocator(
const overflow_allocator_type&
allocator);
190 template <
typename Key,
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_SET_DEFAULT_NAME);
200 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
201 inline fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(
const overflow_allocator_type& overflowAllocator)
202 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
204 #if EASTL_NAME_ENABLED
205 mAllocator.set_name(EASTL_FIXED_SET_DEFAULT_NAME);
210 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
211 inline fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(
const Compare& compare)
212 : base_type(compare, fixed_allocator_type(mBuffer))
214 #if EASTL_NAME_ENABLED
215 mAllocator.set_name(EASTL_FIXED_SET_DEFAULT_NAME);
220 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
221 inline fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(
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,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
235 inline fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(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,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
249 inline fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(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,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
263 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(
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_SET_DEFAULT_NAME);
270 insert(ilist.begin(), ilist.end());
274 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
275 template <
typename InputIterator>
276 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_set(InputIterator first, InputIterator last)
277 : base_type(fixed_allocator_type(mBuffer))
279 #if EASTL_NAME_ENABLED
280 mAllocator.set_name(EASTL_FIXED_SET_DEFAULT_NAME);
287 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
288 inline typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
289 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(
const this_type& x)
291 base_type::operator=(x);
296 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
297 inline typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
301 insert(ilist.begin(), ilist.end());
306 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
307 inline typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
308 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(this_type&& x)
310 base_type::operator=(x);
315 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
316 inline void fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::swap(this_type& x)
319 eastl::fixed_swap(*
this, x);
323 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
324 inline void fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::reset_lose_memory()
326 base_type::reset_lose_memory();
327 base_type::get_allocator().reset(mBuffer);
331 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
332 inline typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::size_type
333 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::max_size()
const
339 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
340 inline const typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
341 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
343 return mAllocator.get_overflow_allocator();
347 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
348 inline typename fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
349 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
351 return mAllocator.get_overflow_allocator();
355 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
356 inline void fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
358 mAllocator.set_overflow_allocator(allocator);
366 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
367 inline void swap(fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& a,
368 fixed_set<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& b)
371 eastl::fixed_swap(a, b);
380 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
381 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset()
382 : base_type(fixed_allocator_type(mBuffer))
384 #if EASTL_NAME_ENABLED
385 mAllocator.set_name(EASTL_FIXED_MULTISET_DEFAULT_NAME);
390 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
391 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(
const overflow_allocator_type& overflowAllocator)
392 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
394 #if EASTL_NAME_ENABLED
395 mAllocator.set_name(EASTL_FIXED_MULTISET_DEFAULT_NAME);
400 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
401 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(
const Compare& compare)
402 : base_type(compare, fixed_allocator_type(mBuffer))
404 #if EASTL_NAME_ENABLED
405 mAllocator.set_name(EASTL_FIXED_MULTISET_DEFAULT_NAME);
410 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
411 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(
const this_type& x)
412 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
414 mAllocator.copy_overflow_allocator(x.mAllocator);
416 #if EASTL_NAME_ENABLED
420 base_type::operator=(x);
424 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
425 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(this_type&& x)
426 : base_type(x.get_compare(), fixed_allocator_type(mBuffer))
428 mAllocator.copy_overflow_allocator(x.mAllocator);
430 #if EASTL_NAME_ENABLED
434 base_type::operator=(x);
438 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
439 inline fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(this_type&& x,
const overflow_allocator_type& overflowAllocator)
440 : base_type(x.get_compare(), fixed_allocator_type(mBuffer, overflowAllocator))
442 mAllocator.copy_overflow_allocator(x.mAllocator);
444 #if EASTL_NAME_ENABLED
448 base_type::operator=(x);
452 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
453 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(
std::initializer_list<value_type> ilist,
const overflow_allocator_type& overflowAllocator)
454 : base_type(fixed_allocator_type(mBuffer, overflowAllocator))
456 #if EASTL_NAME_ENABLED
457 mAllocator.set_name(EASTL_FIXED_MULTISET_DEFAULT_NAME);
460 insert(ilist.begin(), ilist.end());
464 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
465 template <
typename InputIterator>
466 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::fixed_multiset(InputIterator first, InputIterator last)
467 : base_type(fixed_allocator_type(mBuffer))
469 #if EASTL_NAME_ENABLED
470 mAllocator.set_name(EASTL_FIXED_MULTISET_DEFAULT_NAME);
477 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
478 inline typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
479 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(
const this_type& x)
481 base_type::operator=(x);
486 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
487 inline typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
491 insert(ilist.begin(), ilist.end());
496 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
497 inline typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::this_type&
498 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::operator=(this_type&& x)
500 base_type::operator=(x);
505 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
506 inline void fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::swap(this_type& x)
509 eastl::fixed_swap(*
this, x);
513 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
514 inline void fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::reset_lose_memory()
516 base_type::reset_lose_memory();
517 base_type::get_allocator().reset(mBuffer);
521 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
522 inline typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::size_type
523 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::max_size()
const
529 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
530 inline const typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
531 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() const EA_NOEXCEPT
533 return mAllocator.get_overflow_allocator();
537 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
538 inline typename fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::overflow_allocator_type&
539 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::get_overflow_allocator() EA_NOEXCEPT
541 return mAllocator.get_overflow_allocator();
545 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
546 inline void fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>::set_overflow_allocator(
const overflow_allocator_type& allocator)
548 mAllocator.set_overflow_allocator(allocator);
556 template <
typename Key,
size_t nodeCount,
bool bEnableOverflow,
typename Compare,
typename OverflowAllocator>
557 inline void swap(fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& a,
558 fixed_multiset<Key, nodeCount, bEnableOverflow, Compare, OverflowAllocator>& b)
561 eastl::fixed_swap(a, b);
Definition: allocator.h:52
Definition: fixed_set.h:136
Definition: fixed_pool.h:607
Definition: fixed_set.h:69
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: red_black_tree.h:108