YkESet 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Yk/EMMap/Iterator.html +626 -0
- data/docs/Yk/EMMap.html +1504 -0
- data/docs/Yk/EMSet/Iterator.html +626 -0
- data/docs/Yk/EMSet.html +1472 -0
- data/docs/Yk/EMap/Iterator.html +626 -0
- data/docs/Yk/EMap.html +1730 -0
- data/docs/Yk/ESet/Iterator.html +626 -0
- data/docs/Yk/ESet.html +1472 -0
- data/docs/Yk.html +126 -0
- data/docs/_index.html +170 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file_list.html +51 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +170 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +571 -0
- data/docs/top-level-namespace.html +110 -0
- data/eset.gemspec +29 -0
- data/ext/Yk/.ruby-version +1 -0
- data/ext/Yk/.yardoc/checksums +1 -0
- data/ext/Yk/.yardoc/complete +0 -0
- data/ext/Yk/.yardoc/object_types +0 -0
- data/ext/Yk/.yardoc/objects/root.dat +0 -0
- data/ext/Yk/.yardoc/proxy_types +0 -0
- data/ext/Yk/Makefile +267 -0
- data/ext/Yk/depend +2 -0
- data/ext/Yk/extconf.rb +7 -0
- data/ext/Yk/for_yard.rb +192 -0
- data/ext/Yk/for_yard_product.rb +397 -0
- data/ext/Yk/map_tz +78 -0
- data/ext/Yk/set_tz +77 -0
- data/ext/Yk/stl_map_tz.h +1026 -0
- data/ext/Yk/stl_multimap_tz.h +927 -0
- data/ext/Yk/stl_multiset_tz.h +805 -0
- data/ext/Yk/stl_set_tz.h +815 -0
- data/ext/Yk/stl_set_tz_ruby.cpp +575 -0
- data/ext/Yk/stl_tree_tz.h +1865 -0
- data/ext/Yk/test_set.rb +115 -0
- data/ext/Yk/tree_tz.cc +489 -0
- data/ext/Yk/tz_stl_auto.cpp +84 -0
- data/lib/eset/version.rb +3 -0
- data/lib/eset.rb +7 -0
- metadata +101 -0
|
@@ -0,0 +1,1865 @@
|
|
|
1
|
+
// RB tree implementation -*- C++ -*-
|
|
2
|
+
|
|
3
|
+
// Copyright (C) 2001-2013 Free Software Foundation, Inc.
|
|
4
|
+
//
|
|
5
|
+
// This file is part of the GNU ISO C++ Library. This library is free
|
|
6
|
+
// software; you can redistribute it and/or modify it under the
|
|
7
|
+
// terms of the GNU General Public License as published by the
|
|
8
|
+
// Free Software Foundation; either version 3, or (at your option)
|
|
9
|
+
// any later version.
|
|
10
|
+
|
|
11
|
+
// This library is distributed in the hope that it will be useful,
|
|
12
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
// GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
// Under Section 7 of GPL version 3, you are granted additional
|
|
17
|
+
// permissions described in the GCC Runtime Library Exception, version
|
|
18
|
+
// 3.1, as published by the Free Software Foundation.
|
|
19
|
+
|
|
20
|
+
// You should have received a copy of the GNU General Public License and
|
|
21
|
+
// a copy of the GCC Runtime Library Exception along with this program;
|
|
22
|
+
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
23
|
+
// <http://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
*
|
|
27
|
+
* Copyright (c) 1996,1997
|
|
28
|
+
* Silicon Graphics Computer Systems, Inc.
|
|
29
|
+
*
|
|
30
|
+
* Permission to use, copy, modify, distribute and sell this software
|
|
31
|
+
* and its documentation for any purpose is hereby granted without fee,
|
|
32
|
+
* provided that the above copyright notice appear in all copies and
|
|
33
|
+
* that both that copyright notice and this permission notice appear
|
|
34
|
+
* in supporting documentation. Silicon Graphics makes no
|
|
35
|
+
* representations about the suitability of this software for any
|
|
36
|
+
* purpose. It is provided "as is" without express or implied warranty.
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
* Copyright (c) 1994
|
|
40
|
+
* Hewlett-Packard Company
|
|
41
|
+
*
|
|
42
|
+
* Permission to use, copy, modify, distribute and sell this software
|
|
43
|
+
* and its documentation for any purpose is hereby granted without fee,
|
|
44
|
+
* provided that the above copyright notice appear in all copies and
|
|
45
|
+
* that both that copyright notice and this permission notice appear
|
|
46
|
+
* in supporting documentation. Hewlett-Packard Company makes no
|
|
47
|
+
* representations about the suitability of this software for any
|
|
48
|
+
* purpose. It is provided "as is" without express or implied warranty.
|
|
49
|
+
*
|
|
50
|
+
* Copyright (c) 2020
|
|
51
|
+
*
|
|
52
|
+
* Yougaein@github (Kokeji Yougain)
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/** @file bits/stl_tree.h
|
|
57
|
+
* This is an internal header file, included by other library headers.
|
|
58
|
+
* Do not attempt to use it directly. @headername{map,set}
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
#ifndef _STL_TREE_TZ_H
|
|
62
|
+
#define _STL_TREE_TZ_H 1
|
|
63
|
+
|
|
64
|
+
#include <bits/stl_algobase.h>
|
|
65
|
+
#include <bits/allocator.h>
|
|
66
|
+
#include <bits/stl_function.h>
|
|
67
|
+
#include <bits/cpp_type_traits.h>
|
|
68
|
+
#include <bits/alloc_traits.h>
|
|
69
|
+
#include <iostream>
|
|
70
|
+
#include <ruby.h>
|
|
71
|
+
|
|
72
|
+
namespace tz _GLIBCXX_VISIBILITY(default)
|
|
73
|
+
{
|
|
74
|
+
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
75
|
+
using namespace std;
|
|
76
|
+
|
|
77
|
+
// Red-black tree class, designed for use in implementing STL
|
|
78
|
+
// associative containers (set, multiset, map, and multimap). The
|
|
79
|
+
// insertion and deletion algorithms are based on those in Cormen,
|
|
80
|
+
// Leiserson, and Rivest, Introduction to Algorithms (MIT Press,
|
|
81
|
+
// 1990), except that
|
|
82
|
+
//
|
|
83
|
+
// (1) the header cell is maintained with links not only to the root
|
|
84
|
+
// but also to the leftmost node of the tree, to enable constant
|
|
85
|
+
// time begin(), and to the rightmost node of the tree, to enable
|
|
86
|
+
// linear time performance when used with the generic set algorithms
|
|
87
|
+
// (set_union, etc.)
|
|
88
|
+
//
|
|
89
|
+
// (2) when a node being deleted has two children its successor node
|
|
90
|
+
// is relinked into its place, rather than copied, so that the only
|
|
91
|
+
// iterators invalidated are those referring to the deleted node.
|
|
92
|
+
|
|
93
|
+
enum _Rb_tree_color { _S_red = false, _S_black = true };
|
|
94
|
+
|
|
95
|
+
struct _Rb_tree_node_base
|
|
96
|
+
{
|
|
97
|
+
typedef _Rb_tree_node_base* _Base_ptr;
|
|
98
|
+
typedef const _Rb_tree_node_base* _Const_Base_ptr;
|
|
99
|
+
|
|
100
|
+
_Rb_tree_color _M_color;
|
|
101
|
+
_Base_ptr _M_parent;
|
|
102
|
+
_Base_ptr _M_left;
|
|
103
|
+
_Base_ptr _M_right;
|
|
104
|
+
int _TZ_refCount;
|
|
105
|
+
void* _TZ_tree;
|
|
106
|
+
void (*_TZ_destroyer)(_Rb_tree_node_base*);
|
|
107
|
+
|
|
108
|
+
_Rb_tree_node_base() : _TZ_refCount(0), _TZ_destroyer(0), _M_parent(0), _M_left(this), _M_right(this) { }
|
|
109
|
+
~_Rb_tree_node_base(){
|
|
110
|
+
_M_left = this;
|
|
111
|
+
_M_right = this;
|
|
112
|
+
_M_parent = 0;
|
|
113
|
+
_M_color = _S_red;
|
|
114
|
+
}
|
|
115
|
+
void prepareDestroy(void (*destroyer)(_Rb_tree_node_base*)){
|
|
116
|
+
_M_left = this;
|
|
117
|
+
_M_right = this;
|
|
118
|
+
_M_parent = 0;
|
|
119
|
+
_M_color = _S_red;
|
|
120
|
+
_TZ_destroyer = destroyer;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static _Base_ptr
|
|
124
|
+
_S_minimum(_Base_ptr __x)
|
|
125
|
+
{
|
|
126
|
+
while (__x->_M_left != 0) __x = __x->_M_left;
|
|
127
|
+
return __x;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static _Const_Base_ptr
|
|
131
|
+
_S_minimum(_Const_Base_ptr __x)
|
|
132
|
+
{
|
|
133
|
+
while (__x->_M_left != 0) __x = __x->_M_left;
|
|
134
|
+
return __x;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static _Base_ptr
|
|
138
|
+
_S_maximum(_Base_ptr __x)
|
|
139
|
+
{
|
|
140
|
+
while (__x->_M_right != 0) __x = __x->_M_right;
|
|
141
|
+
return __x;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static _Const_Base_ptr
|
|
145
|
+
_S_maximum(_Const_Base_ptr __x)
|
|
146
|
+
{
|
|
147
|
+
while (__x->_M_right != 0) __x = __x->_M_right;
|
|
148
|
+
return __x;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
template<typename _Val>
|
|
153
|
+
struct _Rb_tree_node : public _Rb_tree_node_base
|
|
154
|
+
{
|
|
155
|
+
typedef _Rb_tree_node<_Val>* _Link_type;
|
|
156
|
+
_Val _M_value_field;
|
|
157
|
+
|
|
158
|
+
template<typename... _Args>
|
|
159
|
+
_Rb_tree_node(_Args&&... __args)
|
|
160
|
+
: _Rb_tree_node_base(),
|
|
161
|
+
_M_value_field(std::forward<_Args>(__args)...) { }
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
_GLIBCXX_PURE _Rb_tree_node_base*
|
|
165
|
+
_Rb_tree_increment(_Rb_tree_node_base* __x) throw ();
|
|
166
|
+
|
|
167
|
+
_GLIBCXX_PURE const _Rb_tree_node_base*
|
|
168
|
+
_Rb_tree_increment(const _Rb_tree_node_base* __x) throw ();
|
|
169
|
+
|
|
170
|
+
_GLIBCXX_PURE _Rb_tree_node_base*
|
|
171
|
+
_Rb_tree_decrement(_Rb_tree_node_base* __x) throw ();
|
|
172
|
+
|
|
173
|
+
_GLIBCXX_PURE const _Rb_tree_node_base*
|
|
174
|
+
_Rb_tree_decrement(const _Rb_tree_node_base* __x) throw ();
|
|
175
|
+
|
|
176
|
+
template<typename _Tp>
|
|
177
|
+
struct _Rb_tree_iterator
|
|
178
|
+
{
|
|
179
|
+
typedef _Tp value_type;
|
|
180
|
+
typedef _Tp& reference;
|
|
181
|
+
typedef _Tp* pointer;
|
|
182
|
+
|
|
183
|
+
typedef bidirectional_iterator_tag iterator_category;
|
|
184
|
+
typedef ptrdiff_t difference_type;
|
|
185
|
+
|
|
186
|
+
typedef _Rb_tree_iterator<_Tp> _Self;
|
|
187
|
+
typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
|
|
188
|
+
typedef _Rb_tree_node<_Tp>* _Link_type;
|
|
189
|
+
|
|
190
|
+
_Rb_tree_iterator()
|
|
191
|
+
: _M_node(0) {
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
explicit
|
|
195
|
+
_Rb_tree_iterator(_Link_type __x)
|
|
196
|
+
: _M_node(__x) {
|
|
197
|
+
_M_node->_TZ_refCount += 1;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
_Rb_tree_iterator(const _Rb_tree_iterator<_Tp>& arg) : _M_node(arg._M_node){
|
|
201
|
+
if(_M_node)
|
|
202
|
+
_M_node->_TZ_refCount += 1;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
~_Rb_tree_iterator(){
|
|
206
|
+
if(_M_node){
|
|
207
|
+
_M_node->_TZ_refCount -= 1;
|
|
208
|
+
if(_M_node->_TZ_refCount == 0 && _M_node->_TZ_destroyer){
|
|
209
|
+
_M_node->_TZ_destroyer(_M_node);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_Rb_tree_iterator<_Tp>& operator=(const _Rb_tree_iterator<_Tp>& arg){
|
|
215
|
+
if(_M_node != arg._M_node){
|
|
216
|
+
if(_M_node)
|
|
217
|
+
_M_node->_TZ_refCount -= 1;
|
|
218
|
+
_M_node = arg._M_node;
|
|
219
|
+
if(_M_node)
|
|
220
|
+
_M_node->_TZ_refCount += 1;
|
|
221
|
+
}
|
|
222
|
+
return *this;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
reference
|
|
226
|
+
operator*() const
|
|
227
|
+
{
|
|
228
|
+
return static_cast<_Link_type>(_M_node)->_M_value_field;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
pointer
|
|
232
|
+
operator->() const
|
|
233
|
+
{
|
|
234
|
+
return std::__addressof(static_cast<_Link_type>
|
|
235
|
+
(_M_node)->_M_value_field);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_Self&
|
|
239
|
+
operator++()
|
|
240
|
+
{
|
|
241
|
+
_M_node = _Rb_tree_increment(_M_node);
|
|
242
|
+
return *this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
_Self
|
|
246
|
+
operator++(int)
|
|
247
|
+
{
|
|
248
|
+
_Self __tmp = *this;
|
|
249
|
+
_M_node = _Rb_tree_increment(_M_node);
|
|
250
|
+
return __tmp;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
_Self&
|
|
254
|
+
operator--()
|
|
255
|
+
{
|
|
256
|
+
_M_node = _Rb_tree_decrement(_M_node);
|
|
257
|
+
return *this;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
_Self
|
|
261
|
+
operator--(int)
|
|
262
|
+
{
|
|
263
|
+
_Self __tmp = *this;
|
|
264
|
+
_M_node = _Rb_tree_decrement(_M_node);
|
|
265
|
+
return __tmp;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
bool
|
|
269
|
+
operator==(const _Self& __x) const
|
|
270
|
+
{ return _M_node == __x._M_node; }
|
|
271
|
+
|
|
272
|
+
bool
|
|
273
|
+
operator!=(const _Self& __x) const
|
|
274
|
+
{ return _M_node != __x._M_node; }
|
|
275
|
+
|
|
276
|
+
_Base_ptr _M_node;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
template<typename _Tp>
|
|
280
|
+
struct _Rb_tree_const_iterator
|
|
281
|
+
{
|
|
282
|
+
typedef _Tp value_type;
|
|
283
|
+
typedef const _Tp& reference;
|
|
284
|
+
typedef const _Tp* pointer;
|
|
285
|
+
|
|
286
|
+
typedef _Rb_tree_iterator<_Tp> iterator;
|
|
287
|
+
|
|
288
|
+
typedef bidirectional_iterator_tag iterator_category;
|
|
289
|
+
typedef ptrdiff_t difference_type;
|
|
290
|
+
|
|
291
|
+
typedef _Rb_tree_const_iterator<_Tp> _Self;
|
|
292
|
+
typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
|
|
293
|
+
typedef const _Rb_tree_node<_Tp>* _Link_type;
|
|
294
|
+
|
|
295
|
+
_Rb_tree_const_iterator()
|
|
296
|
+
: _M_node(0) {
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
explicit
|
|
300
|
+
_Rb_tree_const_iterator(_Link_type __x)
|
|
301
|
+
: _M_node(__x) {
|
|
302
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount += 1;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
_Rb_tree_const_iterator(const iterator& __it)
|
|
306
|
+
: _M_node(__it._M_node) {
|
|
307
|
+
if(_M_node)
|
|
308
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount += 1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
_Rb_tree_const_iterator(const _Rb_tree_const_iterator& __it) : _M_node(__it._M_node) {
|
|
312
|
+
if(_M_node)
|
|
313
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount += 1;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
~_Rb_tree_const_iterator(){
|
|
317
|
+
if(_M_node){
|
|
318
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount -= 1;
|
|
319
|
+
if(_M_node->_TZ_refCount == 0 && _M_node->_TZ_destroyer){
|
|
320
|
+
_M_node->_TZ_destroyer((_Rb_tree_node_base*)_M_node);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
_Rb_tree_const_iterator<_Tp>& operator=(const _Rb_tree_const_iterator<_Tp>& arg){
|
|
326
|
+
if(_M_node != arg._M_node){
|
|
327
|
+
if(_M_node)
|
|
328
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount -= 1;
|
|
329
|
+
_M_node = arg._M_node;
|
|
330
|
+
if(_M_node)
|
|
331
|
+
((_Rb_tree_node_base*)_M_node)->_TZ_refCount += 1;
|
|
332
|
+
}
|
|
333
|
+
return *this;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
iterator
|
|
337
|
+
_M_const_cast() const
|
|
338
|
+
{ return iterator(static_cast<typename iterator::_Link_type>
|
|
339
|
+
(const_cast<typename iterator::_Base_ptr>(_M_node))); }
|
|
340
|
+
|
|
341
|
+
reference
|
|
342
|
+
operator*() const
|
|
343
|
+
{
|
|
344
|
+
return static_cast<_Link_type>(_M_node)->_M_value_field;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
pointer
|
|
348
|
+
operator->() const
|
|
349
|
+
{
|
|
350
|
+
return std::__addressof(static_cast<_Link_type>
|
|
351
|
+
(_M_node)->_M_value_field);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
_Self&
|
|
355
|
+
operator++()
|
|
356
|
+
{
|
|
357
|
+
_M_node = _Rb_tree_increment(_M_node);
|
|
358
|
+
return *this;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
_Self
|
|
362
|
+
operator++(int)
|
|
363
|
+
{
|
|
364
|
+
_Self __tmp = *this;
|
|
365
|
+
_M_node = _Rb_tree_increment(_M_node);
|
|
366
|
+
return __tmp;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
_Self&
|
|
370
|
+
operator--()
|
|
371
|
+
{
|
|
372
|
+
_M_node = _Rb_tree_decrement(_M_node);
|
|
373
|
+
return *this;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
_Self
|
|
377
|
+
operator--(int)
|
|
378
|
+
{
|
|
379
|
+
_Self __tmp = *this;
|
|
380
|
+
_M_node = _Rb_tree_decrement(_M_node);
|
|
381
|
+
return __tmp;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
bool
|
|
385
|
+
operator==(const _Self& __x) const
|
|
386
|
+
{ return _M_node == __x._M_node; }
|
|
387
|
+
|
|
388
|
+
bool
|
|
389
|
+
operator!=(const _Self& __x) const
|
|
390
|
+
{ return _M_node != __x._M_node; }
|
|
391
|
+
|
|
392
|
+
_Base_ptr _M_node;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
template<typename _Val>
|
|
396
|
+
inline bool
|
|
397
|
+
operator==(const _Rb_tree_iterator<_Val>& __x,
|
|
398
|
+
const _Rb_tree_const_iterator<_Val>& __y)
|
|
399
|
+
{ return __x._M_node == __y._M_node; }
|
|
400
|
+
|
|
401
|
+
template<typename _Val>
|
|
402
|
+
inline bool
|
|
403
|
+
operator!=(const _Rb_tree_iterator<_Val>& __x,
|
|
404
|
+
const _Rb_tree_const_iterator<_Val>& __y)
|
|
405
|
+
{ return __x._M_node != __y._M_node; }
|
|
406
|
+
|
|
407
|
+
void
|
|
408
|
+
_Rb_tree_insert_and_rebalance(const bool __insert_left,
|
|
409
|
+
_Rb_tree_node_base* __x,
|
|
410
|
+
_Rb_tree_node_base* __p,
|
|
411
|
+
_Rb_tree_node_base& __header) throw ();
|
|
412
|
+
|
|
413
|
+
_Rb_tree_node_base*
|
|
414
|
+
_Rb_tree_rebalance_for_erase(_Rb_tree_node_base* const __z,
|
|
415
|
+
_Rb_tree_node_base& __header) throw ();
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
419
|
+
typename _Compare, typename _Alloc = allocator<_Val> >
|
|
420
|
+
class _Rb_tree
|
|
421
|
+
{
|
|
422
|
+
typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other
|
|
423
|
+
_Node_allocator;
|
|
424
|
+
|
|
425
|
+
protected:
|
|
426
|
+
typedef _Rb_tree_node_base* _Base_ptr;
|
|
427
|
+
typedef const _Rb_tree_node_base* _Const_Base_ptr;
|
|
428
|
+
|
|
429
|
+
public:
|
|
430
|
+
typedef _Key key_type;
|
|
431
|
+
typedef _Val value_type;
|
|
432
|
+
typedef value_type* pointer;
|
|
433
|
+
typedef const value_type* const_pointer;
|
|
434
|
+
typedef value_type& reference;
|
|
435
|
+
typedef const value_type& const_reference;
|
|
436
|
+
typedef _Rb_tree_node<_Val>* _Link_type;
|
|
437
|
+
typedef const _Rb_tree_node<_Val>* _Const_Link_type;
|
|
438
|
+
typedef size_t size_type;
|
|
439
|
+
typedef ptrdiff_t difference_type;
|
|
440
|
+
typedef _Alloc allocator_type;
|
|
441
|
+
|
|
442
|
+
_Node_allocator&
|
|
443
|
+
_M_get_Node_allocator() _GLIBCXX_NOEXCEPT
|
|
444
|
+
{ return *static_cast<_Node_allocator*>(&this->_M_impl); }
|
|
445
|
+
|
|
446
|
+
const _Node_allocator&
|
|
447
|
+
_M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
|
|
448
|
+
{ return *static_cast<const _Node_allocator*>(&this->_M_impl); }
|
|
449
|
+
|
|
450
|
+
allocator_type
|
|
451
|
+
get_allocator() const _GLIBCXX_NOEXCEPT
|
|
452
|
+
{ return allocator_type(_M_get_Node_allocator()); }
|
|
453
|
+
|
|
454
|
+
protected:
|
|
455
|
+
_Link_type
|
|
456
|
+
_M_get_node()
|
|
457
|
+
{
|
|
458
|
+
_Link_type tmp = _M_impl._Node_allocator::allocate(1);
|
|
459
|
+
return tmp;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
void
|
|
463
|
+
_M_put_node(_Link_type __p)
|
|
464
|
+
{
|
|
465
|
+
if(__p->_TZ_refCount == 0)
|
|
466
|
+
_M_impl._Node_allocator::deallocate(__p, 1);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
template<typename... _Args>
|
|
470
|
+
_Link_type
|
|
471
|
+
_M_create_node(_Args&&... __args)
|
|
472
|
+
{
|
|
473
|
+
_Link_type __tmp = _M_get_node();
|
|
474
|
+
__try
|
|
475
|
+
{
|
|
476
|
+
allocator_traits<_Node_allocator>::
|
|
477
|
+
construct(_M_get_Node_allocator(), __tmp,
|
|
478
|
+
std::forward<_Args>(__args)...);
|
|
479
|
+
__tmp->_TZ_tree = this;
|
|
480
|
+
}
|
|
481
|
+
__catch(...)
|
|
482
|
+
{
|
|
483
|
+
_M_put_node(__tmp);
|
|
484
|
+
__throw_exception_again;
|
|
485
|
+
}
|
|
486
|
+
return __tmp;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
void
|
|
490
|
+
_M_destroy_node(_Link_type __p)
|
|
491
|
+
{
|
|
492
|
+
_M_get_Node_allocator().destroy(__p);
|
|
493
|
+
_M_put_node(__p);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
_Link_type
|
|
497
|
+
_M_clone_node(_Const_Link_type __x)
|
|
498
|
+
{
|
|
499
|
+
_Link_type __tmp = _M_create_node(__x->_M_value_field);
|
|
500
|
+
__tmp->_M_color = __x->_M_color;
|
|
501
|
+
__tmp->_M_left = 0;
|
|
502
|
+
__tmp->_M_right = 0;
|
|
503
|
+
return __tmp;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
protected:
|
|
507
|
+
template<typename _Key_compare,
|
|
508
|
+
bool _Is_pod_comparator = __is_pod(_Key_compare)>
|
|
509
|
+
struct _Rb_tree_impl : public _Node_allocator
|
|
510
|
+
{
|
|
511
|
+
_Key_compare _M_key_compare;
|
|
512
|
+
_Rb_tree_node_base& _M_header;
|
|
513
|
+
size_type _M_node_count; // Keeps track of size of tree.
|
|
514
|
+
|
|
515
|
+
_Rb_tree_impl()
|
|
516
|
+
: _Node_allocator(), _M_key_compare(), _M_header(*new _Rb_tree_node_base),
|
|
517
|
+
_M_node_count(0)
|
|
518
|
+
{ _M_initialize(); }
|
|
519
|
+
|
|
520
|
+
static void destroyNode(_Rb_tree_node_base* p){
|
|
521
|
+
_Node_allocator().destroy((_Link_type)p);
|
|
522
|
+
_Node_allocator().deallocate((_Link_type)p, 1);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
static void _TZ_simple_delete(_Rb_tree_node_base* __p){
|
|
526
|
+
delete __p;
|
|
527
|
+
}
|
|
528
|
+
~_Rb_tree_impl(){
|
|
529
|
+
_Rb_tree_node_base* __p = &_M_header;
|
|
530
|
+
if(__p->_TZ_refCount == 0){
|
|
531
|
+
delete __p;
|
|
532
|
+
}else{
|
|
533
|
+
__p->prepareDestroy(&_TZ_simple_delete);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
_Rb_tree_impl(const _Key_compare& __comp, const _Node_allocator& __a)
|
|
538
|
+
: _Node_allocator(__a), _M_key_compare(__comp), _M_header(*new _Rb_tree_node_base),
|
|
539
|
+
_M_node_count(0)
|
|
540
|
+
{ _M_initialize(); }
|
|
541
|
+
|
|
542
|
+
_Rb_tree_impl(const _Key_compare& __comp, _Node_allocator&& __a)
|
|
543
|
+
: _Node_allocator(std::move(__a)), _M_key_compare(__comp),
|
|
544
|
+
_M_header(*new _Rb_tree_node_base), _M_node_count(0)
|
|
545
|
+
{ _M_initialize(); }
|
|
546
|
+
|
|
547
|
+
private:
|
|
548
|
+
void
|
|
549
|
+
_M_initialize()
|
|
550
|
+
{
|
|
551
|
+
this->_M_header._M_color = _S_red;
|
|
552
|
+
this->_M_header._M_parent = 0;
|
|
553
|
+
this->_M_header._M_left = &this->_M_header;
|
|
554
|
+
this->_M_header._M_right = &this->_M_header;
|
|
555
|
+
this->_M_header._TZ_tree = this;
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
public:
|
|
559
|
+
_Rb_tree_impl<_Compare> _M_impl;
|
|
560
|
+
VALUE memo;
|
|
561
|
+
|
|
562
|
+
protected:
|
|
563
|
+
_Base_ptr&
|
|
564
|
+
_M_root()
|
|
565
|
+
{ return this->_M_impl._M_header._M_parent; }
|
|
566
|
+
|
|
567
|
+
_Const_Base_ptr
|
|
568
|
+
_M_root() const
|
|
569
|
+
{ return this->_M_impl._M_header._M_parent; }
|
|
570
|
+
|
|
571
|
+
_Base_ptr&
|
|
572
|
+
_M_leftmost()
|
|
573
|
+
{ return this->_M_impl._M_header._M_left; }
|
|
574
|
+
|
|
575
|
+
_Const_Base_ptr
|
|
576
|
+
_M_leftmost() const
|
|
577
|
+
{ return this->_M_impl._M_header._M_left; }
|
|
578
|
+
|
|
579
|
+
_Base_ptr&
|
|
580
|
+
_M_rightmost()
|
|
581
|
+
{ return this->_M_impl._M_header._M_right; }
|
|
582
|
+
|
|
583
|
+
_Const_Base_ptr
|
|
584
|
+
_M_rightmost() const
|
|
585
|
+
{ return this->_M_impl._M_header._M_right; }
|
|
586
|
+
|
|
587
|
+
_Link_type
|
|
588
|
+
_M_begin()
|
|
589
|
+
{ return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
|
|
590
|
+
|
|
591
|
+
_Const_Link_type
|
|
592
|
+
_M_begin() const
|
|
593
|
+
{
|
|
594
|
+
return static_cast<_Const_Link_type>
|
|
595
|
+
(this->_M_impl._M_header._M_parent);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
_Link_type
|
|
599
|
+
_M_end()
|
|
600
|
+
{ return reinterpret_cast<_Link_type>(&this->_M_impl._M_header); }
|
|
601
|
+
|
|
602
|
+
_Const_Link_type
|
|
603
|
+
_M_end() const
|
|
604
|
+
{ return reinterpret_cast<_Const_Link_type>(&this->_M_impl._M_header); }
|
|
605
|
+
|
|
606
|
+
static const_reference
|
|
607
|
+
_S_value(_Const_Link_type __x)
|
|
608
|
+
{ return __x->_M_value_field; }
|
|
609
|
+
|
|
610
|
+
static const _Key&
|
|
611
|
+
_S_key(_Const_Link_type __x)
|
|
612
|
+
{ return _KeyOfValue()(_S_value(__x)); }
|
|
613
|
+
|
|
614
|
+
static _Link_type
|
|
615
|
+
_S_left(_Base_ptr __x)
|
|
616
|
+
{ return static_cast<_Link_type>(__x->_M_left); }
|
|
617
|
+
|
|
618
|
+
static _Const_Link_type
|
|
619
|
+
_S_left(_Const_Base_ptr __x)
|
|
620
|
+
{ return static_cast<_Const_Link_type>(__x->_M_left); }
|
|
621
|
+
|
|
622
|
+
static _Link_type
|
|
623
|
+
_S_right(_Base_ptr __x)
|
|
624
|
+
{ return static_cast<_Link_type>(__x->_M_right); }
|
|
625
|
+
|
|
626
|
+
static _Const_Link_type
|
|
627
|
+
_S_right(_Const_Base_ptr __x)
|
|
628
|
+
{ return static_cast<_Const_Link_type>(__x->_M_right); }
|
|
629
|
+
|
|
630
|
+
static const_reference
|
|
631
|
+
_S_value(_Const_Base_ptr __x)
|
|
632
|
+
{ return static_cast<_Const_Link_type>(__x)->_M_value_field; }
|
|
633
|
+
|
|
634
|
+
static const _Key&
|
|
635
|
+
_S_key(_Const_Base_ptr __x)
|
|
636
|
+
{ return _KeyOfValue()(_S_value(__x)); }
|
|
637
|
+
|
|
638
|
+
static _Base_ptr
|
|
639
|
+
_S_minimum(_Base_ptr __x)
|
|
640
|
+
{ return _Rb_tree_node_base::_S_minimum(__x); }
|
|
641
|
+
|
|
642
|
+
static _Const_Base_ptr
|
|
643
|
+
_S_minimum(_Const_Base_ptr __x)
|
|
644
|
+
{ return _Rb_tree_node_base::_S_minimum(__x); }
|
|
645
|
+
|
|
646
|
+
static _Base_ptr
|
|
647
|
+
_S_maximum(_Base_ptr __x)
|
|
648
|
+
{ return _Rb_tree_node_base::_S_maximum(__x); }
|
|
649
|
+
|
|
650
|
+
static _Const_Base_ptr
|
|
651
|
+
_S_maximum(_Const_Base_ptr __x)
|
|
652
|
+
{ return _Rb_tree_node_base::_S_maximum(__x); }
|
|
653
|
+
|
|
654
|
+
public:
|
|
655
|
+
typedef _Rb_tree_iterator<value_type> iterator;
|
|
656
|
+
typedef _Rb_tree_const_iterator<value_type> const_iterator;
|
|
657
|
+
|
|
658
|
+
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
659
|
+
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
660
|
+
|
|
661
|
+
private:
|
|
662
|
+
pair<_Base_ptr, _Base_ptr>
|
|
663
|
+
_M_get_insert_unique_pos(const key_type& __k);
|
|
664
|
+
|
|
665
|
+
pair<_Base_ptr, _Base_ptr>
|
|
666
|
+
_M_get_insert_equal_pos(const key_type& __k);
|
|
667
|
+
|
|
668
|
+
pair<_Base_ptr, _Base_ptr>
|
|
669
|
+
_M_get_insert_hint_unique_pos(const_iterator __pos,
|
|
670
|
+
const key_type& __k);
|
|
671
|
+
|
|
672
|
+
pair<_Base_ptr, _Base_ptr>
|
|
673
|
+
_M_get_insert_hint_equal_pos(const_iterator __pos,
|
|
674
|
+
const key_type& __k);
|
|
675
|
+
|
|
676
|
+
template<typename _Arg>
|
|
677
|
+
iterator
|
|
678
|
+
_M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v);
|
|
679
|
+
|
|
680
|
+
iterator
|
|
681
|
+
_M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
|
|
682
|
+
|
|
683
|
+
template<typename _Arg>
|
|
684
|
+
iterator
|
|
685
|
+
_M_insert_lower(_Base_ptr __y, _Arg&& __v);
|
|
686
|
+
|
|
687
|
+
template<typename _Arg>
|
|
688
|
+
iterator
|
|
689
|
+
_M_insert_equal_lower(_Arg&& __x);
|
|
690
|
+
|
|
691
|
+
iterator
|
|
692
|
+
_M_insert_lower_node(_Base_ptr __p, _Link_type __z);
|
|
693
|
+
|
|
694
|
+
iterator
|
|
695
|
+
_M_insert_equal_lower_node(_Link_type __z);
|
|
696
|
+
|
|
697
|
+
_Link_type
|
|
698
|
+
_M_copy(_Const_Link_type __x, _Link_type __p);
|
|
699
|
+
|
|
700
|
+
void
|
|
701
|
+
_M_erase(_Link_type __x);
|
|
702
|
+
|
|
703
|
+
iterator
|
|
704
|
+
_M_lower_bound(_Link_type __x, _Link_type __y,
|
|
705
|
+
const _Key& __k);
|
|
706
|
+
|
|
707
|
+
const_iterator
|
|
708
|
+
_M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
|
|
709
|
+
const _Key& __k) const;
|
|
710
|
+
|
|
711
|
+
iterator
|
|
712
|
+
_M_upper_bound(_Link_type __x, _Link_type __y,
|
|
713
|
+
const _Key& __k);
|
|
714
|
+
|
|
715
|
+
const_iterator
|
|
716
|
+
_M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
|
|
717
|
+
const _Key& __k) const;
|
|
718
|
+
|
|
719
|
+
public:
|
|
720
|
+
// allocation/deallocation
|
|
721
|
+
_Rb_tree() : memo(0){ }
|
|
722
|
+
|
|
723
|
+
_Rb_tree(const _Compare& __comp,
|
|
724
|
+
const allocator_type& __a = allocator_type())
|
|
725
|
+
: memo(0), _M_impl(__comp, _Node_allocator(__a)) { }
|
|
726
|
+
|
|
727
|
+
_Rb_tree(const _Rb_tree& __x)
|
|
728
|
+
: memo(0), _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
|
|
729
|
+
{
|
|
730
|
+
if (__x._M_root() != 0)
|
|
731
|
+
{
|
|
732
|
+
_M_root() = _M_copy(__x._M_begin(), _M_end());
|
|
733
|
+
_M_leftmost() = _S_minimum(_M_root());
|
|
734
|
+
_M_rightmost() = _S_maximum(_M_root());
|
|
735
|
+
_M_impl._M_node_count = __x._M_impl._M_node_count;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
_Rb_tree(_Rb_tree&& __x);
|
|
740
|
+
|
|
741
|
+
~_Rb_tree() _GLIBCXX_NOEXCEPT
|
|
742
|
+
{ _M_erase(_M_begin()); }
|
|
743
|
+
|
|
744
|
+
_Rb_tree&
|
|
745
|
+
operator=(const _Rb_tree& __x);
|
|
746
|
+
|
|
747
|
+
// Accessors.
|
|
748
|
+
_Compare
|
|
749
|
+
key_comp() const
|
|
750
|
+
{ return _M_impl._M_key_compare; }
|
|
751
|
+
|
|
752
|
+
iterator
|
|
753
|
+
begin() _GLIBCXX_NOEXCEPT
|
|
754
|
+
{
|
|
755
|
+
return iterator(static_cast<_Link_type>
|
|
756
|
+
(this->_M_impl._M_header._M_left));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const_iterator
|
|
760
|
+
begin() const _GLIBCXX_NOEXCEPT
|
|
761
|
+
{
|
|
762
|
+
return const_iterator(static_cast<_Const_Link_type>
|
|
763
|
+
(this->_M_impl._M_header._M_left));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
iterator
|
|
767
|
+
end() _GLIBCXX_NOEXCEPT
|
|
768
|
+
{ return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
|
|
769
|
+
|
|
770
|
+
const_iterator
|
|
771
|
+
end() const _GLIBCXX_NOEXCEPT
|
|
772
|
+
{
|
|
773
|
+
return const_iterator(static_cast<_Const_Link_type>
|
|
774
|
+
(&this->_M_impl._M_header));
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
reverse_iterator
|
|
778
|
+
rbegin() _GLIBCXX_NOEXCEPT
|
|
779
|
+
{ return reverse_iterator(end()); }
|
|
780
|
+
|
|
781
|
+
const_reverse_iterator
|
|
782
|
+
rbegin() const _GLIBCXX_NOEXCEPT
|
|
783
|
+
{ return const_reverse_iterator(end()); }
|
|
784
|
+
|
|
785
|
+
reverse_iterator
|
|
786
|
+
rend() _GLIBCXX_NOEXCEPT
|
|
787
|
+
{ return reverse_iterator(begin()); }
|
|
788
|
+
|
|
789
|
+
const_reverse_iterator
|
|
790
|
+
rend() const _GLIBCXX_NOEXCEPT
|
|
791
|
+
{ return const_reverse_iterator(begin()); }
|
|
792
|
+
|
|
793
|
+
bool
|
|
794
|
+
empty() const _GLIBCXX_NOEXCEPT
|
|
795
|
+
{ return _M_impl._M_node_count == 0; }
|
|
796
|
+
|
|
797
|
+
size_type
|
|
798
|
+
size() const _GLIBCXX_NOEXCEPT
|
|
799
|
+
{ return _M_impl._M_node_count; }
|
|
800
|
+
|
|
801
|
+
size_type
|
|
802
|
+
max_size() const _GLIBCXX_NOEXCEPT
|
|
803
|
+
{ return _M_get_Node_allocator().max_size(); }
|
|
804
|
+
|
|
805
|
+
void
|
|
806
|
+
swap(_Rb_tree& __t);
|
|
807
|
+
|
|
808
|
+
// Insert/erase.
|
|
809
|
+
template<typename _Arg>
|
|
810
|
+
pair<iterator, bool>
|
|
811
|
+
_M_insert_unique(_Arg&& __x);
|
|
812
|
+
|
|
813
|
+
template<typename _Arg>
|
|
814
|
+
iterator
|
|
815
|
+
_M_insert_equal(_Arg&& __x);
|
|
816
|
+
|
|
817
|
+
template<typename _Arg>
|
|
818
|
+
iterator
|
|
819
|
+
_M_insert_unique_(const_iterator __position, _Arg&& __x);
|
|
820
|
+
|
|
821
|
+
template<typename _Arg>
|
|
822
|
+
iterator
|
|
823
|
+
_M_insert_equal_(const_iterator __position, _Arg&& __x);
|
|
824
|
+
|
|
825
|
+
template<typename... _Args>
|
|
826
|
+
pair<iterator, bool>
|
|
827
|
+
_M_emplace_unique(_Args&&... __args);
|
|
828
|
+
|
|
829
|
+
template<typename... _Args>
|
|
830
|
+
iterator
|
|
831
|
+
_M_emplace_equal(_Args&&... __args);
|
|
832
|
+
|
|
833
|
+
template<typename... _Args>
|
|
834
|
+
iterator
|
|
835
|
+
_M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
|
|
836
|
+
|
|
837
|
+
template<typename... _Args>
|
|
838
|
+
iterator
|
|
839
|
+
_M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
|
|
840
|
+
|
|
841
|
+
template<typename _InputIterator>
|
|
842
|
+
void
|
|
843
|
+
_M_insert_unique(_InputIterator __first, _InputIterator __last);
|
|
844
|
+
|
|
845
|
+
template<typename _InputIterator>
|
|
846
|
+
void
|
|
847
|
+
_M_insert_equal(_InputIterator __first, _InputIterator __last);
|
|
848
|
+
|
|
849
|
+
private:
|
|
850
|
+
void
|
|
851
|
+
_M_erase_aux(const_iterator __position);
|
|
852
|
+
|
|
853
|
+
void
|
|
854
|
+
_M_erase_aux(const_iterator __first, const_iterator __last);
|
|
855
|
+
|
|
856
|
+
public:
|
|
857
|
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
858
|
+
// DR 130. Associative erase should return an iterator.
|
|
859
|
+
_GLIBCXX_ABI_TAG_CXX11
|
|
860
|
+
iterator
|
|
861
|
+
erase(const_iterator __position)
|
|
862
|
+
{
|
|
863
|
+
const_iterator __result = __position;
|
|
864
|
+
++__result;
|
|
865
|
+
_M_erase_aux(__position);
|
|
866
|
+
return __result._M_const_cast();
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// LWG 2059.
|
|
870
|
+
_GLIBCXX_ABI_TAG_CXX11
|
|
871
|
+
iterator
|
|
872
|
+
erase(iterator __position)
|
|
873
|
+
{
|
|
874
|
+
iterator __result = __position;
|
|
875
|
+
++__result;
|
|
876
|
+
_M_erase_aux(__position);
|
|
877
|
+
return __result;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
size_type
|
|
881
|
+
erase(const key_type& __x);
|
|
882
|
+
|
|
883
|
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
884
|
+
// DR 130. Associative erase should return an iterator.
|
|
885
|
+
_GLIBCXX_ABI_TAG_CXX11
|
|
886
|
+
iterator
|
|
887
|
+
erase(const_iterator __first, const_iterator __last)
|
|
888
|
+
{
|
|
889
|
+
_M_erase_aux(__first, __last);
|
|
890
|
+
return __last._M_const_cast();
|
|
891
|
+
}
|
|
892
|
+
void
|
|
893
|
+
erase(const key_type* __first, const key_type* __last);
|
|
894
|
+
|
|
895
|
+
void
|
|
896
|
+
clear() _GLIBCXX_NOEXCEPT
|
|
897
|
+
{
|
|
898
|
+
_M_erase(_M_begin());
|
|
899
|
+
_M_leftmost() = _M_end();
|
|
900
|
+
_M_root() = 0;
|
|
901
|
+
_M_rightmost() = _M_end();
|
|
902
|
+
_M_impl._M_node_count = 0;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// Set operations.
|
|
906
|
+
iterator
|
|
907
|
+
find(const key_type& __k);
|
|
908
|
+
|
|
909
|
+
const_iterator
|
|
910
|
+
find(const key_type& __k) const;
|
|
911
|
+
|
|
912
|
+
size_type
|
|
913
|
+
count(const key_type& __k) const;
|
|
914
|
+
|
|
915
|
+
iterator
|
|
916
|
+
lower_bound(const key_type& __k)
|
|
917
|
+
{ return _M_lower_bound(_M_begin(), _M_end(), __k); }
|
|
918
|
+
|
|
919
|
+
const_iterator
|
|
920
|
+
lower_bound(const key_type& __k) const
|
|
921
|
+
{ return _M_lower_bound(_M_begin(), _M_end(), __k); }
|
|
922
|
+
|
|
923
|
+
iterator
|
|
924
|
+
upper_bound(const key_type& __k)
|
|
925
|
+
{ return _M_upper_bound(_M_begin(), _M_end(), __k); }
|
|
926
|
+
|
|
927
|
+
const_iterator
|
|
928
|
+
upper_bound(const key_type& __k) const
|
|
929
|
+
{ return _M_upper_bound(_M_begin(), _M_end(), __k); }
|
|
930
|
+
|
|
931
|
+
pair<iterator, iterator>
|
|
932
|
+
equal_range(const key_type& __k);
|
|
933
|
+
|
|
934
|
+
pair<const_iterator, const_iterator>
|
|
935
|
+
equal_range(const key_type& __k) const;
|
|
936
|
+
|
|
937
|
+
// Debugging.
|
|
938
|
+
bool
|
|
939
|
+
__rb_verify() const;
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
943
|
+
typename _Compare, typename _Alloc>
|
|
944
|
+
inline bool
|
|
945
|
+
operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
946
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
947
|
+
{
|
|
948
|
+
return __x.size() == __y.size()
|
|
949
|
+
&& std::equal(__x.begin(), __x.end(), __y.begin());
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
953
|
+
typename _Compare, typename _Alloc>
|
|
954
|
+
inline bool
|
|
955
|
+
operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
956
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
957
|
+
{
|
|
958
|
+
return std::lexicographical_compare(__x.begin(), __x.end(),
|
|
959
|
+
__y.begin(), __y.end());
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
963
|
+
typename _Compare, typename _Alloc>
|
|
964
|
+
inline bool
|
|
965
|
+
operator!=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
966
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
967
|
+
{ return !(__x == __y); }
|
|
968
|
+
|
|
969
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
970
|
+
typename _Compare, typename _Alloc>
|
|
971
|
+
inline bool
|
|
972
|
+
operator>(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
973
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
974
|
+
{ return __y < __x; }
|
|
975
|
+
|
|
976
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
977
|
+
typename _Compare, typename _Alloc>
|
|
978
|
+
inline bool
|
|
979
|
+
operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
980
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
981
|
+
{ return !(__y < __x); }
|
|
982
|
+
|
|
983
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
984
|
+
typename _Compare, typename _Alloc>
|
|
985
|
+
inline bool
|
|
986
|
+
operator>=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
987
|
+
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
988
|
+
{ return !(__x < __y); }
|
|
989
|
+
|
|
990
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
991
|
+
typename _Compare, typename _Alloc>
|
|
992
|
+
inline void
|
|
993
|
+
swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
|
|
994
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
|
|
995
|
+
{ __x.swap(__y); }
|
|
996
|
+
|
|
997
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
998
|
+
typename _Compare, typename _Alloc>
|
|
999
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1000
|
+
_Rb_tree(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&& __x)
|
|
1001
|
+
: _M_impl(__x._M_impl._M_key_compare,
|
|
1002
|
+
std::move(__x._M_get_Node_allocator()))
|
|
1003
|
+
{
|
|
1004
|
+
if (__x._M_root() != 0)
|
|
1005
|
+
{
|
|
1006
|
+
_M_root() = __x._M_root();
|
|
1007
|
+
_M_leftmost() = __x._M_leftmost();
|
|
1008
|
+
_M_rightmost() = __x._M_rightmost();
|
|
1009
|
+
_M_root()->_M_parent = _M_end();
|
|
1010
|
+
|
|
1011
|
+
__x._M_root() = 0;
|
|
1012
|
+
__x._M_leftmost() = __x._M_end();
|
|
1013
|
+
__x._M_rightmost() = __x._M_end();
|
|
1014
|
+
|
|
1015
|
+
this->_M_impl._M_node_count = __x._M_impl._M_node_count;
|
|
1016
|
+
__x._M_impl._M_node_count = 0;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1021
|
+
typename _Compare, typename _Alloc>
|
|
1022
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
|
|
1023
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1024
|
+
operator=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x)
|
|
1025
|
+
{
|
|
1026
|
+
if (this != &__x)
|
|
1027
|
+
{
|
|
1028
|
+
// Note that _Key may be a constant type.
|
|
1029
|
+
clear();
|
|
1030
|
+
_M_impl._M_key_compare = __x._M_impl._M_key_compare;
|
|
1031
|
+
if (__x._M_root() != 0)
|
|
1032
|
+
{
|
|
1033
|
+
_M_root() = _M_copy(__x._M_begin(), _M_end());
|
|
1034
|
+
_M_leftmost() = _S_minimum(_M_root());
|
|
1035
|
+
_M_rightmost() = _S_maximum(_M_root());
|
|
1036
|
+
_M_impl._M_node_count = __x._M_impl._M_node_count;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return *this;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1043
|
+
typename _Compare, typename _Alloc>
|
|
1044
|
+
template<typename _Arg>
|
|
1045
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1046
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1047
|
+
_M_insert_(_Base_ptr __x, _Base_ptr __p, _Arg&& __v)
|
|
1048
|
+
{
|
|
1049
|
+
bool __insert_left = (__x != 0 || __p == _M_end()
|
|
1050
|
+
|| _M_impl._M_key_compare(_KeyOfValue()(__v),
|
|
1051
|
+
_S_key(__p)));
|
|
1052
|
+
|
|
1053
|
+
_Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
|
|
1054
|
+
|
|
1055
|
+
_Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
|
|
1056
|
+
this->_M_impl._M_header);
|
|
1057
|
+
++_M_impl._M_node_count;
|
|
1058
|
+
__z->_TZ_tree = this;
|
|
1059
|
+
return iterator(__z);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1063
|
+
typename _Compare, typename _Alloc>
|
|
1064
|
+
template<typename _Arg>
|
|
1065
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1066
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1067
|
+
_M_insert_lower(_Base_ptr __p, _Arg&& __v)
|
|
1068
|
+
{
|
|
1069
|
+
bool __insert_left = (__p == _M_end()
|
|
1070
|
+
|| !_M_impl._M_key_compare(_S_key(__p),
|
|
1071
|
+
_KeyOfValue()(__v)));
|
|
1072
|
+
|
|
1073
|
+
_Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
|
|
1074
|
+
|
|
1075
|
+
_Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
|
|
1076
|
+
this->_M_impl._M_header);
|
|
1077
|
+
++_M_impl._M_node_count;
|
|
1078
|
+
return iterator(__z);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1082
|
+
typename _Compare, typename _Alloc>
|
|
1083
|
+
template<typename _Arg>
|
|
1084
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1085
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1086
|
+
_M_insert_equal_lower(_Arg&& __v)
|
|
1087
|
+
{
|
|
1088
|
+
_Link_type __x = _M_begin();
|
|
1089
|
+
_Link_type __y = _M_end();
|
|
1090
|
+
while (__x != 0)
|
|
1091
|
+
{
|
|
1092
|
+
__y = __x;
|
|
1093
|
+
__x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
|
|
1094
|
+
_S_left(__x) : _S_right(__x);
|
|
1095
|
+
}
|
|
1096
|
+
return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
template<typename _Key, typename _Val, typename _KoV,
|
|
1100
|
+
typename _Compare, typename _Alloc>
|
|
1101
|
+
typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
|
|
1102
|
+
_Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
|
|
1103
|
+
_M_copy(_Const_Link_type __x, _Link_type __p)
|
|
1104
|
+
{
|
|
1105
|
+
// Structural copy. __x and __p must be non-null.
|
|
1106
|
+
_Link_type __top = _M_clone_node(__x);
|
|
1107
|
+
__top->_M_parent = __p;
|
|
1108
|
+
|
|
1109
|
+
__try
|
|
1110
|
+
{
|
|
1111
|
+
if (__x->_M_right)
|
|
1112
|
+
__top->_M_right = _M_copy(_S_right(__x), __top);
|
|
1113
|
+
__p = __top;
|
|
1114
|
+
__x = _S_left(__x);
|
|
1115
|
+
|
|
1116
|
+
while (__x != 0)
|
|
1117
|
+
{
|
|
1118
|
+
_Link_type __y = _M_clone_node(__x);
|
|
1119
|
+
__p->_M_left = __y;
|
|
1120
|
+
__y->_M_parent = __p;
|
|
1121
|
+
if (__x->_M_right)
|
|
1122
|
+
__y->_M_right = _M_copy(_S_right(__x), __y);
|
|
1123
|
+
__p = __y;
|
|
1124
|
+
__x = _S_left(__x);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
__catch(...)
|
|
1128
|
+
{
|
|
1129
|
+
_M_erase(__top);
|
|
1130
|
+
__throw_exception_again;
|
|
1131
|
+
}
|
|
1132
|
+
return __top;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1136
|
+
typename _Compare, typename _Alloc>
|
|
1137
|
+
void
|
|
1138
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1139
|
+
_M_erase(_Link_type __x)
|
|
1140
|
+
{
|
|
1141
|
+
// Erase without rebalancing.
|
|
1142
|
+
while (__x != 0)
|
|
1143
|
+
{
|
|
1144
|
+
_M_erase(_S_right(__x));
|
|
1145
|
+
_Link_type __y = _S_left(__x);
|
|
1146
|
+
if(__x->_TZ_refCount == 0){
|
|
1147
|
+
_M_destroy_node(__x);
|
|
1148
|
+
}else{
|
|
1149
|
+
__x->prepareDestroy(&_Rb_tree_impl<_Compare>::destroyNode);
|
|
1150
|
+
}
|
|
1151
|
+
__x = __y;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1156
|
+
typename _Compare, typename _Alloc>
|
|
1157
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1158
|
+
_Compare, _Alloc>::iterator
|
|
1159
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1160
|
+
_M_lower_bound(_Link_type __x, _Link_type __y,
|
|
1161
|
+
const _Key& __k)
|
|
1162
|
+
{
|
|
1163
|
+
while (__x != 0)
|
|
1164
|
+
if (!_M_impl._M_key_compare(_S_key(__x), __k))
|
|
1165
|
+
__y = __x, __x = _S_left(__x);
|
|
1166
|
+
else
|
|
1167
|
+
__x = _S_right(__x);
|
|
1168
|
+
return iterator(__y);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1172
|
+
typename _Compare, typename _Alloc>
|
|
1173
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1174
|
+
_Compare, _Alloc>::const_iterator
|
|
1175
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1176
|
+
_M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
|
|
1177
|
+
const _Key& __k) const
|
|
1178
|
+
{
|
|
1179
|
+
while (__x != 0)
|
|
1180
|
+
if (!_M_impl._M_key_compare(_S_key(__x), __k))
|
|
1181
|
+
__y = __x, __x = _S_left(__x);
|
|
1182
|
+
else
|
|
1183
|
+
__x = _S_right(__x);
|
|
1184
|
+
return const_iterator(__y);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1188
|
+
typename _Compare, typename _Alloc>
|
|
1189
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1190
|
+
_Compare, _Alloc>::iterator
|
|
1191
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1192
|
+
_M_upper_bound(_Link_type __x, _Link_type __y,
|
|
1193
|
+
const _Key& __k)
|
|
1194
|
+
{
|
|
1195
|
+
while (__x != 0)
|
|
1196
|
+
if (_M_impl._M_key_compare(__k, _S_key(__x)))
|
|
1197
|
+
__y = __x, __x = _S_left(__x);
|
|
1198
|
+
else
|
|
1199
|
+
__x = _S_right(__x);
|
|
1200
|
+
return iterator(__y);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1204
|
+
typename _Compare, typename _Alloc>
|
|
1205
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1206
|
+
_Compare, _Alloc>::const_iterator
|
|
1207
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1208
|
+
_M_upper_bound(_Const_Link_type __x, _Const_Link_type __y,
|
|
1209
|
+
const _Key& __k) const
|
|
1210
|
+
{
|
|
1211
|
+
while (__x != 0)
|
|
1212
|
+
if (_M_impl._M_key_compare(__k, _S_key(__x)))
|
|
1213
|
+
__y = __x, __x = _S_left(__x);
|
|
1214
|
+
else
|
|
1215
|
+
__x = _S_right(__x);
|
|
1216
|
+
return const_iterator(__y);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1220
|
+
typename _Compare, typename _Alloc>
|
|
1221
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1222
|
+
_Compare, _Alloc>::iterator,
|
|
1223
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1224
|
+
_Compare, _Alloc>::iterator>
|
|
1225
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1226
|
+
equal_range(const _Key& __k)
|
|
1227
|
+
{
|
|
1228
|
+
_Link_type __x = _M_begin();
|
|
1229
|
+
_Link_type __y = _M_end();
|
|
1230
|
+
while (__x != 0)
|
|
1231
|
+
{
|
|
1232
|
+
if (_M_impl._M_key_compare(_S_key(__x), __k))
|
|
1233
|
+
__x = _S_right(__x);
|
|
1234
|
+
else if (_M_impl._M_key_compare(__k, _S_key(__x)))
|
|
1235
|
+
__y = __x, __x = _S_left(__x);
|
|
1236
|
+
else
|
|
1237
|
+
{
|
|
1238
|
+
_Link_type __xu(__x), __yu(__y);
|
|
1239
|
+
__y = __x, __x = _S_left(__x);
|
|
1240
|
+
__xu = _S_right(__xu);
|
|
1241
|
+
return pair<iterator,
|
|
1242
|
+
iterator>(_M_lower_bound(__x, __y, __k),
|
|
1243
|
+
_M_upper_bound(__xu, __yu, __k));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return pair<iterator, iterator>(iterator(__y),
|
|
1247
|
+
iterator(__y));
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1251
|
+
typename _Compare, typename _Alloc>
|
|
1252
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1253
|
+
_Compare, _Alloc>::const_iterator,
|
|
1254
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1255
|
+
_Compare, _Alloc>::const_iterator>
|
|
1256
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1257
|
+
equal_range(const _Key& __k) const
|
|
1258
|
+
{
|
|
1259
|
+
_Const_Link_type __x = _M_begin();
|
|
1260
|
+
_Const_Link_type __y = _M_end();
|
|
1261
|
+
while (__x != 0)
|
|
1262
|
+
{
|
|
1263
|
+
if (_M_impl._M_key_compare(_S_key(__x), __k))
|
|
1264
|
+
__x = _S_right(__x);
|
|
1265
|
+
else if (_M_impl._M_key_compare(__k, _S_key(__x)))
|
|
1266
|
+
__y = __x, __x = _S_left(__x);
|
|
1267
|
+
else
|
|
1268
|
+
{
|
|
1269
|
+
_Const_Link_type __xu(__x), __yu(__y);
|
|
1270
|
+
__y = __x, __x = _S_left(__x);
|
|
1271
|
+
__xu = _S_right(__xu);
|
|
1272
|
+
return pair<const_iterator,
|
|
1273
|
+
const_iterator>(_M_lower_bound(__x, __y, __k),
|
|
1274
|
+
_M_upper_bound(__xu, __yu, __k));
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return pair<const_iterator, const_iterator>(const_iterator(__y),
|
|
1278
|
+
const_iterator(__y));
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1282
|
+
typename _Compare, typename _Alloc>
|
|
1283
|
+
void
|
|
1284
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1285
|
+
swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
|
|
1286
|
+
{
|
|
1287
|
+
if (_M_root() == 0)
|
|
1288
|
+
{
|
|
1289
|
+
if (__t._M_root() != 0)
|
|
1290
|
+
{
|
|
1291
|
+
_M_root() = __t._M_root();
|
|
1292
|
+
_M_leftmost() = __t._M_leftmost();
|
|
1293
|
+
_M_rightmost() = __t._M_rightmost();
|
|
1294
|
+
_M_root()->_M_parent = _M_end();
|
|
1295
|
+
|
|
1296
|
+
__t._M_root() = 0;
|
|
1297
|
+
__t._M_leftmost() = __t._M_end();
|
|
1298
|
+
__t._M_rightmost() = __t._M_end();
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
else if (__t._M_root() == 0)
|
|
1302
|
+
{
|
|
1303
|
+
__t._M_root() = _M_root();
|
|
1304
|
+
__t._M_leftmost() = _M_leftmost();
|
|
1305
|
+
__t._M_rightmost() = _M_rightmost();
|
|
1306
|
+
__t._M_root()->_M_parent = __t._M_end();
|
|
1307
|
+
|
|
1308
|
+
_M_root() = 0;
|
|
1309
|
+
_M_leftmost() = _M_end();
|
|
1310
|
+
_M_rightmost() = _M_end();
|
|
1311
|
+
}
|
|
1312
|
+
else
|
|
1313
|
+
{
|
|
1314
|
+
std::swap(_M_root(),__t._M_root());
|
|
1315
|
+
std::swap(_M_leftmost(),__t._M_leftmost());
|
|
1316
|
+
std::swap(_M_rightmost(),__t._M_rightmost());
|
|
1317
|
+
|
|
1318
|
+
_M_root()->_M_parent = _M_end();
|
|
1319
|
+
__t._M_root()->_M_parent = __t._M_end();
|
|
1320
|
+
}
|
|
1321
|
+
// No need to swap header's color as it does not change.
|
|
1322
|
+
std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
|
|
1323
|
+
std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
|
|
1324
|
+
|
|
1325
|
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
1326
|
+
// 431. Swapping containers with unequal allocators.
|
|
1327
|
+
std::__alloc_swap<_Node_allocator>::
|
|
1328
|
+
_S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator());
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1332
|
+
typename _Compare, typename _Alloc>
|
|
1333
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1334
|
+
_Compare, _Alloc>::_Base_ptr,
|
|
1335
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1336
|
+
_Compare, _Alloc>::_Base_ptr>
|
|
1337
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1338
|
+
_M_get_insert_unique_pos(const key_type& __k)
|
|
1339
|
+
{
|
|
1340
|
+
typedef pair<_Base_ptr, _Base_ptr> _Res;
|
|
1341
|
+
_Link_type __x = _M_begin();
|
|
1342
|
+
_Link_type __y = _M_end();
|
|
1343
|
+
bool __comp = true;
|
|
1344
|
+
while (__x != 0)
|
|
1345
|
+
{
|
|
1346
|
+
__y = __x;
|
|
1347
|
+
__comp = _M_impl._M_key_compare(__k, _S_key(__x));
|
|
1348
|
+
__x = __comp ? _S_left(__x) : _S_right(__x);
|
|
1349
|
+
}
|
|
1350
|
+
iterator __j = iterator(__y);
|
|
1351
|
+
if (__comp)
|
|
1352
|
+
{
|
|
1353
|
+
if (__j == begin())
|
|
1354
|
+
return _Res(__x, __y);
|
|
1355
|
+
else
|
|
1356
|
+
--__j;
|
|
1357
|
+
}
|
|
1358
|
+
if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
|
|
1359
|
+
return _Res(__x, __y);
|
|
1360
|
+
return _Res(__j._M_node, 0);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1364
|
+
typename _Compare, typename _Alloc>
|
|
1365
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1366
|
+
_Compare, _Alloc>::_Base_ptr,
|
|
1367
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1368
|
+
_Compare, _Alloc>::_Base_ptr>
|
|
1369
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1370
|
+
_M_get_insert_equal_pos(const key_type& __k)
|
|
1371
|
+
{
|
|
1372
|
+
typedef pair<_Base_ptr, _Base_ptr> _Res;
|
|
1373
|
+
_Link_type __x = _M_begin();
|
|
1374
|
+
_Link_type __y = _M_end();
|
|
1375
|
+
while (__x != 0)
|
|
1376
|
+
{
|
|
1377
|
+
__y = __x;
|
|
1378
|
+
__x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
|
|
1379
|
+
_S_left(__x) : _S_right(__x);
|
|
1380
|
+
}
|
|
1381
|
+
return _Res(__x, __y);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1385
|
+
typename _Compare, typename _Alloc>
|
|
1386
|
+
template<typename _Arg>
|
|
1387
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1388
|
+
_Compare, _Alloc>::iterator, bool>
|
|
1389
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1390
|
+
_M_insert_unique(_Arg&& __v)
|
|
1391
|
+
{
|
|
1392
|
+
typedef pair<iterator, bool> _Res;
|
|
1393
|
+
pair<_Base_ptr, _Base_ptr> __res
|
|
1394
|
+
= _M_get_insert_unique_pos(_KeyOfValue()(__v));
|
|
1395
|
+
|
|
1396
|
+
if (__res.second)
|
|
1397
|
+
return _Res(_M_insert_(__res.first, __res.second,
|
|
1398
|
+
_GLIBCXX_FORWARD(_Arg, __v)),
|
|
1399
|
+
true);
|
|
1400
|
+
|
|
1401
|
+
return _Res(iterator(static_cast<_Link_type>(__res.first)), false);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1405
|
+
typename _Compare, typename _Alloc>
|
|
1406
|
+
template<typename _Arg>
|
|
1407
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1408
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1409
|
+
_M_insert_equal(_Arg&& __v)
|
|
1410
|
+
{
|
|
1411
|
+
pair<_Base_ptr, _Base_ptr> __res
|
|
1412
|
+
= _M_get_insert_equal_pos(_KeyOfValue()(__v));
|
|
1413
|
+
return _M_insert_(__res.first, __res.second, _GLIBCXX_FORWARD(_Arg, __v));
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1417
|
+
typename _Compare, typename _Alloc>
|
|
1418
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1419
|
+
_Compare, _Alloc>::_Base_ptr,
|
|
1420
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1421
|
+
_Compare, _Alloc>::_Base_ptr>
|
|
1422
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1423
|
+
_M_get_insert_hint_unique_pos(const_iterator __position,
|
|
1424
|
+
const key_type& __k)
|
|
1425
|
+
{
|
|
1426
|
+
iterator __pos = __position._M_const_cast();
|
|
1427
|
+
typedef pair<_Base_ptr, _Base_ptr> _Res;
|
|
1428
|
+
|
|
1429
|
+
// end()
|
|
1430
|
+
if (__pos._M_node == _M_end())
|
|
1431
|
+
{
|
|
1432
|
+
if (size() > 0
|
|
1433
|
+
&& _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
|
|
1434
|
+
return _Res(0, _M_rightmost());
|
|
1435
|
+
else
|
|
1436
|
+
return _M_get_insert_unique_pos(__k);
|
|
1437
|
+
}
|
|
1438
|
+
else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
|
|
1439
|
+
{
|
|
1440
|
+
// First, try before...
|
|
1441
|
+
iterator __before = __pos;
|
|
1442
|
+
if (__pos._M_node == _M_leftmost()) // begin()
|
|
1443
|
+
return _Res(_M_leftmost(), _M_leftmost());
|
|
1444
|
+
else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
|
|
1445
|
+
{
|
|
1446
|
+
if (_S_right(__before._M_node) == 0)
|
|
1447
|
+
return _Res(0, __before._M_node);
|
|
1448
|
+
else
|
|
1449
|
+
return _Res(__pos._M_node, __pos._M_node);
|
|
1450
|
+
}
|
|
1451
|
+
else
|
|
1452
|
+
return _M_get_insert_unique_pos(__k);
|
|
1453
|
+
}
|
|
1454
|
+
else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
|
|
1455
|
+
{
|
|
1456
|
+
// ... then try after.
|
|
1457
|
+
iterator __after = __pos;
|
|
1458
|
+
if (__pos._M_node == _M_rightmost())
|
|
1459
|
+
return _Res(0, _M_rightmost());
|
|
1460
|
+
else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
|
|
1461
|
+
{
|
|
1462
|
+
if (_S_right(__pos._M_node) == 0)
|
|
1463
|
+
return _Res(0, __pos._M_node);
|
|
1464
|
+
else
|
|
1465
|
+
return _Res(__after._M_node, __after._M_node);
|
|
1466
|
+
}
|
|
1467
|
+
else
|
|
1468
|
+
return _M_get_insert_unique_pos(__k);
|
|
1469
|
+
}
|
|
1470
|
+
else
|
|
1471
|
+
// Equivalent keys.
|
|
1472
|
+
return _Res(__pos._M_node, 0);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1476
|
+
typename _Compare, typename _Alloc>
|
|
1477
|
+
template<typename _Arg>
|
|
1478
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1479
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1480
|
+
_M_insert_unique_(const_iterator __position, _Arg&& __v)
|
|
1481
|
+
{
|
|
1482
|
+
pair<_Base_ptr, _Base_ptr> __res
|
|
1483
|
+
= _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
|
|
1484
|
+
|
|
1485
|
+
if (__res.second)
|
|
1486
|
+
return _M_insert_(__res.first, __res.second,
|
|
1487
|
+
_GLIBCXX_FORWARD(_Arg, __v));
|
|
1488
|
+
return iterator(static_cast<_Link_type>(__res.first));
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1492
|
+
typename _Compare, typename _Alloc>
|
|
1493
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1494
|
+
_Compare, _Alloc>::_Base_ptr,
|
|
1495
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1496
|
+
_Compare, _Alloc>::_Base_ptr>
|
|
1497
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1498
|
+
_M_get_insert_hint_equal_pos(const_iterator __position, const key_type& __k)
|
|
1499
|
+
{
|
|
1500
|
+
iterator __pos = __position._M_const_cast();
|
|
1501
|
+
typedef pair<_Base_ptr, _Base_ptr> _Res;
|
|
1502
|
+
|
|
1503
|
+
// end()
|
|
1504
|
+
if (__pos._M_node == _M_end())
|
|
1505
|
+
{
|
|
1506
|
+
if (size() > 0
|
|
1507
|
+
&& !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
|
|
1508
|
+
return _Res(0, _M_rightmost());
|
|
1509
|
+
else
|
|
1510
|
+
return _M_get_insert_equal_pos(__k);
|
|
1511
|
+
}
|
|
1512
|
+
else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
|
|
1513
|
+
{
|
|
1514
|
+
// First, try before...
|
|
1515
|
+
iterator __before = __pos;
|
|
1516
|
+
if (__pos._M_node == _M_leftmost()) // begin()
|
|
1517
|
+
return _Res(_M_leftmost(), _M_leftmost());
|
|
1518
|
+
else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
|
|
1519
|
+
{
|
|
1520
|
+
if (_S_right(__before._M_node) == 0)
|
|
1521
|
+
return _Res(0, __before._M_node);
|
|
1522
|
+
else
|
|
1523
|
+
return _Res(__pos._M_node, __pos._M_node);
|
|
1524
|
+
}
|
|
1525
|
+
else
|
|
1526
|
+
return _M_get_insert_equal_pos(__k);
|
|
1527
|
+
}
|
|
1528
|
+
else
|
|
1529
|
+
{
|
|
1530
|
+
// ... then try after.
|
|
1531
|
+
iterator __after = __pos;
|
|
1532
|
+
if (__pos._M_node == _M_rightmost())
|
|
1533
|
+
return _Res(0, _M_rightmost());
|
|
1534
|
+
else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
|
|
1535
|
+
{
|
|
1536
|
+
if (_S_right(__pos._M_node) == 0)
|
|
1537
|
+
return _Res(0, __pos._M_node);
|
|
1538
|
+
else
|
|
1539
|
+
return _Res(__after._M_node, __after._M_node);
|
|
1540
|
+
}
|
|
1541
|
+
else
|
|
1542
|
+
return _Res(0, 0);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1547
|
+
typename _Compare, typename _Alloc>
|
|
1548
|
+
template<typename _Arg>
|
|
1549
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1550
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1551
|
+
_M_insert_equal_(const_iterator __position, _Arg&& __v)
|
|
1552
|
+
{
|
|
1553
|
+
pair<_Base_ptr, _Base_ptr> __res
|
|
1554
|
+
= _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
|
|
1555
|
+
|
|
1556
|
+
if (__res.second)
|
|
1557
|
+
return _M_insert_(__res.first, __res.second,
|
|
1558
|
+
_GLIBCXX_FORWARD(_Arg, __v));
|
|
1559
|
+
|
|
1560
|
+
return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1564
|
+
typename _Compare, typename _Alloc>
|
|
1565
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1566
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1567
|
+
_M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
|
|
1568
|
+
{
|
|
1569
|
+
bool __insert_left = (__x != 0 || __p == _M_end()
|
|
1570
|
+
|| _M_impl._M_key_compare(_S_key(__z),
|
|
1571
|
+
_S_key(__p)));
|
|
1572
|
+
|
|
1573
|
+
_Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
|
|
1574
|
+
this->_M_impl._M_header);
|
|
1575
|
+
++_M_impl._M_node_count;
|
|
1576
|
+
return iterator(__z);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1580
|
+
typename _Compare, typename _Alloc>
|
|
1581
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1582
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1583
|
+
_M_insert_lower_node(_Base_ptr __p, _Link_type __z)
|
|
1584
|
+
{
|
|
1585
|
+
bool __insert_left = (__p == _M_end()
|
|
1586
|
+
|| !_M_impl._M_key_compare(_S_key(__p),
|
|
1587
|
+
_S_key(__z)));
|
|
1588
|
+
|
|
1589
|
+
_Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
|
|
1590
|
+
this->_M_impl._M_header);
|
|
1591
|
+
++_M_impl._M_node_count;
|
|
1592
|
+
return iterator(__z);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1596
|
+
typename _Compare, typename _Alloc>
|
|
1597
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1598
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1599
|
+
_M_insert_equal_lower_node(_Link_type __z)
|
|
1600
|
+
{
|
|
1601
|
+
_Link_type __x = _M_begin();
|
|
1602
|
+
_Link_type __y = _M_end();
|
|
1603
|
+
while (__x != 0)
|
|
1604
|
+
{
|
|
1605
|
+
__y = __x;
|
|
1606
|
+
__x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
|
|
1607
|
+
_S_left(__x) : _S_right(__x);
|
|
1608
|
+
}
|
|
1609
|
+
return _M_insert_lower_node(__y, __z);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1613
|
+
typename _Compare, typename _Alloc>
|
|
1614
|
+
template<typename... _Args>
|
|
1615
|
+
pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1616
|
+
_Compare, _Alloc>::iterator, bool>
|
|
1617
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1618
|
+
_M_emplace_unique(_Args&&... __args)
|
|
1619
|
+
{
|
|
1620
|
+
_Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
|
|
1621
|
+
|
|
1622
|
+
__try
|
|
1623
|
+
{
|
|
1624
|
+
typedef pair<iterator, bool> _Res;
|
|
1625
|
+
auto __res = _M_get_insert_unique_pos(_S_key(__z));
|
|
1626
|
+
if (__res.second)
|
|
1627
|
+
return _Res(_M_insert_node(__res.first, __res.second, __z), true);
|
|
1628
|
+
|
|
1629
|
+
_M_destroy_node(__z);
|
|
1630
|
+
return _Res(iterator(static_cast<_Link_type>(__res.first)), false);
|
|
1631
|
+
}
|
|
1632
|
+
__catch(...)
|
|
1633
|
+
{
|
|
1634
|
+
_M_destroy_node(__z);
|
|
1635
|
+
__throw_exception_again;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1640
|
+
typename _Compare, typename _Alloc>
|
|
1641
|
+
template<typename... _Args>
|
|
1642
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1643
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1644
|
+
_M_emplace_equal(_Args&&... __args)
|
|
1645
|
+
{
|
|
1646
|
+
_Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
|
|
1647
|
+
|
|
1648
|
+
__try
|
|
1649
|
+
{
|
|
1650
|
+
auto __res = _M_get_insert_equal_pos(_S_key(__z));
|
|
1651
|
+
return _M_insert_node(__res.first, __res.second, __z);
|
|
1652
|
+
}
|
|
1653
|
+
__catch(...)
|
|
1654
|
+
{
|
|
1655
|
+
_M_destroy_node(__z);
|
|
1656
|
+
__throw_exception_again;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1661
|
+
typename _Compare, typename _Alloc>
|
|
1662
|
+
template<typename... _Args>
|
|
1663
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1664
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1665
|
+
_M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
|
|
1666
|
+
{
|
|
1667
|
+
_Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
|
|
1668
|
+
|
|
1669
|
+
__try
|
|
1670
|
+
{
|
|
1671
|
+
auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
|
|
1672
|
+
|
|
1673
|
+
if (__res.second)
|
|
1674
|
+
return _M_insert_node(__res.first, __res.second, __z);
|
|
1675
|
+
|
|
1676
|
+
_M_destroy_node(__z);
|
|
1677
|
+
return iterator(static_cast<_Link_type>(__res.first));
|
|
1678
|
+
}
|
|
1679
|
+
__catch(...)
|
|
1680
|
+
{
|
|
1681
|
+
_M_destroy_node(__z);
|
|
1682
|
+
__throw_exception_again;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1687
|
+
typename _Compare, typename _Alloc>
|
|
1688
|
+
template<typename... _Args>
|
|
1689
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
|
|
1690
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1691
|
+
_M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
|
|
1692
|
+
{
|
|
1693
|
+
_Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
|
|
1694
|
+
|
|
1695
|
+
__try
|
|
1696
|
+
{
|
|
1697
|
+
auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
|
|
1698
|
+
|
|
1699
|
+
if (__res.second)
|
|
1700
|
+
return _M_insert_node(__res.first, __res.second, __z);
|
|
1701
|
+
|
|
1702
|
+
return _M_insert_equal_lower_node(__z);
|
|
1703
|
+
}
|
|
1704
|
+
__catch(...)
|
|
1705
|
+
{
|
|
1706
|
+
_M_destroy_node(__z);
|
|
1707
|
+
__throw_exception_again;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
template<typename _Key, typename _Val, typename _KoV,
|
|
1712
|
+
typename _Cmp, typename _Alloc>
|
|
1713
|
+
template<class _II>
|
|
1714
|
+
void
|
|
1715
|
+
_Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
|
|
1716
|
+
_M_insert_unique(_II __first, _II __last)
|
|
1717
|
+
{
|
|
1718
|
+
for (; __first != __last; ++__first)
|
|
1719
|
+
_M_insert_unique_(end(), *__first);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
template<typename _Key, typename _Val, typename _KoV,
|
|
1723
|
+
typename _Cmp, typename _Alloc>
|
|
1724
|
+
template<class _II>
|
|
1725
|
+
void
|
|
1726
|
+
_Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
|
|
1727
|
+
_M_insert_equal(_II __first, _II __last)
|
|
1728
|
+
{
|
|
1729
|
+
for (; __first != __last; ++__first)
|
|
1730
|
+
_M_insert_equal_(end(), *__first);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1734
|
+
typename _Compare, typename _Alloc>
|
|
1735
|
+
void
|
|
1736
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1737
|
+
_M_erase_aux(const_iterator __position)
|
|
1738
|
+
{
|
|
1739
|
+
_Link_type __y =
|
|
1740
|
+
static_cast<_Link_type>(_Rb_tree_rebalance_for_erase
|
|
1741
|
+
(const_cast<_Base_ptr>(__position._M_node),
|
|
1742
|
+
this->_M_impl._M_header));
|
|
1743
|
+
_M_destroy_node(__y);
|
|
1744
|
+
--_M_impl._M_node_count;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1748
|
+
typename _Compare, typename _Alloc>
|
|
1749
|
+
void
|
|
1750
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1751
|
+
_M_erase_aux(const_iterator __first, const_iterator __last)
|
|
1752
|
+
{
|
|
1753
|
+
if (__first == begin() && __last == end())
|
|
1754
|
+
clear();
|
|
1755
|
+
else
|
|
1756
|
+
while (__first != __last)
|
|
1757
|
+
erase(__first++);
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1761
|
+
typename _Compare, typename _Alloc>
|
|
1762
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
|
|
1763
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1764
|
+
erase(const _Key& __x)
|
|
1765
|
+
{
|
|
1766
|
+
pair<iterator, iterator> __p = equal_range(__x);
|
|
1767
|
+
const size_type __old_size = size();
|
|
1768
|
+
erase(__p.first, __p.second);
|
|
1769
|
+
return __old_size - size();
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1773
|
+
typename _Compare, typename _Alloc>
|
|
1774
|
+
void
|
|
1775
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1776
|
+
erase(const _Key* __first, const _Key* __last)
|
|
1777
|
+
{
|
|
1778
|
+
while (__first != __last)
|
|
1779
|
+
erase(*__first++);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1783
|
+
typename _Compare, typename _Alloc>
|
|
1784
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1785
|
+
_Compare, _Alloc>::iterator
|
|
1786
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1787
|
+
find(const _Key& __k)
|
|
1788
|
+
{
|
|
1789
|
+
iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
|
|
1790
|
+
return (__j == end()
|
|
1791
|
+
|| _M_impl._M_key_compare(__k,
|
|
1792
|
+
_S_key(__j._M_node))) ? end() : __j;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1796
|
+
typename _Compare, typename _Alloc>
|
|
1797
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue,
|
|
1798
|
+
_Compare, _Alloc>::const_iterator
|
|
1799
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1800
|
+
find(const _Key& __k) const
|
|
1801
|
+
{
|
|
1802
|
+
const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
|
|
1803
|
+
return (__j == end()
|
|
1804
|
+
|| _M_impl._M_key_compare(__k,
|
|
1805
|
+
_S_key(__j._M_node))) ? end() : __j;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1809
|
+
typename _Compare, typename _Alloc>
|
|
1810
|
+
typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
|
|
1811
|
+
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
|
|
1812
|
+
count(const _Key& __k) const
|
|
1813
|
+
{
|
|
1814
|
+
pair<const_iterator, const_iterator> __p = equal_range(__k);
|
|
1815
|
+
const size_type __n = std::distance(__p.first, __p.second);
|
|
1816
|
+
return __n;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
_GLIBCXX_PURE unsigned int
|
|
1820
|
+
_Rb_tree_black_count(const _Rb_tree_node_base* __node,
|
|
1821
|
+
const _Rb_tree_node_base* __root) throw ();
|
|
1822
|
+
|
|
1823
|
+
template<typename _Key, typename _Val, typename _KeyOfValue,
|
|
1824
|
+
typename _Compare, typename _Alloc>
|
|
1825
|
+
bool
|
|
1826
|
+
_Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify() const
|
|
1827
|
+
{
|
|
1828
|
+
if (_M_impl._M_node_count == 0 || begin() == end())
|
|
1829
|
+
return _M_impl._M_node_count == 0 && begin() == end()
|
|
1830
|
+
&& this->_M_impl._M_header._M_left == _M_end()
|
|
1831
|
+
&& this->_M_impl._M_header._M_right == _M_end();
|
|
1832
|
+
|
|
1833
|
+
unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
|
|
1834
|
+
for (const_iterator __it = begin(); __it != end(); ++__it)
|
|
1835
|
+
{
|
|
1836
|
+
_Const_Link_type __x = static_cast<_Const_Link_type>(__it._M_node);
|
|
1837
|
+
_Const_Link_type __L = _S_left(__x);
|
|
1838
|
+
_Const_Link_type __R = _S_right(__x);
|
|
1839
|
+
|
|
1840
|
+
if (__x->_M_color == _S_red)
|
|
1841
|
+
if ((__L && __L->_M_color == _S_red)
|
|
1842
|
+
|| (__R && __R->_M_color == _S_red))
|
|
1843
|
+
return false;
|
|
1844
|
+
|
|
1845
|
+
if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
|
|
1846
|
+
return false;
|
|
1847
|
+
if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
|
|
1848
|
+
return false;
|
|
1849
|
+
|
|
1850
|
+
if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
|
|
1855
|
+
return false;
|
|
1856
|
+
if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
|
|
1857
|
+
return false;
|
|
1858
|
+
return true;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
}
|
|
1862
|
+
_GLIBCXX_END_NAMESPACE_VERSION
|
|
1863
|
+
//} // namespace
|
|
1864
|
+
|
|
1865
|
+
#endif
|