Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
/*
Copyright (C) 2009-2010 Electronic Arts, Inc.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1.  Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
2.  Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
3.  Neither the name of Electronic Arts, Inc. ("EA") nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

///////////////////////////////////////////////////////////////////////////////
// Written by Paul Pedriana.
//
// Refactored to be compliant with the PhysX data types by John W. Ratcliff
// on March 23, 2011
//////////////////////////////////////////////////////////////////////////////



#ifndef MI_MAP_SET_H
#define MI_MAP_SET_H

#include "MiPlatformConfig.h"
#include "MiMapSetInternal.h"


namespace mimp
{

    /// EASTL_MAP_DEFAULT_NAME
    ///
    /// Defines a default container name in the absence of a user-provided name.
    ///
    #ifndef EASTL_MAP_DEFAULT_NAME
        #define EASTL_MAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " map" // Unless the user overrides something, this is "EASTL map".
    #endif


    /// EASTL_MULTIMAP_DEFAULT_NAME
    ///
    /// Defines a default container name in the absence of a user-provided name.
    ///
    #ifndef EASTL_MULTIMAP_DEFAULT_NAME
        #define EASTL_MULTIMAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " multimap" // Unless the user overrides something, this is "EASTL multimap".
    #endif


    /// EASTL_MAP_DEFAULT_ALLOCATOR
    ///
    #ifndef EASTL_MAP_DEFAULT_ALLOCATOR
        #define EASTL_MAP_DEFAULT_ALLOCATOR allocator_type(EASTL_MAP_DEFAULT_NAME)
    #endif

    /// EASTL_MULTIMAP_DEFAULT_ALLOCATOR
    ///
    #ifndef EASTL_MULTIMAP_DEFAULT_ALLOCATOR
        #define EASTL_MULTIMAP_DEFAULT_ALLOCATOR allocator_type(EASTL_MULTIMAP_DEFAULT_NAME)
    #endif



    /// map
    ///
    /// Implements a canonical map. 
    ///
    /// The large majority of the implementation of this class is found in the rbtree
    /// base class. We control the behaviour of rbtree via template parameters.
    ///
    /// Pool allocation
    /// If you want to make a custom memory pool for a map container, your pool 
    /// needs to contain items of type map::node_type. So if you have a memory
    /// pool that has a constructor that takes the size of pool items and the
    /// count of pool items, you would do this (assuming that MemoryPool implements
    /// the Allocator interface):
    ///     typedef map<Widget, int, less<Widget>, MemoryPool> WidgetMap;  // Delare your WidgetMap type.
    ///     MemoryPool myPool(sizeof(WidgetMap::node_type), 100);          // Make a pool of 100 Widget nodes.
    ///     WidgetMap myMap(&myPool);                                      // Create a map that uses the pool.
    ///
    template <typename Key, typename T, typename Compare = mimp::less<Key>, typename Allocator = EASTLAllocatorType>
    class map
        : public rbtree<Key, mimp::pair<const Key, T>, Compare, Allocator, mimp::use_first<mimp::pair<const Key, T> >, true, true>
    {
    public:
        typedef rbtree<Key, mimp::pair<const Key, T>, Compare, Allocator,
                        mimp::use_first<mimp::pair<const Key, T> >, true, true>   base_type;
        typedef map<Key, T, Compare, Allocator>                                     this_type;
        typedef typename base_type::size_type                                       size_type;
        typedef typename base_type::key_type                                        key_type;
        typedef T                                                                   mapped_type;
        typedef typename base_type::value_type                                      value_type;
        typedef typename base_type::node_type                                       node_type;
        typedef typename base_type::iterator                                        iterator;
        typedef typename base_type::const_iterator                                  const_iterator;
        typedef typename base_type::allocator_type                                  allocator_type;
        typedef typename base_type::insert_return_type                              insert_return_type;
        typedef typename base_type::extract_key                                     extract_key;
        // Other types are inherited from the base class.

        using base_type::begin;
        using base_type::end;
        using base_type::find;
        using base_type::lower_bound;
        using base_type::upper_bound;
        using base_type::mCompare;

        #if !defined(__GNUC__) || (__GNUC__ >= 3) // GCC 2.x has a bug which we work around.
        using base_type::insert;
        using base_type::erase;
        #endif

    public:
        map(const allocator_type& allocator = EASTL_MAP_DEFAULT_ALLOCATOR);
        map(const Compare& compare, const allocator_type& allocator = EASTL_MAP_DEFAULT_ALLOCATOR);
        map(const this_type& x);

        template <typename Iterator>
        map(Iterator itBegin, Iterator itEnd); // allocator arg removed because VC7.1 fails on the default arg. To consider: Make a second version of this function without a default arg.

    public:
        /// This is an extension to the C++ standard. We insert a default-constructed 
        /// element with the given key. The reason for this is that we can avoid the 
        /// potentially expensive operation of creating and/or copying a mapped_type
        /// object on the stack.
        insert_return_type insert(const Key& key);

        #if defined(__GNUC__) && (__GNUC__ < 3) // If using old GCC (GCC 2.x has a bug which we work around)
            template <typename InputIterator>
            void               insert(InputIterator first, InputIterator last)     { return base_type::insert(first, last);     }
            insert_return_type insert(const value_type& value)                     { return base_type::insert(value);           }
            iterator           insert(iterator position, const value_type& value)  { return base_type::insert(position, value); }
            iterator           erase(iterator position)                            { return base_type::erase(position);         }
            iterator           erase(iterator first, iterator last)                { return base_type::erase(first, last);      }
        #endif

        size_type erase(const Key& key);
        size_type count(const Key& key) const;

        mimp::pair<iterator, iterator>             equal_range(const Key& key);
        mimp::pair<const_iterator, const_iterator> equal_range(const Key& key) const;

        T& operator[](const Key& key); // Of map, multimap, set, and multimap, only map has operator[].

    }; // map






    /// multimap
    ///
    /// Implements a canonical multimap.
    ///
    /// The large majority of the implementation of this class is found in the rbtree
    /// base class. We control the behaviour of rbtree via template parameters.
    ///
    /// Pool allocation
    /// If you want to make a custom memory pool for a multimap container, your pool 
    /// needs to contain items of type multimap::node_type. So if you have a memory
    /// pool that has a constructor that takes the size of pool items and the
    /// count of pool items, you would do this (assuming that MemoryPool implements
    /// the Allocator interface):
    ///     typedef multimap<Widget, int, less<Widget>, MemoryPool> WidgetMap;  // Delare your WidgetMap type.
    ///     MemoryPool myPool(sizeof(WidgetMap::node_type), 100);               // Make a pool of 100 Widget nodes.
    ///     WidgetMap myMap(&myPool);                                           // Create a map that uses the pool.
    ///
    template <typename Key, typename T, typename Compare = mimp::less<Key>, typename Allocator = EASTLAllocatorType>
    class multimap
        : public rbtree<Key, mimp::pair<const Key, T>, Compare, Allocator, mimp::use_first<mimp::pair<const Key, T> >, true, false>
    {
    public:
        typedef rbtree<Key, mimp::pair<const Key, T>, Compare, Allocator, 
                        mimp::use_first<mimp::pair<const Key, T> >, true, false>  base_type;
        typedef multimap<Key, T, Compare, Allocator>                                this_type;
        typedef typename base_type::size_type                                       size_type;
        typedef typename base_type::key_type                                        key_type;
        typedef T                                                                   mapped_type;
        typedef typename base_type::value_type                                      value_type;
        typedef typename base_type::node_type                                       node_type;
        typedef typename base_type::iterator                                        iterator;
        typedef typename base_type::const_iterator                                  const_iterator;
        typedef typename base_type::allocator_type                                  allocator_type;
        typedef typename base_type::insert_return_type                              insert_return_type;
        typedef typename base_type::extract_key                                     extract_key;
        // Other types are inherited from the base class.

        using base_type::begin;
        using base_type::end;
        using base_type::find;
        using base_type::lower_bound;
        using base_type::upper_bound;
        using base_type::mCompare;

        #if !defined(__GNUC__) || (__GNUC__ >= 3) // GCC 2.x has a bug which we work around.
        using base_type::insert;
        using base_type::erase;
        #endif

    public:
        multimap(const allocator_type& allocator = EASTL_MULTIMAP_DEFAULT_ALLOCATOR);
        multimap(const Compare& compare, const allocator_type& allocator = EASTL_MULTIMAP_DEFAULT_ALLOCATOR);
        multimap(const this_type& x);

        template <typename Iterator>
        multimap(Iterator itBegin, Iterator itEnd); // allocator arg removed because VC7.1 fails on the default arg. To consider: Make a second version of this function without a default arg.

    public:
        /// This is an extension to the C++ standard. We insert a default-constructed 
        /// element with the given key. The reason for this is that we can avoid the 
        /// potentially expensive operation of creating and/or copying a mapped_type
        /// object on the stack.
        insert_return_type insert(const Key& key);

        #if defined(__GNUC__) && (__GNUC__ < 3) // If using old GCC (GCC 2.x has a bug which we work around)
            template <typename InputIterator>
            void               insert(InputIterator first, InputIterator last)     { return base_type::insert(first, last);     }
            insert_return_type insert(const value_type& value)                     { return base_type::insert(value);           }
            iterator           insert(iterator position, const value_type& value)  { return base_type::insert(position, value); }
            iterator           erase(iterator position)                            { return base_type::erase(position);         }
            iterator           erase(iterator first, iterator last)                { return base_type::erase(first, last);      }
        #endif

        size_type erase(const Key& key);
        size_type count(const Key& key) const;

        mimp::pair<iterator, iterator>             equal_range(const Key& key);
        mimp::pair<const_iterator, const_iterator> equal_range(const Key& key) const;

        /// equal_range_small
        /// This is a special version of equal_range which is optimized for the 
        /// case of there being few or no duplicated keys in the tree.
        mimp::pair<iterator, iterator>             equal_range_small(const Key& key);
        mimp::pair<const_iterator, const_iterator> equal_range_small(const Key& key) const;

    }; // multimap





    ///////////////////////////////////////////////////////////////////////
    // map
    ///////////////////////////////////////////////////////////////////////

    template <typename Key, typename T, typename Compare, typename Allocator>
    inline map<Key, T, Compare, Allocator>::map(const allocator_type& allocator)
        : base_type(allocator) { }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline map<Key, T, Compare, Allocator>::map(const Compare& compare, const allocator_type& allocator)
        : base_type(compare, allocator) { }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline map<Key, T, Compare, Allocator>::map(const this_type& x)
        : base_type(x) { }


    template <typename Key, typename T, typename Compare, typename Allocator>
    template <typename Iterator>
    inline map<Key, T, Compare, Allocator>::map(Iterator itBegin, Iterator itEnd)
        : base_type(itBegin, itEnd, Compare(), EASTL_MAP_DEFAULT_ALLOCATOR) { }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename map<Key, T, Compare, Allocator>::insert_return_type
    map<Key, T, Compare, Allocator>::insert(const Key& key)
    {
        return base_type::DoInsertKey(key, true_type());
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename map<Key, T, Compare, Allocator>::size_type
    map<Key, T, Compare, Allocator>::erase(const Key& key)
    {
        const iterator it(find(key));

        if(it != end()) // If it exists...
        {
            base_type::erase(it);
            return 1;
        }
        return 0;
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename map<Key, T, Compare, Allocator>::size_type
    map<Key, T, Compare, Allocator>::count(const Key& key) const
    {
        const const_iterator it(find(key));
        return (it != end()) ? 1 : 0;
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename map<Key, T, Compare, Allocator>::iterator,
                       typename map<Key, T, Compare, Allocator>::iterator>
    map<Key, T, Compare, Allocator>::equal_range(const Key& key)
    {
        // The resulting range will either be empty or have one element,
        // so instead of doing two tree searches (one for lower_bound and 
        // one for upper_bound), we do just lower_bound and see if the 
        // result is a range of size zero or one.
        const iterator itLower(lower_bound(key));

        if((itLower == end()) || mCompare(key, itLower.mpNode->mValue.first)) // If at the end or if (key is < itLower)...
            return mimp::pair<iterator, iterator>(itLower, itLower);

        iterator itUpper(itLower);
        return mimp::pair<iterator, iterator>(itLower, ++itUpper);
    }
    

    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename map<Key, T, Compare, Allocator>::const_iterator, 
                       typename map<Key, T, Compare, Allocator>::const_iterator>
    map<Key, T, Compare, Allocator>::equal_range(const Key& key) const
    {
        // See equal_range above for comments.
        const const_iterator itLower(lower_bound(key));

        if((itLower == end()) || mCompare(key, itLower.mpNode->mValue.first)) // If at the end or if (key is < itLower)...
            return mimp::pair<const_iterator, const_iterator>(itLower, itLower);

        const_iterator itUpper(itLower);
        return mimp::pair<const_iterator, const_iterator>(itLower, ++itUpper);
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline T& map<Key, T, Compare, Allocator>::operator[](const Key& key)
    {
        iterator itLower(lower_bound(key)); // itLower->first is >= key.

        if((itLower == end()) || mCompare(key, (*itLower).first))
        {
            itLower = base_type::insert(itLower, value_type(key, T()));

            // To do: Convert this to use the more efficient:
            //    itLower = DoInsertKey(itLower, key, true_type());
            // when we gain confidence in that function.
        }

        return (*itLower).second;

        // Reference implementation of this function, which may not be as fast:
        //iterator it(base_type::insert(mimp::pair<iterator, iterator>(key, T())).first);
        //return it->second;
    }






    ///////////////////////////////////////////////////////////////////////
    // multimap
    ///////////////////////////////////////////////////////////////////////

    template <typename Key, typename T, typename Compare, typename Allocator>
    inline multimap<Key, T, Compare, Allocator>::multimap(const allocator_type& allocator)
        : base_type(allocator)
    {
        // Empty
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline multimap<Key, T, Compare, Allocator>::multimap(const Compare& compare, const allocator_type& allocator)
        : base_type(compare, allocator)
    {
        // Empty
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline multimap<Key, T, Compare, Allocator>::multimap(const this_type& x)
        : base_type(x)
    {
        // Empty
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    template <typename Iterator>
    inline multimap<Key, T, Compare, Allocator>::multimap(Iterator itBegin, Iterator itEnd)
        : base_type(itBegin, itEnd, Compare(), EASTL_MULTIMAP_DEFAULT_ALLOCATOR)
    {
        // Empty
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename multimap<Key, T, Compare, Allocator>::insert_return_type
    multimap<Key, T, Compare, Allocator>::insert(const Key& key)
    {
        return base_type::DoInsertKey(key, false_type());
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename multimap<Key, T, Compare, Allocator>::size_type
    multimap<Key, T, Compare, Allocator>::erase(const Key& key)
    {
        const mimp::pair<iterator, iterator> range(equal_range(key));
        const size_type n = (size_type)mimp::distance(range.first, range.second);
        base_type::erase(range.first, range.second);
        return n;
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline typename multimap<Key, T, Compare, Allocator>::size_type
    multimap<Key, T, Compare, Allocator>::count(const Key& key) const
    {
        const mimp::pair<const_iterator, const_iterator> range(equal_range(key));
        return (size_type)mimp::distance(range.first, range.second);
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename multimap<Key, T, Compare, Allocator>::iterator,
                       typename multimap<Key, T, Compare, Allocator>::iterator>
    multimap<Key, T, Compare, Allocator>::equal_range(const Key& key)
    {
        // There are multiple ways to implement equal_range. The implementation mentioned
        // in the C++ standard and which is used by most (all?) commercial STL implementations
        // is this:
        //    return mimp::pair<iterator, iterator>(lower_bound(key), upper_bound(key));
        //
        // This does two tree searches -- one for the lower bound and one for the 
        // upper bound. This works well for the case whereby you have a large container
        // and there are lots of duplicated values. We provide an alternative version
        // of equal_range called equal_range_small for cases where the user is confident
        // that the number of duplicated items is only a few.

        return mimp::pair<iterator, iterator>(lower_bound(key), upper_bound(key));
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename multimap<Key, T, Compare, Allocator>::const_iterator, 
                       typename multimap<Key, T, Compare, Allocator>::const_iterator>
    multimap<Key, T, Compare, Allocator>::equal_range(const Key& key) const
    {
        // See comments above in the non-const version of equal_range.
        return mimp::pair<const_iterator, const_iterator>(lower_bound(key), upper_bound(key));
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename multimap<Key, T, Compare, Allocator>::iterator,
                       typename multimap<Key, T, Compare, Allocator>::iterator>
    multimap<Key, T, Compare, Allocator>::equal_range_small(const Key& key)
    {
        // We provide alternative version of equal_range here which works faster
        // for the case where there are at most small number of potential duplicated keys.
        const iterator itLower(lower_bound(key));
        iterator       itUpper(itLower);

        while((itUpper != end()) && !mCompare(key, itUpper.mpNode->mValue.first))
            ++itUpper;

        return mimp::pair<iterator, iterator>(itLower, itUpper);
    }


    template <typename Key, typename T, typename Compare, typename Allocator>
    inline mimp::pair<typename multimap<Key, T, Compare, Allocator>::const_iterator, 
                       typename multimap<Key, T, Compare, Allocator>::const_iterator>
    multimap<Key, T, Compare, Allocator>::equal_range_small(const Key& key) const
    {
        // We provide alternative version of equal_range here which works faster
        // for the case where there are at most small number of potential duplicated keys.
        const const_iterator itLower(lower_bound(key));
        const_iterator       itUpper(itLower);

        while((itUpper != end()) && !mCompare(key, itUpper.mpNode->mValue.first))
            ++itUpper;

        return mimp::pair<const_iterator, const_iterator>(itLower, itUpper);
    }


    /// EASTL_SET_DEFAULT_NAME
    ///
    /// Defines a default container name in the absence of a user-provided name.
    ///
    #ifndef EASTL_SET_DEFAULT_NAME
        #define EASTL_SET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " set" // Unless the user overrides something, this is "EASTL set".
    #endif


    /// EASTL_MULTISET_DEFAULT_NAME
    ///
    /// Defines a default container name in the absence of a user-provided name.
    ///
    #ifndef EASTL_MULTISET_DEFAULT_NAME
        #define EASTL_MULTISET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " multiset" // Unless the user overrides something, this is "EASTL multiset".
    #endif


    /// EASTL_SET_DEFAULT_ALLOCATOR
    ///
    #ifndef EASTL_SET_DEFAULT_ALLOCATOR
        #define EASTL_SET_DEFAULT_ALLOCATOR allocator_type(EASTL_SET_DEFAULT_NAME)
    #endif

    /// EASTL_MULTISET_DEFAULT_ALLOCATOR
    ///
    #ifndef EASTL_MULTISET_DEFAULT_ALLOCATOR
        #define EASTL_MULTISET_DEFAULT_ALLOCATOR allocator_type(EASTL_MULTISET_DEFAULT_NAME)
    #endif



    /// set
    ///
    /// Implements a canonical set. 
    ///
    /// The large majority of the implementation of this class is found in the rbtree
    /// base class. We control the behaviour of rbtree via template parameters.
    ///
    /// Note that the 'bMutableIterators' template parameter to rbtree is set to false.
    /// This means that set::iterator is const and the same as set::const_iterator.
    /// This is by design and it follows the C++ standard defect report recommendation.
    /// If the user wants to modify a container element, the user needs to either use
    /// mutable data members or use const_cast on the iterator's data member. Both of 
    /// these solutions are recommended by the C++ standard defect report.
    /// To consider: Expose the bMutableIterators template policy here at the set level
    /// so the user can have non-const set iterators via a template parameter.
    ///
    /// Pool allocation
    /// If you want to make a custom memory pool for a set container, your pool 
    /// needs to contain items of type set::node_type. So if you have a memory
    /// pool that has a constructor that takes the size of pool items and the
    /// count of pool items, you would do this (assuming that MemoryPool implements
    /// the Allocator interface):
    ///     typedef set<Widget, less<Widget>, MemoryPool> WidgetSet;    // Delare your WidgetSet type.
    ///     MemoryPool myPool(sizeof(WidgetSet::node_type), 100);       // Make a pool of 100 Widget nodes.
    ///     WidgetSet mySet(&myPool);                                   // Create a map that uses the pool.
    ///
    template <typename Key, typename Compare = mimp::less<Key>, typename Allocator = EASTLAllocatorType>
    class set
        : public rbtree<Key, Key, Compare, Allocator, mimp::use_self<Key>, false, true>
    {
    public:
        typedef rbtree<Key, Key, Compare, Allocator, mimp::use_self<Key>, false, true> base_type;
        typedef set<Key, Compare, Allocator>                                            this_type;
        typedef typename base_type::size_type                                           size_type;
        typedef typename base_type::value_type                                          value_type;
        typedef typename base_type::iterator                                            iterator;
        typedef typename base_type::const_iterator                                      const_iterator;
        typedef typename base_type::reverse_iterator                                    reverse_iterator;
        typedef typename base_type::const_reverse_iterator                              const_reverse_iterator;
        typedef typename base_type::allocator_type                                      allocator_type;
        // Other types are inherited from the base class.

        using base_type::begin;
        using base_type::end;
        using base_type::find;
        using base_type::lower_bound;
        using base_type::upper_bound;
        using base_type::mCompare;

    public:
        set(const allocator_type& allocator = EASTL_SET_DEFAULT_ALLOCATOR);
        set(const Compare& compare, const allocator_type& allocator = EASTL_SET_DEFAULT_ALLOCATOR);
        set(const this_type& x);

        template <typename Iterator>
        set(Iterator itBegin, Iterator itEnd); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.

    public:
        size_type erase(const Key& k);
        iterator  erase(iterator position);
        iterator  erase(iterator first, iterator last);

        reverse_iterator erase(reverse_iterator position);
        reverse_iterator erase(reverse_iterator first, reverse_iterator last);

        size_type count(const Key& k) const;

        mimp::pair<iterator, iterator>             equal_range(const Key& k);
        mimp::pair<const_iterator, const_iterator> equal_range(const Key& k) const;

    }; // set





    /// multiset
    ///
    /// Implements a canonical multiset.
    ///
    /// The large majority of the implementation of this class is found in the rbtree
    /// base class. We control the behaviour of rbtree via template parameters.
    ///
    /// See notes above in 'set' regarding multable iterators.
    ///
    /// Pool allocation
    /// If you want to make a custom memory pool for a multiset container, your pool 
    /// needs to contain items of type multiset::node_type. So if you have a memory
    /// pool that has a constructor that takes the size of pool items and the
    /// count of pool items, you would do this (assuming that MemoryPool implements
    /// the Allocator interface):
    ///     typedef multiset<Widget, less<Widget>, MemoryPool> WidgetSet;   // Delare your WidgetSet type.
    ///     MemoryPool myPool(sizeof(WidgetSet::node_type), 100);           // Make a pool of 100 Widget nodes.
    ///     WidgetSet mySet(&myPool);                                       // Create a map that uses the pool.
    ///
    template <typename Key, typename Compare = mimp::less<Key>, typename Allocator = EASTLAllocatorType>
    class multiset
        : public rbtree<Key, Key, Compare, Allocator, mimp::use_self<Key>, false, false>
    {
    public:
        typedef rbtree<Key, Key, Compare, Allocator, mimp::use_self<Key>, false, false>    base_type;
        typedef multiset<Key, Compare, Allocator>                                           this_type;
        typedef typename base_type::size_type                                               size_type;
        typedef typename base_type::value_type                                              value_type;
        typedef typename base_type::iterator                                                iterator;
        typedef typename base_type::const_iterator                                          const_iterator;
        typedef typename base_type::reverse_iterator                                    reverse_iterator;
        typedef typename base_type::const_reverse_iterator                              const_reverse_iterator;
        typedef typename base_type::allocator_type                                          allocator_type;
        // Other types are inherited from the base class.

        using base_type::begin;
        using base_type::end;
        using base_type::find;
        using base_type::lower_bound;
        using base_type::upper_bound;
        using base_type::mCompare;

    public:
        multiset(const allocator_type& allocator = EASTL_MULTISET_DEFAULT_ALLOCATOR);
        multiset(const Compare& compare, const allocator_type& allocator = EASTL_MULTISET_DEFAULT_ALLOCATOR);
        multiset(const this_type& x);

        template <typename Iterator>
        multiset(Iterator itBegin, Iterator itEnd); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.

    public:
        size_type erase(const Key& k);
        iterator  erase(iterator position);
        iterator  erase(iterator first, iterator last);

        reverse_iterator erase(reverse_iterator position);
        reverse_iterator erase(reverse_iterator first, reverse_iterator last);

        size_type count(const Key& k) const;

        mimp::pair<iterator, iterator>             equal_range(const Key& k);
        mimp::pair<const_iterator, const_iterator> equal_range(const Key& k) const;

        /// equal_range_small
        /// This is a special version of equal_range which is optimized for the 
        /// case of there being few or no duplicated keys in the tree.
        mimp::pair<iterator, iterator>             equal_range_small(const Key& k);
        mimp::pair<const_iterator, const_iterator> equal_range_small(const Key& k) const;

    }; // multiset





    ///////////////////////////////////////////////////////////////////////
    // set
    ///////////////////////////////////////////////////////////////////////

    template <typename Key, typename Compare, typename Allocator>
    inline set<Key, Compare, Allocator>::set(const allocator_type& allocator)
        : base_type(allocator)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline set<Key, Compare, Allocator>::set(const Compare& compare, const allocator_type& allocator)
        : base_type(compare, allocator)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline set<Key, Compare, Allocator>::set(const this_type& x)
        : base_type(x)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    template <typename Iterator>
    inline set<Key, Compare, Allocator>::set(Iterator itBegin, Iterator itEnd)
        : base_type(itBegin, itEnd, Compare(), EASTL_SET_DEFAULT_ALLOCATOR)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::size_type
    set<Key, Compare, Allocator>::erase(const Key& k)
    {
        const iterator it(find(k));

        if(it != end()) // If it exists...
        {
            base_type::erase(it);
            return 1;
        }
        return 0;
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::iterator
    set<Key, Compare, Allocator>::erase(iterator position)
    {
        // We need to provide this version because we override another version 
        // and C++ hiding rules would make the base version of this hidden.
        return base_type::erase(position);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::iterator
    set<Key, Compare, Allocator>::erase(iterator first, iterator last)
    {
        // We need to provide this version because we override another version 
        // and C++ hiding rules would make the base version of this hidden.
        return base_type::erase(first, last);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::size_type
    set<Key, Compare, Allocator>::count(const Key& k) const
    {
        const const_iterator it(find(k));
        return (it != end()) ? (size_type)1 : (size_type)0;
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::reverse_iterator
    set<Key, Compare, Allocator>::erase(reverse_iterator position)
    {
        return reverse_iterator(erase((++position).base()));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename set<Key, Compare, Allocator>::reverse_iterator
    set<Key, Compare, Allocator>::erase(reverse_iterator first, reverse_iterator last)
    {
        // Version which erases in order from first to last.
        // difference_type i(first.base() - last.base());
        // while(i--)
        //     first = erase(first);
        // return first;

        // Version which erases in order from last to first, but is slightly more efficient:
        return reverse_iterator(erase((++last).base(), (++first).base()));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename set<Key, Compare, Allocator>::iterator,
                       typename set<Key, Compare, Allocator>::iterator>
    set<Key, Compare, Allocator>::equal_range(const Key& k)
    {
        // The resulting range will either be empty or have one element,
        // so instead of doing two tree searches (one for lower_bound and 
        // one for upper_bound), we do just lower_bound and see if the 
        // result is a range of size zero or one.
        const iterator itLower(lower_bound(k));

        if((itLower == end()) || mCompare(k, *itLower)) // If at the end or if (k is < itLower)...
            return mimp::pair<iterator, iterator>(itLower, itLower);

        iterator itUpper(itLower);
        return mimp::pair<iterator, iterator>(itLower, ++itUpper);
    }
    

    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename set<Key, Compare, Allocator>::const_iterator, 
                       typename set<Key, Compare, Allocator>::const_iterator>
    set<Key, Compare, Allocator>::equal_range(const Key& k) const
    {
        // See equal_range above for comments.
        const const_iterator itLower(lower_bound(k));

        if((itLower == end()) || mCompare(k, *itLower)) // If at the end or if (k is < itLower)...
            return mimp::pair<const_iterator, const_iterator>(itLower, itLower);

        const_iterator itUpper(itLower);
        return mimp::pair<const_iterator, const_iterator>(itLower, ++itUpper);
    }





    ///////////////////////////////////////////////////////////////////////
    // multiset
    ///////////////////////////////////////////////////////////////////////

    template <typename Key, typename Compare, typename Allocator>
    inline multiset<Key, Compare, Allocator>::multiset(const allocator_type& allocator)
        : base_type(allocator)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline multiset<Key, Compare, Allocator>::multiset(const Compare& compare, const allocator_type& allocator)
        : base_type(compare, allocator)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline multiset<Key, Compare, Allocator>::multiset(const this_type& x)
        : base_type(x)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    template <typename Iterator>
    inline multiset<Key, Compare, Allocator>::multiset(Iterator itBegin, Iterator itEnd)
        : base_type(itBegin, itEnd, Compare(), EASTL_MULTISET_DEFAULT_ALLOCATOR)
    {
        // Empty
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::size_type
    multiset<Key, Compare, Allocator>::erase(const Key& k)
    {
        const mimp::pair<iterator, iterator> range(equal_range(k));
        const size_type n = (size_type)mimp::distance(range.first, range.second);
        base_type::erase(range.first, range.second);
        return n;
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::iterator
    multiset<Key, Compare, Allocator>::erase(iterator position)
    {
        // We need to provide this version because we override another version 
        // and C++ hiding rules would make the base version of this hidden.
        return base_type::erase(position);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::iterator
    multiset<Key, Compare, Allocator>::erase(iterator first, iterator last)
    {
        // We need to provide this version because we override another version 
        // and C++ hiding rules would make the base version of this hidden.
        return base_type::erase(first, last);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::size_type
    multiset<Key, Compare, Allocator>::count(const Key& k) const
    {
        const mimp::pair<const_iterator, const_iterator> range(equal_range(k));
        return (size_type)mimp::distance(range.first, range.second);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::reverse_iterator
    multiset<Key, Compare, Allocator>::erase(reverse_iterator position)
    {
        return reverse_iterator(erase((++position).base()));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline typename multiset<Key, Compare, Allocator>::reverse_iterator
    multiset<Key, Compare, Allocator>::erase(reverse_iterator first, reverse_iterator last)
    {
        // Version which erases in order from first to last.
        // difference_type i(first.base() - last.base());
        // while(i--)
        //     first = erase(first);
        // return first;

        // Version which erases in order from last to first, but is slightly more efficient:
        return reverse_iterator(erase((++last).base(), (++first).base()));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename multiset<Key, Compare, Allocator>::iterator,
                       typename multiset<Key, Compare, Allocator>::iterator>
    multiset<Key, Compare, Allocator>::equal_range(const Key& k)
    {
        // There are multiple ways to implement equal_range. The implementation mentioned
        // in the C++ standard and which is used by most (all?) commercial STL implementations
        // is this:
        //    return mimp::pair<iterator, iterator>(lower_bound(k), upper_bound(k));
        //
        // This does two tree searches -- one for the lower bound and one for the 
        // upper bound. This works well for the case whereby you have a large container
        // and there are lots of duplicated values. We provide an alternative version
        // of equal_range called equal_range_small for cases where the user is confident
        // that the number of duplicated items is only a few.

        return mimp::pair<iterator, iterator>(lower_bound(k), upper_bound(k));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename multiset<Key, Compare, Allocator>::const_iterator, 
                       typename multiset<Key, Compare, Allocator>::const_iterator>
    multiset<Key, Compare, Allocator>::equal_range(const Key& k) const
    {
        // See comments above in the non-const version of equal_range.
        return mimp::pair<iterator, iterator>(lower_bound(k), upper_bound(k));
    }


    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename multiset<Key, Compare, Allocator>::iterator,
                       typename multiset<Key, Compare, Allocator>::iterator>
    multiset<Key, Compare, Allocator>::equal_range_small(const Key& k)
    {
        // We provide alternative version of equal_range here which works faster
        // for the case where there are at most small number of potential duplicated keys.
        const iterator itLower(lower_bound(k));
        iterator       itUpper(itLower);

        while((itUpper != end()) && !mCompare(k, itUpper.mpNode->mValue))
            ++itUpper;

        return mimp::pair<iterator, iterator>(itLower, itUpper);
    }


    template <typename Key, typename Compare, typename Allocator>
    inline mimp::pair<typename multiset<Key, Compare, Allocator>::const_iterator, 
                       typename multiset<Key, Compare, Allocator>::const_iterator>
    multiset<Key, Compare, Allocator>::equal_range_small(const Key& k) const
    {
        // We provide alternative version of equal_range here which works faster
        // for the case where there are at most small number of potential duplicated keys.
        const const_iterator itLower(lower_bound(k));
        const_iterator       itUpper(itLower);

        while((itUpper != end()) && !mCompare(k, *itUpper))
            ++itUpper;

        return mimp::pair<const_iterator, const_iterator>(itLower, itUpper);
    }


} // namespace mimp


#endif // Header include guard

Commits for Divide-Dependencies/physx/APEX_1.4/shared/general/meshimport/include/utils/MiMapSet.h

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx