1
 
/*      Copyright (C) 2004 Garrett A. Kajmowicz
 
2
 
        This file is part of the uClibc++ Library.
 
4
 
        This library is free software; you can redistribute it and/or
 
5
 
        modify it under the terms of the GNU Lesser General Public
 
6
 
        License as published by the Free Software Foundation; either
 
7
 
        version 2.1 of the License, or (at your option) any later version.
 
9
 
        This library is distributed in the hope that it will be useful,
 
10
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 
        Lesser General Public License for more details.
 
14
 
        You should have received a copy of the GNU Lesser General Public
 
15
 
        License along with this library; if not, write to the Free Software
 
16
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
26
 
#include <associative_base>
 
28
 
#ifndef __STD_HEADER_SET
 
29
 
#define __STD_HEADER_SET
 
31
 
#pragma GCC visibility push(default)
 
36
 
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class set;
 
37
 
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class multiset;
 
40
 
/* This is the implementation for the set container.  As noted above, it deviates
 
41
 
 * from ISO spec by deriving from a base class in order to reduce code redundancy.
 
42
 
 * More code could be reduced by convirting to virtual functions (thus allowing
 
43
 
 * much of the erase and insert code to be duplicated), but that would deviate from
 
44
 
 * the specifications too much to be worth the risk.
 
48
 
//Implementation of set
 
51
 
template<class Key, class Compare, class Allocator> class _UCXXEXPORT set
 
52
 
        : public __single_associative<Key, Key, Compare, Allocator>
 
54
 
                //Default value of allocator does not meet C++ standard specs, but it works for this library
 
58
 
        typedef __single_associative<Key, Key, Compare, Allocator>      base;
 
59
 
        typedef typename base::key_type                                 key_type;
 
60
 
        typedef typename base::value_type                               value_type;
 
61
 
        typedef typename base::key_compare                              key_compare;
 
62
 
        typedef typename base::allocator_type                           allocator_type;
 
63
 
        typedef typename base::reference                                reference;
 
64
 
        typedef typename base::const_reference                          const_reference;
 
65
 
        typedef typename base::iterator                                 iterator;
 
66
 
        typedef typename base::const_iterator                           const_iterator;
 
67
 
        typedef typename base::size_type                                size_type;
 
68
 
        typedef typename base::difference_type                          difference_type;
 
69
 
        typedef typename base::pointer                                  pointer;
 
70
 
        typedef typename base::const_pointer                            const_pointer;
 
71
 
        typedef typename base::reverse_iterator                         reverse_iterator;
 
72
 
        typedef typename base::const_reverse_iterator                   const_reverse_iterator;
 
74
 
//      using base::value_compare;
 
76
 
        static const key_type v_t_k(const value_type v){
 
80
 
        explicit set(const Compare& comp = Compare(), const Allocator& al = Allocator())
 
81
 
                : base(comp, al, v_t_k) {  }
 
83
 
        template <class InputIterator> set(InputIterator first, InputIterator last,
 
84
 
                const Compare& comp = Compare(), const Allocator& al = Allocator())
 
85
 
                : base(first, last, comp, al, v_t_k) {  }
 
87
 
        set(const set<Key, Compare,Allocator>& x) : base(x) {  }
 
90
 
        using base::operator=;
 
91
 
        using base::operator==;
 
92
 
        using base::operator!=;
 
104
 
        using base::max_size;
 
109
 
        using base::lower_bound;
 
110
 
        using base::upper_bound;
 
111
 
        using base::equal_range;
 
118
 
//Implementation of multiset
 
121
 
template<class Key, class Compare, class Allocator> class _UCXXEXPORT multiset
 
122
 
        : public __multi_associative<Key, Key, Compare, Allocator>
 
124
 
                //Default value of allocator does not meet C++ standard specs, but it works for this library
 
128
 
        typedef __multi_associative<Key, Key, Compare, Allocator>       base;
 
129
 
        typedef typename base::key_type                                 key_type;
 
130
 
        typedef typename base::value_type                               value_type;
 
131
 
        typedef typename base::key_compare                              key_compare;
 
132
 
        typedef typename base::allocator_type                           allocator_type;
 
133
 
        typedef typename base::reference                                reference;
 
134
 
        typedef typename base::const_reference                          const_reference;
 
135
 
        typedef typename base::iterator                                 iterator;
 
136
 
        typedef typename base::const_iterator                           const_iterator;
 
137
 
        typedef typename base::size_type                                size_type;
 
138
 
        typedef typename base::difference_type                          difference_type;
 
139
 
        typedef typename base::pointer                                  pointer;
 
140
 
        typedef typename base::const_pointer                            const_pointer;
 
141
 
        typedef typename base::reverse_iterator                         reverse_iterator;
 
142
 
        typedef typename base::const_reverse_iterator                   const_reverse_iterator;
 
144
 
        static const key_type v_t_k(const value_type v){
 
148
 
        explicit multiset(const Compare& comp = Compare(), const Allocator& al = Allocator())
 
149
 
                : base(comp, al, v_t_k) {  }
 
151
 
        template <class InputIterator> multiset(InputIterator first, InputIterator last,
 
152
 
                const Compare& comp = Compare(), const Allocator& al = Allocator())
 
153
 
                : base(first, last, comp, al, v_t_k) {  }
 
156
 
        multiset(const multiset<Key, Compare, Allocator>& x) : base(x) {  }
 
159
 
        using base::operator=;
 
160
 
        using base::operator==;
 
161
 
        using base::operator!=;
 
173
 
        using base::max_size;
 
177
 
        using base::lower_bound;
 
178
 
        using base::upper_bound;
 
179
 
        using base::equal_range;
 
187
 
/* Non-member functions.  These are at the end because they are not associated with any
 
188
 
   particular class.  These will be implemented as I figure out exactly what all of 
 
189
 
   them are supposed to do, and I have time.
 
192
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator< 
 
193
 
                (const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
 
195
 
                typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
196
 
                typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
197
 
                typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
198
 
                typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
200
 
                while(first1 != last1 && first2 != last2){
 
201
 
                        if( *first1 < *first2 ){
 
204
 
                        if( *first2 < *first1 ){
 
210
 
                return first1==last1 && first2 != last2;
 
213
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator>
 
214
 
                (const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
 
216
 
                typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
217
 
                typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
218
 
                typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
219
 
                typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
221
 
                while(first1 != last1 && first2 != last2){
 
222
 
                        if( *first1 > *first2 ){
 
225
 
                        if( *first2 > *first1 ){
 
231
 
                return first1!=last1 && first2 == last2;
 
234
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator>=
 
235
 
                (const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
 
237
 
                typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
238
 
                typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
239
 
                typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
240
 
                typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
242
 
                while(first1 != last1 && first2 != last2){
 
243
 
                        if( *first1 > *first2 ){
 
246
 
                        if( *first2 > *first1 ){
 
252
 
                return first1!=last1;
 
255
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator<=
 
256
 
                (const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
 
258
 
                typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
259
 
                typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
260
 
                typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
261
 
                typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
263
 
                while(first1 != last1 && first2 != last2){
 
264
 
                        if( *first1 < *first2 ){
 
267
 
                        if( *first2 < *first1 ){
 
273
 
                return first2!=last2;
 
275
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT void swap
 
276
 
                (set<Key,Compare,Allocator>& x, set<Key,Compare,Allocator>& y)
 
282
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator==
 
283
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
285
 
                if(x.data == y.data){
 
291
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator< 
 
292
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
294
 
                typename multiset<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
295
 
                typename multiset<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
296
 
                typename multiset<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
297
 
                typename multiset<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
299
 
                while(first1 != last1 && first2 != last2){
 
300
 
                        if( *first1 < *first2 ){
 
303
 
                        if( *first2 < *first1 ){
 
309
 
                return first1==last1 && first2 != last2;
 
312
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator!=
 
313
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
315
 
                typename multiset<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
316
 
                typename multiset<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
317
 
                typename multiset<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
318
 
                typename multiset<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
320
 
                while(first1 != last1 && first2 != last2){
 
321
 
                        if( *first1 != *first2 ){
 
327
 
                return first1!=last1 || first2 != last2;
 
330
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator> 
 
331
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
333
 
                typename multiset<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
334
 
                typename multiset<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
335
 
                typename multiset<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
336
 
                typename multiset<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
338
 
                while(first1 != last1 && first2 != last2){
 
339
 
                        if( *first1 > *first2 ){
 
342
 
                        if( *first2 > *first1 ){
 
348
 
                return first1!=last1 && first2 == last2;
 
351
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator>=
 
352
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
354
 
                typename multiset<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
355
 
                typename multiset<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
356
 
                typename multiset<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
357
 
                typename multiset<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
359
 
                while(first1 != last1 && first2 != last2){
 
360
 
                        if( *first1 > *first2 ){
 
363
 
                        if( *first2 > *first1 ){
 
369
 
                return first1!=last1;
 
372
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator<=
 
373
 
                (const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
 
375
 
                typename multiset<Key,Compare,Allocator>::const_iterator first1 = x.begin();
 
376
 
                typename multiset<Key,Compare,Allocator>::const_iterator first2 = y.begin();
 
377
 
                typename multiset<Key,Compare,Allocator>::const_iterator last1 = x.end();
 
378
 
                typename multiset<Key,Compare,Allocator>::const_iterator last2 = y.end();
 
380
 
                while(first1 != last1 && first2 != last2){
 
381
 
                        if( *first1 < *first2 ){
 
384
 
                        if( *first2 < *first1 ){
 
390
 
                return first2!=last2;
 
393
 
        template <class Key, class Compare, class Allocator> _UCXXEXPORT void swap
 
394
 
                (multiset<Key,Compare,Allocator>& x, multiset<Key,Compare,Allocator>& y)
 
403
 
#pragma GCC visibility pop