-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvector_multiset.h
769 lines (596 loc) · 29.7 KB
/
vector_multiset.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// This file implements vector_multiset. It acts much like std::multiset, except
// its underlying representation is a random access container such as vector.
// These containers are sometimes also known as "sorted vectors."
// vector_sets have an advantage over conventional sets in that their memory
// is contiguous and node-less. The result is that lookups are faster, more
// cache friendly (which potentially more so benefits speed), and the container
// uses less memory. The downside is that inserting new items into the container
// is slower if they are inserted in random order instead of in sorted order.
// This tradeoff is well-worth it for many cases. Note that vector_multiset allows
// you to use a deque or other random access container which may perform
// better for you than vector.
//
// Note that with vector_set, vector_multiset, vector_map, vector_multimap
// that the modification of the container potentially invalidates all
// existing iterators into the container, unlike what happens with conventional
// sets and maps.
//
// This type could conceptually use a eastl::array as its underlying container,
// however the current design requires an allocator aware container.
// Consider using a fixedVector instead.
//////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_VECTOR_MULTISET_H
#define EASTL_VECTOR_MULTISET_H
#include <eastl/internal/config.h>
#include <eastl/allocator.h>
#include <eastl/functional.h>
#include <eastl/vector.h>
#include <eastl/utility.h>
#include <eastl/algorithm.h>
#include <eastl/initializer_list.h>
#include <stddef.h>
#if defined(EASTL_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
#endif
namespace eastl
{
/// EASTL_VECTOR_MULTISET_DEFAULT_NAME
///
/// Defines a default container name in the absence of a user-provided name.
///
#ifndef EASTL_VECTOR_MULTISET_DEFAULT_NAME
#define EASTL_VECTOR_MULTISET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " vector_multiset" // Unless the user overrides something, this is "EASTL vector_multiset".
#endif
/// EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR
///
#ifndef EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR
#define EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR allocator_type(EASTL_VECTOR_MULTISET_DEFAULT_NAME)
#endif
/// vector_multiset
///
/// Implements a multiset via a random access container such as a vector.
/// This container is also known as a sorted_vector. We choose to call it
/// vector_multiset, as that is a more consistent universally applicable name
/// for it in this library.
///
/// Note that with vector_set, vector_multiset, vector_map, vector_multimap
/// that the modification of the container potentially invalidates all
/// existing iterators into the container, unlike what happens with conventional
/// sets and maps.
///
/// This type could conceptually use a eastl::array as its underlying container,
/// however the current design requires an allocator aware container.
/// Consider using a fixedVector instead.
///
/// To consider: std::multiset has the limitation that values in the set cannot
/// be modified, with the idea that modifying them would change their sort
/// order. We have the opportunity to make it so that values can be modified
/// via changing iterators to be non-const, with the downside being that
/// the container can get screwed up if the user screws up. Alternatively,
/// we can do what std STL does and require the user to make their stored
/// classes use 'mutable' as needed. See the C++ standard defect report
/// #103 (DR 103) for a discussion of this.
///
template <typename Key, typename Compare = eastl::less<Key>, typename Allocator = EASTLAllocatorType,
typename RandomAccessContainer = eastl::vector<Key, Allocator> >
class vector_multiset : protected Compare, public RandomAccessContainer
{
public:
typedef RandomAccessContainer base_type;
typedef vector_multiset<Key, Compare, Allocator, RandomAccessContainer> this_type;
typedef Allocator allocator_type;
typedef Key key_type;
typedef Key value_type;
typedef Compare key_compare;
typedef Compare value_compare;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename base_type::size_type size_type;
typedef typename base_type::difference_type difference_type;
typedef typename base_type::iterator iterator; // **Currently typedefing from iterator instead of const_iterator due to const issues **: Note that we typedef from const_iterator. This is by design, as sets are sorted and values cannot be modified. To consider: allow values to be modified and thus risk changing their sort values.
typedef typename base_type::const_iterator const_iterator;
typedef typename base_type::reverse_iterator reverse_iterator; // See notes directly above regarding const_iterator.
typedef typename base_type::const_reverse_iterator const_reverse_iterator;
using base_type::begin;
using base_type::end;
using base_type::getAllocator;
public:
// We have an empty ctor and a ctor that takes an allocator instead of one for both
// because this way our RandomAccessContainer wouldn't be required to have an constructor
// that takes allocator_type.
vector_multiset();
explicit vector_multiset(const allocator_type& allocator);
explicit vector_multiset(const key_compare& comp, const allocator_type& allocator = EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR);
vector_multiset(const this_type& x);
vector_multiset(this_type&& x);
vector_multiset(this_type&& x, const allocator_type& allocator);
vector_multiset(std::initializer_list<value_type> ilist, const key_compare& compare = key_compare(), const allocator_type& allocator = EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR);
template <typename InputIterator>
vector_multiset(InputIterator first, InputIterator last); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.
template <typename InputIterator>
vector_multiset(InputIterator first, InputIterator last, const key_compare& compare); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.
this_type& operator=(const this_type& x);
this_type& operator=(std::initializer_list<value_type> ilist);
this_type& operator=(this_type&& x);
void swap(this_type& x);
const key_compare& key_comp() const;
key_compare& key_comp();
const value_compare& value_comp() const;
value_compare& value_comp();
// Inherited from base class:
//
// allocator_type& getAllocator();
// void setAllocator(const allocator_type& allocator);
//
// iterator begin();
// const_iterator begin() const;
// const_iterator cbegin() const;
//
// iterator end();
// const_iterator end() const;
// const_iterator cend() const;
//
// reverse_iterator rbegin();
// const_reverse_iterator rbegin() const;
// const_reverse_iterator crbegin() const;
//
// reverse_iterator rend();
// const_reverse_iterator rend() const;
// const_reverse_iterator crend() const;
//
// size_type size() const;
// bool empty() const;
// void clear();
template <class... Args>
iterator emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
iterator insert(const value_type& value); // The signature of this function was change in EASTL v2.05.00 from (the mistaken) pair<iterator, bool> to (the correct) iterator.
iterator insert(const_iterator position, const value_type& value);
iterator insert(const_iterator position, value_type&& value);
void insert(std::initializer_list<value_type> ilist);
template <typename P>
iterator insert(P&& otherValue);
template <typename InputIterator>
void insert(InputIterator first, InputIterator last);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);
size_type erase(const key_type& k);
reverse_iterator erase(const_reverse_iterator position);
reverse_iterator erase(const_reverse_iterator first, const_reverse_iterator last);
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
template <typename U, typename BinaryPredicate>
iterator find_as(const U& u, BinaryPredicate predicate);
template <typename U, typename BinaryPredicate>
const_iterator find_as(const U& u, BinaryPredicate predicate) const;
size_type count(const key_type& k) const;
iterator lowerBound(const key_type& k);
const_iterator lowerBound(const key_type& k) const;
iterator upperBound(const key_type& k);
const_iterator upperBound(const key_type& k) const;
eastl::pair<iterator, iterator> equalRange(const key_type& k);
eastl::pair<const_iterator, const_iterator> equalRange(const key_type& k) const;
/// equalRange_small
/// This is a special version of equalRange which is optimized for the
/// case of there being few or no duplicated keys in the tree.
eastl::pair<iterator, iterator> equalRange_small(const key_type& k)
{
// Defined inline because VC7.1 is broken for when it's defined outside.
const iterator itLower(lowerBound(k));
iterator itUpper(itLower);
while((itUpper != end()) && !value_compare::operator()(k, *itUpper))
++itUpper;
return eastl::pair<iterator, iterator>(itLower, itUpper);
}
eastl::pair<const_iterator, const_iterator> equalRange_small(const key_type& k) const;
// Functions which are disallowed due to being unsafe.
void pushBack(const value_type& value) = delete;
reference pushBack() = delete;
void* pushBackUninitialized() = delete;
template <class... Args>
reference emplace_back(Args&&...) = delete;
// NOTE(rparolin): It is undefined behaviour if user code fails to ensure the container
// invariants are respected by performing an explicit call to 'sort' before any other
// operations on the container are performed that do not clear the elements.
//
// 'pushBack_unsorted' and 'emplace_back_unsorted' do not satisfy container invariants
// for being sorted. We provide these overloads explicitly labelled as '_unsorted' as an
// optimization opportunity when batch inserting elements so users can defer the cost of
// sorting the container once when all elements are contained. This was done to clarify
// the intent of code by leaving a trace that a manual call to sort is required.
//
template <typename... Args> decltype(auto) pushBack_unsorted(Args&&... args)
{ return base_type::pushBack(eastl::forward<Args>(args)...); }
template <typename... Args> decltype(auto) emplace_back_unsorted(Args&&... args)
{ return base_type::emplace_back(eastl::forward<Args>(args)...); }
}; // vector_multiset
///////////////////////////////////////////////////////////////////////
// vector_multiset
///////////////////////////////////////////////////////////////////////
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset()
: value_compare(), base_type()
{
getAllocator().setName(EASTL_VECTOR_MULTISET_DEFAULT_NAME);
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(const allocator_type& allocator)
: value_compare(), base_type(allocator)
{
// Empty
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(const key_compare& comp, const allocator_type& allocator)
: value_compare(comp), base_type(allocator)
{
// Empty
}
template <typename K, typename C, typename A, typename RAC>
template <typename InputIterator>
inline vector_multiset<K, C, A, RAC>::vector_multiset(InputIterator first, InputIterator last)
: value_compare(), base_type(EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR)
{
insert(first, last);
}
template <typename K, typename C, typename A, typename RAC>
template <typename InputIterator>
inline vector_multiset<K, C, A, RAC>::vector_multiset(InputIterator first, InputIterator last, const key_compare& compare)
: value_compare(compare), base_type(EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR)
{
insert(first, last);
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(const this_type& x)
: value_compare(x), base_type(x)
{
// Empty
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(this_type&& x)
// careful to only copy / move the distinct base sub-objects of x:
: value_compare(static_cast<value_compare&>(x)), base_type(eastl::move(static_cast<base_type&&>(x)))
{
// Empty. Note: x is left with empty contents but its original value_compare instead of the default one.
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(this_type&& x, const allocator_type& allocator)
// careful to only copy / move the distinct base sub-objects of x:
: value_compare(static_cast<value_compare&>(x)), base_type(eastl::move(static_cast<base_type&&>(x)), allocator)
{
// Empty. Note: x is left with empty contents but its original value_compare instead of the default one.
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>::vector_multiset(std::initializer_list<value_type> ilist, const key_compare& compare, const allocator_type& allocator)
: value_compare(compare), base_type(allocator)
{
insert(ilist.begin(), ilist.end());
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>&
vector_multiset<K, C, A, RAC>::operator=(const this_type& x)
{
base_type::operator=(x);
value_compare::operator=(x);
return *this;
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>&
vector_multiset<K, C, A, RAC>::operator=(this_type&& x)
{
base_type::operator=(eastl::move(x));
using eastl::swap;
swap(static_cast<value_compare&>(*this), static_cast<value_compare&>(x));
return *this;
}
template <typename K, typename C, typename A, typename RAC>
inline vector_multiset<K, C, A, RAC>&
vector_multiset<K, C, A, RAC>::operator=(std::initializer_list<value_type> ilist)
{
base_type::clear();
insert(ilist.begin(), ilist.end());
return *this;
}
template <typename K, typename C, typename A, typename RAC>
inline void vector_multiset<K, C, A, RAC>::swap(this_type& x)
{
base_type::swap(x);
using eastl::swap;
swap(static_cast<value_compare&>(*this), static_cast<value_compare&>(x));
}
template <typename K, typename C, typename A, typename RAC>
inline const typename vector_multiset<K, C, A, RAC>::key_compare&
vector_multiset<K, C, A, RAC>::key_comp() const
{
return static_cast<const key_compare&>(*this);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::key_compare&
vector_multiset<K, C, A, RAC>::key_comp()
{
return static_cast<key_compare&>(*this);
}
template <typename K, typename C, typename A, typename RAC>
inline const typename vector_multiset<K, C, A, RAC>::value_compare&
vector_multiset<K, C, A, RAC>::value_comp() const
{
return static_cast<const value_compare&>(*this);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::value_compare&
vector_multiset<K, C, A, RAC>::value_comp()
{
return static_cast<value_compare&>(*this);
}
template <typename K, typename C, typename A, typename RAC>
template <class... Args>
typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::emplace(Args&&... args)
{
#if EASTL_USE_FORWARD_WORKAROUND
auto value = value_type(eastl::forward<Args>(args)...); // Workaround for compiler bug in VS2013 which results in a compiler internal crash while compiling this code.
#else
value_type value(eastl::forward<Args>(args)...);
#endif
return insert(eastl::move(value));
}
template <typename K, typename C, typename A, typename RAC>
template <class... Args>
typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::emplace_hint(const_iterator position, Args&&... args)
{
#if EASTL_USE_FORWARD_WORKAROUND
auto value = value_type(eastl::forward<Args>(args)...); // Workaround for compiler bug in VS2013 which results in a compiler internal crash while compiling this code.
#else
value_type value(eastl::forward<Args>(args)...);
#endif
return insert(position, eastl::move(value));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::insert(const value_type& value)
{
const iterator itUB(upperBound(value));
return base_type::insert(itUB, value);
}
template <typename K, typename C, typename A, typename RAC>
template <typename P>
typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::insert(P&& otherValue)
{
value_type value(eastl::forward<P>(otherValue));
const iterator itUB(upperBound(value));
return base_type::insert(itUB, eastl::move(value));
}
template <typename K, typename C, typename A, typename RAC>
inline void vector_multiset<K, C, A, RAC>::insert(std::initializer_list<value_type> ilist)
{
insert(ilist.begin(), ilist.end());
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::insert(const_iterator position, const value_type& value)
{
// We assume that the user knows what he is doing and has supplied us with
// a position that is right where value should be inserted (put in front of).
// We do a test to see if the position is correct. If so then we insert,
// if not then we ignore the input position. However,
if((position == end()) || !value_compare::operator()(*position, value)) // If value is <= the element at position...
{
if((position == begin()) || !value_compare::operator()(value, *(position - 1))) // If value is >= the element before position...
return base_type::insert(position, value);
}
// In this case we have an incorrect position. We fall back to the regular insert function.
return insert(value);
}
template <typename K, typename C, typename A, typename RAC>
typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::insert(const_iterator position, value_type&& value)
{
if((position == end()) || !value_compare::operator()(*position, value)) // If value is <= the element at position...
{
if((position == begin()) || !value_compare::operator()(value, *(position - 1))) // If value is >= the element before position...
return base_type::insert(position, eastl::move(value));
}
// In this case we have an incorrect position. We fall back to the regular insert function.
return insert(eastl::move(value));
}
template <typename K, typename C, typename A, typename RAC>
template <typename InputIterator>
inline void vector_multiset<K, C, A, RAC>::insert(InputIterator first, InputIterator last)
{
// To consider: Improve the speed of this by getting the length of the
// input range and resizing our container to that size
// before doing the insertions. We can't use reserve
// because we don't know if we are using a vector or not.
// Alternatively, force the user to do the reservation.
// To consider: When inserting values that come from a container
// like this container, use the property that they are
// known to be sorted and speed up the inserts here.
for(; first != last; ++first)
base_type::insert(upperBound(*first), *first);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::erase(const_iterator position)
{
// Note that we return iterator and not void. This allows for more efficient use of
// the container and is consistent with the C++ language defect report #130 (DR 130)
return base_type::erase(position);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::erase(const_iterator first, const_iterator last)
{
return base_type::erase(first, last);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::reverse_iterator
vector_multiset<K, C, A, RAC>::erase(const_reverse_iterator position)
{
return reverse_iterator(base_type::erase((++position).base()));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::reverse_iterator
vector_multiset<K, C, A, RAC>::erase(const_reverse_iterator first, const_reverse_iterator last)
{
return reverse_iterator(base_type::erase((++last).base(), (++first).base()));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::size_type
vector_multiset<K, C, A, RAC>::erase(const key_type& k)
{
const eastl::pair<iterator, iterator> pairIts(equalRange(k));
if(pairIts.first != pairIts.second)
base_type::erase(pairIts.first, pairIts.second);
return (size_type)eastl::distance(pairIts.first, pairIts.second); // This can result in any value >= 0.
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::find(const key_type& k)
{
const eastl::pair<iterator, iterator> pairIts(equalRange(k));
return (pairIts.first != pairIts.second) ? pairIts.first : end();
}
template <typename K, typename C, typename A, typename RAC>
template <typename U, typename BinaryPredicate>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::find_as(const U& u, BinaryPredicate predicate)
{
const eastl::pair<iterator, iterator> pairIts(eastl::equalRange(begin(), end(), u, predicate));
return (pairIts.first != pairIts.second) ? pairIts.first : end();
}
template <typename K, typename C, typename A, typename RAC>
template <typename U, typename BinaryPredicate>
inline typename vector_multiset<K, C, A, RAC>::const_iterator
vector_multiset<K, C, A, RAC>::find_as(const U& u, BinaryPredicate predicate) const
{
const eastl::pair<const_iterator, const_iterator> pairIts(eastl::equalRange(begin(), end(), u, predicate));
return (pairIts.first != pairIts.second) ? pairIts.first : end();
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::const_iterator
vector_multiset<K, C, A, RAC>::find(const key_type& k) const
{
const eastl::pair<const_iterator, const_iterator> pairIts(equalRange(k));
return (pairIts.first != pairIts.second) ? pairIts.first : end();
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::size_type
vector_multiset<K, C, A, RAC>::count(const key_type& k) const
{
const eastl::pair<const_iterator, const_iterator> pairIts(equalRange(k));
return (size_type)eastl::distance(pairIts.first, pairIts.second);
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::lowerBound(const key_type& k)
{
return eastl::lowerBound(begin(), end(), k, static_cast<value_compare&>(*this));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::const_iterator
vector_multiset<K, C, A, RAC>::lowerBound(const key_type& k) const
{
return eastl::lowerBound(begin(), end(), k, static_cast<const value_compare&>(*this));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::iterator
vector_multiset<K, C, A, RAC>::upperBound(const key_type& k)
{
return eastl::upperBound(begin(), end(), k, static_cast<value_compare&>(*this));
}
template <typename K, typename C, typename A, typename RAC>
inline typename vector_multiset<K, C, A, RAC>::const_iterator
vector_multiset<K, C, A, RAC>::upperBound(const key_type& k) const
{
return eastl::upperBound(begin(), end(), k, static_cast<const value_compare&>(*this));
}
template <typename K, typename C, typename A, typename RAC>
inline eastl::pair<typename vector_multiset<K, C, A, RAC>::iterator, typename vector_multiset<K, C, A, RAC>::iterator>
vector_multiset<K, C, A, RAC>::equalRange(const key_type& k)
{
return eastl::equalRange(begin(), end(), k, static_cast<value_compare&>(*this));
}
template <typename K, typename C, typename A, typename RAC>
inline eastl::pair<typename vector_multiset<K, C, A, RAC>::const_iterator, typename vector_multiset<K, C, A, RAC>::const_iterator>
vector_multiset<K, C, A, RAC>::equalRange(const key_type& k) const
{
return eastl::equalRange(begin(), end(), k, static_cast<const value_compare&>(*this));
}
/*
// VC++ fails to compile this when defined here, saying the function isn't a memgber of vector_multimap.
template <typename K, typename C, typename A, typename RAC>
inline eastl::pair<typename vector_multiset<K, C, A, RAC>::iterator, typename vector_multiset<K, C, A, RAC>::iterator>
vector_multiset<K, C, A, RAC>::equalRange_small(const key_type& k)
{
const iterator itLower(lowerBound(k));
iterator itUpper(itLower);
while((itUpper != end()) && !value_compare::operator()(k, *itUpper))
++itUpper;
return eastl::pair<iterator, iterator>(itLower, itUpper);
}
*/
template <typename K, typename C, typename A, typename RAC>
inline eastl::pair<typename vector_multiset<K, C, A, RAC>::const_iterator, typename vector_multiset<K, C, A, RAC>::const_iterator>
vector_multiset<K, C, A, RAC>::equalRange_small(const key_type& k) const
{
const const_iterator itLower(lowerBound(k));
const_iterator itUpper(itLower);
while((itUpper != end()) && !value_compare::operator()(k, *itUpper))
++itUpper;
return eastl::pair<const_iterator, const_iterator>(itLower, itUpper);
}
///////////////////////////////////////////////////////////////////////////
// global operators
///////////////////////////////////////////////////////////////////////////
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator==(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return (a.size() == b.size()) && eastl::equal(b.begin(), b.end(), a.begin());
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator<(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return eastl::lexicographicalCompare(a.begin(), a.end(), b.begin(), b.end(), a.value_comp());
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator!=(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return !(a == b);
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator>(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return b < a;
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator<=(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return !(b < a);
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline bool operator>=(const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
const vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
return !(a < b);
}
template <typename Key, typename Compare, typename Allocator, typename RandomAccessContainer>
inline void swap(vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& a,
vector_multiset<Key, Compare, Allocator, RandomAccessContainer>& b)
{
a.swap(b);
}
} // namespace eastl
#endif // Header include guard