tools/qmap.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qmap.h" -
43 -
44#include <stdlib.h> -
45 -
46#ifdef QT_QMAP_DEBUG -
47# include <qstring.h> -
48# include <qvector.h> -
49#endif -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53const QMapDataBase QMapDataBase::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, { 0, 0, 0 }, 0 }; -
54 -
55const QMapNodeBase *QMapNodeBase::nextNode() const -
56{ -
57 const QMapNodeBase *n = this;
executed (the execution status of this line is deduced): const QMapNodeBase *n = this;
-
58 if (n->right) {
evaluated: n->right
TRUEFALSE
yes
Evaluation Count:323112
yes
Evaluation Count:1047878
323112-1047878
59 n = n->right;
executed (the execution status of this line is deduced): n = n->right;
-
60 while (n->left)
evaluated: n->left
TRUEFALSE
yes
Evaluation Count:123762
yes
Evaluation Count:323112
123762-323112
61 n = n->left;
executed: n = n->left;
Execution Count:123762
123762
62 } else {
executed: }
Execution Count:323112
323112
63 const QMapNodeBase *y = n->parent();
executed (the execution status of this line is deduced): const QMapNodeBase *y = n->parent();
-
64 while (y && n == y->right) {
partially evaluated: y
TRUEFALSE
yes
Evaluation Count:1437464
no
Evaluation Count:0
evaluated: n == y->right
TRUEFALSE
yes
Evaluation Count:389693
yes
Evaluation Count:1047712
0-1437464
65 n = y;
executed (the execution status of this line is deduced): n = y;
-
66 y = n->parent();
executed (the execution status of this line is deduced): y = n->parent();
-
67 }
executed: }
Execution Count:389693
389693
68 n = y;
executed (the execution status of this line is deduced): n = y;
-
69 }
executed: }
Execution Count:1047604
1047604
70 return n;
executed: return n;
Execution Count:1370793
1370793
71} -
72 -
73const QMapNodeBase *QMapNodeBase::previousNode() const -
74{ -
75 const QMapNodeBase *n = this;
executed (the execution status of this line is deduced): const QMapNodeBase *n = this;
-
76 if (n->left) {
evaluated: n->left
TRUEFALSE
yes
Evaluation Count:282332
yes
Evaluation Count:22735
22735-282332
77 n = n->left;
executed (the execution status of this line is deduced): n = n->left;
-
78 while (n->right)
evaluated: n->right
TRUEFALSE
yes
Evaluation Count:42957
yes
Evaluation Count:282240
42957-282240
79 n = n->right;
executed: n = n->right;
Execution Count:42957
42957
80 } else {
executed: }
Execution Count:281930
281930
81 const QMapNodeBase *y = n->parent();
executed (the execution status of this line is deduced): const QMapNodeBase *y = n->parent();
-
82 while (y && n == y->left) {
evaluated: y
TRUEFALSE
yes
Evaluation Count:41233
yes
Evaluation Count:24
evaluated: n == y->left
TRUEFALSE
yes
Evaluation Count:18522
yes
Evaluation Count:22711
24-41233
83 n = y;
executed (the execution status of this line is deduced): n = y;
-
84 y = n->parent();
executed (the execution status of this line is deduced): y = n->parent();
-
85 }
executed: }
Execution Count:18522
18522
86 n = y;
executed (the execution status of this line is deduced): n = y;
-
87 }
executed: }
Execution Count:22735
22735
88 return n;
executed: return n;
Execution Count:304627
304627
89} -
90 -
91 -
92void QMapDataBase::rotateLeft(QMapNodeBase *x) -
93{ -
94 QMapNodeBase *&root = header.left;
executed (the execution status of this line is deduced): QMapNodeBase *&root = header.left;
-
95 QMapNodeBase *y = x->right;
executed (the execution status of this line is deduced): QMapNodeBase *y = x->right;
-
96 x->right = y->left;
executed (the execution status of this line is deduced): x->right = y->left;
-
97 if (y->left != 0)
evaluated: y->left != 0
TRUEFALSE
yes
Evaluation Count:91961
yes
Evaluation Count:286110
91961-286110
98 y->left->setParent(x);
executed: y->left->setParent(x);
Execution Count:91961
91961
99 y->setParent(x->parent());
executed (the execution status of this line is deduced): y->setParent(x->parent());
-
100 if (x == root)
evaluated: x == root
TRUEFALSE
yes
Evaluation Count:178422
yes
Evaluation Count:199649
178422-199649
101 root = y;
executed: root = y;
Execution Count:178422
178422
102 else if (x == x->parent()->left)
evaluated: x == x->parent()->left
TRUEFALSE
yes
Evaluation Count:43337
yes
Evaluation Count:156312
43337-156312
103 x->parent()->left = y;
executed: x->parent()->left = y;
Execution Count:43337
43337
104 else -
105 x->parent()->right = y;
executed: x->parent()->right = y;
Execution Count:156312
156312
106 y->left = x;
executed (the execution status of this line is deduced): y->left = x;
-
107 x->setParent(y);
executed (the execution status of this line is deduced): x->setParent(y);
-
108}
executed: }
Execution Count:378071
378071
109 -
110 -
111void QMapDataBase::rotateRight(QMapNodeBase *x) -
112{ -
113 QMapNodeBase *&root = header.left;
executed (the execution status of this line is deduced): QMapNodeBase *&root = header.left;
-
114 QMapNodeBase *y = x->left;
executed (the execution status of this line is deduced): QMapNodeBase *y = x->left;
-
115 x->left = y->right;
executed (the execution status of this line is deduced): x->left = y->right;
-
116 if (y->right != 0)
evaluated: y->right != 0
TRUEFALSE
yes
Evaluation Count:69313
yes
Evaluation Count:80197
69313-80197
117 y->right->setParent(x);
executed: y->right->setParent(x);
Execution Count:69313
69313
118 y->setParent(x->parent());
executed (the execution status of this line is deduced): y->setParent(x->parent());
-
119 if (x == root)
evaluated: x == root
TRUEFALSE
yes
Evaluation Count:2996
yes
Evaluation Count:146514
2996-146514
120 root = y;
executed: root = y;
Execution Count:2996
2996
121 else if (x == x->parent()->right)
evaluated: x == x->parent()->right
TRUEFALSE
yes
Evaluation Count:28369
yes
Evaluation Count:118145
28369-118145
122 x->parent()->right = y;
executed: x->parent()->right = y;
Execution Count:28369
28369
123 else -
124 x->parent()->left = y;
executed: x->parent()->left = y;
Execution Count:118145
118145
125 y->right = x;
executed (the execution status of this line is deduced): y->right = x;
-
126 x->setParent(y);
executed (the execution status of this line is deduced): x->setParent(y);
-
127}
executed: }
Execution Count:149510
149510
128 -
129 -
130void QMapDataBase::rebalance(QMapNodeBase *x) -
131{ -
132 QMapNodeBase *&root = header.left;
executed (the execution status of this line is deduced): QMapNodeBase *&root = header.left;
-
133 x->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x->setColor(QMapNodeBase::Red);
-
134 while (x != root && x->parent()->color() == QMapNodeBase::Red) {
evaluated: x != root
TRUEFALSE
yes
Evaluation Count:1537306
yes
Evaluation Count:672316
evaluated: x->parent()->color() == QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:808628
yes
Evaluation Count:728679
672316-1537306
135 if (x->parent() == x->parent()->parent()->left) {
evaluated: x->parent() == x->parent()->parent()->left
TRUEFALSE
yes
Evaluation Count:268665
yes
Evaluation Count:539963
268665-539963
136 QMapNodeBase *y = x->parent()->parent()->right;
executed (the execution status of this line is deduced): QMapNodeBase *y = x->parent()->parent()->right;
-
137 if (y && y->color() == QMapNodeBase::Red) {
evaluated: y
TRUEFALSE
yes
Evaluation Count:197888
yes
Evaluation Count:70777
evaluated: y->color() == QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:130424
yes
Evaluation Count:67464
67464-197888
138 x->parent()->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x->parent()->setColor(QMapNodeBase::Black);
-
139 y->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): y->setColor(QMapNodeBase::Black);
-
140 x->parent()->parent()->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x->parent()->parent()->setColor(QMapNodeBase::Red);
-
141 x = x->parent()->parent();
executed (the execution status of this line is deduced): x = x->parent()->parent();
-
142 } else {
executed: }
Execution Count:130424
130424
143 if (x == x->parent()->right) {
evaluated: x == x->parent()->right
TRUEFALSE
yes
Evaluation Count:16119
yes
Evaluation Count:122122
16119-122122
144 x = x->parent();
executed (the execution status of this line is deduced): x = x->parent();
-
145 rotateLeft(x);
executed (the execution status of this line is deduced): rotateLeft(x);
-
146 }
executed: }
Execution Count:16119
16119
147 x->parent()->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x->parent()->setColor(QMapNodeBase::Black);
-
148 x->parent()->parent()->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x->parent()->parent()->setColor(QMapNodeBase::Red);
-
149 rotateRight (x->parent()->parent());
executed (the execution status of this line is deduced): rotateRight (x->parent()->parent());
-
150 }
executed: }
Execution Count:138241
138241
151 } else { -
152 QMapNodeBase *y = x->parent()->parent()->left;
executed (the execution status of this line is deduced): QMapNodeBase *y = x->parent()->parent()->left;
-
153 if (y && y->color() == QMapNodeBase::Red) {
evaluated: y
TRUEFALSE
yes
Evaluation Count:266304
yes
Evaluation Count:273659
evaluated: y->color() == QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:192172
yes
Evaluation Count:74132
74132-273659
154 x->parent()->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x->parent()->setColor(QMapNodeBase::Black);
-
155 y->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): y->setColor(QMapNodeBase::Black);
-
156 x->parent()->parent()->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x->parent()->parent()->setColor(QMapNodeBase::Red);
-
157 x = x->parent()->parent();
executed (the execution status of this line is deduced): x = x->parent()->parent();
-
158 } else {
executed: }
Execution Count:192172
192172
159 if (x == x->parent()->left) {
evaluated: x == x->parent()->left
TRUEFALSE
yes
Evaluation Count:9432
yes
Evaluation Count:338359
9432-338359
160 x = x->parent();
executed (the execution status of this line is deduced): x = x->parent();
-
161 rotateRight(x);
executed (the execution status of this line is deduced): rotateRight(x);
-
162 }
executed: }
Execution Count:9432
9432
163 x->parent()->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x->parent()->setColor(QMapNodeBase::Black);
-
164 x->parent()->parent()->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x->parent()->parent()->setColor(QMapNodeBase::Red);
-
165 rotateLeft(x->parent()->parent());
executed (the execution status of this line is deduced): rotateLeft(x->parent()->parent());
-
166 }
executed: }
Execution Count:347791
347791
167 } -
168 } -
169 root->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): root->setColor(QMapNodeBase::Black);
-
170}
executed: }
Execution Count:1400731
1400731
171 -
172void QMapDataBase::freeNodeAndRebalance(QMapNodeBase *z) -
173{ -
174 QMapNodeBase *&root = header.left;
executed (the execution status of this line is deduced): QMapNodeBase *&root = header.left;
-
175 QMapNodeBase *y = z;
executed (the execution status of this line is deduced): QMapNodeBase *y = z;
-
176 QMapNodeBase *x;
executed (the execution status of this line is deduced): QMapNodeBase *x;
-
177 QMapNodeBase *x_parent;
executed (the execution status of this line is deduced): QMapNodeBase *x_parent;
-
178 if (y->left == 0) {
evaluated: y->left == 0
TRUEFALSE
yes
Evaluation Count:66761
yes
Evaluation Count:1773
1773-66761
179 x = y->right;
executed (the execution status of this line is deduced): x = y->right;
-
180 if (y == mostLeftNode) {
evaluated: y == mostLeftNode
TRUEFALSE
yes
Evaluation Count:64961
yes
Evaluation Count:1800
1800-64961
181 if (x)
evaluated: x
TRUEFALSE
yes
Evaluation Count:13600
yes
Evaluation Count:51361
13600-51361
182 mostLeftNode = x; // It cannot have (left) children due the red black invariant.
executed: mostLeftNode = x;
Execution Count:13600
13600
183 else -
184 mostLeftNode = y->parent();
executed: mostLeftNode = y->parent();
Execution Count:51361
51361
185 } -
186 } else {
executed: }
Execution Count:66761
66761
187 if (y->right == 0) {
evaluated: y->right == 0
TRUEFALSE
yes
Evaluation Count:879
yes
Evaluation Count:894
879-894
188 x = y->left;
executed (the execution status of this line is deduced): x = y->left;
-
189 } else {
executed: }
Execution Count:879
879
190 y = y->right;
executed (the execution status of this line is deduced): y = y->right;
-
191 while (y->left != 0)
evaluated: y->left != 0
TRUEFALSE
yes
Evaluation Count:184
yes
Evaluation Count:894
184-894
192 y = y->left;
executed: y = y->left;
Execution Count:184
184
193 x = y->right;
executed (the execution status of this line is deduced): x = y->right;
-
194 }
executed: }
Execution Count:894
894
195 } -
196 if (y != z) {
evaluated: y != z
TRUEFALSE
yes
Evaluation Count:894
yes
Evaluation Count:67640
894-67640
197 z->left->setParent(y);
executed (the execution status of this line is deduced): z->left->setParent(y);
-
198 y->left = z->left;
executed (the execution status of this line is deduced): y->left = z->left;
-
199 if (y != z->right) {
evaluated: y != z->right
TRUEFALSE
yes
Evaluation Count:178
yes
Evaluation Count:716
178-716
200 x_parent = y->parent();
executed (the execution status of this line is deduced): x_parent = y->parent();
-
201 if (x)
evaluated: x
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:162
16-162
202 x->setParent(y->parent());
executed: x->setParent(y->parent());
Execution Count:16
16
203 y->parent()->left = x;
executed (the execution status of this line is deduced): y->parent()->left = x;
-
204 y->right = z->right;
executed (the execution status of this line is deduced): y->right = z->right;
-
205 z->right->setParent(y);
executed (the execution status of this line is deduced): z->right->setParent(y);
-
206 } else {
executed: }
Execution Count:178
178
207 x_parent = y;
executed (the execution status of this line is deduced): x_parent = y;
-
208 }
executed: }
Execution Count:716
716
209 if (root == z)
evaluated: root == z
TRUEFALSE
yes
Evaluation Count:611
yes
Evaluation Count:283
283-611
210 root = y;
executed: root = y;
Execution Count:611
611
211 else if (z->parent()->left == z)
evaluated: z->parent()->left == z
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:203
80-203
212 z->parent()->left = y;
executed: z->parent()->left = y;
Execution Count:80
80
213 else -
214 z->parent()->right = y;
executed: z->parent()->right = y;
Execution Count:203
203
215 y->setParent(z->parent());
executed (the execution status of this line is deduced): y->setParent(z->parent());
-
216 // Swap the colors -
217 QMapNodeBase::Color c = y->color();
executed (the execution status of this line is deduced): QMapNodeBase::Color c = y->color();
-
218 y->setColor(z->color());
executed (the execution status of this line is deduced): y->setColor(z->color());
-
219 z->setColor(c);
executed (the execution status of this line is deduced): z->setColor(c);
-
220 y = z;
executed (the execution status of this line is deduced): y = z;
-
221 } else {
executed: }
Execution Count:894
894
222 x_parent = y->parent();
executed (the execution status of this line is deduced): x_parent = y->parent();
-
223 if (x)
evaluated: x
TRUEFALSE
yes
Evaluation Count:14669
yes
Evaluation Count:52971
14669-52971
224 x->setParent(y->parent());
executed: x->setParent(y->parent());
Execution Count:14669
14669
225 if (root == z)
evaluated: root == z
TRUEFALSE
yes
Evaluation Count:36466
yes
Evaluation Count:31174
31174-36466
226 root = x;
executed: root = x;
Execution Count:36466
36466
227 else if (z->parent()->left == z)
evaluated: z->parent()->left == z
TRUEFALSE
yes
Evaluation Count:29500
yes
Evaluation Count:1674
1674-29500
228 z->parent()->left = x;
executed: z->parent()->left = x;
Execution Count:29500
29500
229 else -
230 z->parent()->right = x;
executed: z->parent()->right = x;
Execution Count:1674
1674
231 } -
232 if (y->color() != QMapNodeBase::Red) {
evaluated: y->color() != QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:64795
yes
Evaluation Count:3739
3739-64795
233 while (x != root && (x == 0 || x->color() == QMapNodeBase::Black)) {
evaluated: x != root
TRUEFALSE
yes
Evaluation Count:43111
yes
Evaluation Count:39162
evaluated: x == 0
TRUEFALSE
yes
Evaluation Count:17293
yes
Evaluation Count:25818
evaluated: x->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:7337
yes
Evaluation Count:18481
7337-43111
234 if (x == x_parent->left) {
evaluated: x == x_parent->left
TRUEFALSE
yes
Evaluation Count:24001
yes
Evaluation Count:629
629-24001
235 QMapNodeBase *w = x_parent->right;
executed (the execution status of this line is deduced): QMapNodeBase *w = x_parent->right;
-
236 if (w->color() == QMapNodeBase::Red) {
evaluated: w->color() == QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:7093
yes
Evaluation Count:16908
7093-16908
237 w->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Black);
-
238 x_parent->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x_parent->setColor(QMapNodeBase::Red);
-
239 rotateLeft(x_parent);
executed (the execution status of this line is deduced): rotateLeft(x_parent);
-
240 w = x_parent->right;
executed (the execution status of this line is deduced): w = x_parent->right;
-
241 }
executed: }
Execution Count:7093
7093
242 if ((w->left == 0 || w->left->color() == QMapNodeBase::Black) &&
evaluated: w->left == 0
TRUEFALSE
yes
Evaluation Count:13573
yes
Evaluation Count:10428
evaluated: w->left->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:6877
yes
Evaluation Count:3551
3551-13573
243 (w->right == 0 || w->right->color() == QMapNodeBase::Black)) {
evaluated: w->right == 0
TRUEFALSE
yes
Evaluation Count:10561
yes
Evaluation Count:9889
evaluated: w->right->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:6426
yes
Evaluation Count:3463
3463-10561
244 w->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Red);
-
245 x = x_parent;
executed (the execution status of this line is deduced): x = x_parent;
-
246 x_parent = x_parent->parent();
executed (the execution status of this line is deduced): x_parent = x_parent->parent();
-
247 } else {
executed: }
Execution Count:16987
16987
248 if (w->right == 0 || w->right->color() == QMapNodeBase::Black) {
evaluated: w->right == 0
TRUEFALSE
yes
Evaluation Count:1526
yes
Evaluation Count:5488
evaluated: w->right->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:161
yes
Evaluation Count:5327
161-5488
249 if (w->left)
partially evaluated: w->left
TRUEFALSE
yes
Evaluation Count:1687
no
Evaluation Count:0
0-1687
250 w->left->setColor(QMapNodeBase::Black);
executed: w->left->setColor(QMapNodeBase::Black);
Execution Count:1687
1687
251 w->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Red);
-
252 rotateRight(w);
executed (the execution status of this line is deduced): rotateRight(w);
-
253 w = x_parent->right;
executed (the execution status of this line is deduced): w = x_parent->right;
-
254 }
executed: }
Execution Count:1687
1687
255 w->setColor(x_parent->color());
executed (the execution status of this line is deduced): w->setColor(x_parent->color());
-
256 x_parent->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x_parent->setColor(QMapNodeBase::Black);
-
257 if (w->right)
partially evaluated: w->right
TRUEFALSE
yes
Evaluation Count:7014
no
Evaluation Count:0
0-7014
258 w->right->setColor(QMapNodeBase::Black);
executed: w->right->setColor(QMapNodeBase::Black);
Execution Count:7014
7014
259 rotateLeft(x_parent);
executed (the execution status of this line is deduced): rotateLeft(x_parent);
-
260 break;
executed: break;
Execution Count:7014
7014
261 } -
262 } else { -
263 QMapNodeBase *w = x_parent->left;
executed (the execution status of this line is deduced): QMapNodeBase *w = x_parent->left;
-
264 if (w->color() == QMapNodeBase::Red) {
evaluated: w->color() == QMapNodeBase::Red
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:617
12-617
265 w->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Black);
-
266 x_parent->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): x_parent->setColor(QMapNodeBase::Red);
-
267 rotateRight(x_parent);
executed (the execution status of this line is deduced): rotateRight(x_parent);
-
268 w = x_parent->left;
executed (the execution status of this line is deduced): w = x_parent->left;
-
269 }
executed: }
Execution Count:12
12
270 if ((w->right == 0 || w->right->color() == QMapNodeBase::Black) &&
evaluated: w->right == 0
TRUEFALSE
yes
Evaluation Count:526
yes
Evaluation Count:103
evaluated: w->right->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:90
13-526
271 (w->left == 0 || w->left->color() == QMapNodeBase::Black)) {
evaluated: w->left == 0
TRUEFALSE
yes
Evaluation Count:478
yes
Evaluation Count:61
evaluated: w->left->color() == QMapNodeBase::Black
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:48
13-478
272 w->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Red);
-
273 x = x_parent;
executed (the execution status of this line is deduced): x = x_parent;
-
274 x_parent = x_parent->parent();
executed (the execution status of this line is deduced): x_parent = x_parent->parent();
-
275 } else {
executed: }
Execution Count:491
491
276 if (w->left == 0 || w->left->color() == QMapNodeBase::Black) {
evaluated: w->left == 0
TRUEFALSE
yes
Evaluation Count:54
yes
Evaluation Count:84
partially evaluated: w->left->color() == QMapNodeBase::Black
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:84
0-84
277 if (w->right)
partially evaluated: w->right
TRUEFALSE
yes
Evaluation Count:54
no
Evaluation Count:0
0-54
278 w->right->setColor(QMapNodeBase::Black);
executed: w->right->setColor(QMapNodeBase::Black);
Execution Count:54
54
279 w->setColor(QMapNodeBase::Red);
executed (the execution status of this line is deduced): w->setColor(QMapNodeBase::Red);
-
280 rotateLeft(w);
executed (the execution status of this line is deduced): rotateLeft(w);
-
281 w = x_parent->left;
executed (the execution status of this line is deduced): w = x_parent->left;
-
282 }
executed: }
Execution Count:54
54
283 w->setColor(x_parent->color());
executed (the execution status of this line is deduced): w->setColor(x_parent->color());
-
284 x_parent->setColor(QMapNodeBase::Black);
executed (the execution status of this line is deduced): x_parent->setColor(QMapNodeBase::Black);
-
285 if (w->left)
partially evaluated: w->left
TRUEFALSE
yes
Evaluation Count:138
no
Evaluation Count:0
0-138
286 w->left->setColor(QMapNodeBase::Black);
executed: w->left->setColor(QMapNodeBase::Black);
Execution Count:138
138
287 rotateRight(x_parent);
executed (the execution status of this line is deduced): rotateRight(x_parent);
-
288 break;
executed: break;
Execution Count:138
138
289 } -
290 } -
291 } -
292 if (x)
evaluated: x
TRUEFALSE
yes
Evaluation Count:25824
yes
Evaluation Count:38971
25824-38971
293 x->setColor(QMapNodeBase::Black);
executed: x->setColor(QMapNodeBase::Black);
Execution Count:25824
25824
294 }
executed: }
Execution Count:64795
64795
295 free(y);
executed (the execution status of this line is deduced): free(y);
-
296 --size;
executed (the execution status of this line is deduced): --size;
-
297}
executed: }
Execution Count:68534
68534
298 -
299void QMapDataBase::recalcMostLeftNode() -
300{ -
301 mostLeftNode = &header;
executed (the execution status of this line is deduced): mostLeftNode = &header;
-
302 while (mostLeftNode->left)
evaluated: mostLeftNode->left
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:914553
1304-914553
303 mostLeftNode = mostLeftNode->left;
executed: mostLeftNode = mostLeftNode->left;
Execution Count:1304
1304
304}
executed: }
Execution Count:914272
914272
305 -
306static inline int qMapAlignmentThreshold() -
307{ -
308 // malloc on 32-bit platforms should return pointers that are 8-byte -
309 // aligned or more while on 64-bit platforms they should be 16-byte aligned -
310 // or more -
311 return 2 * sizeof(void*);
executed: return 2 * sizeof(void*);
Execution Count:2751836
2751836
312} -
313 -
314static inline void *qMapAllocate(int alloc, int alignment) -
315{ -
316 return alignment > qMapAlignmentThreshold()
executed: return alignment > qMapAlignmentThreshold() ? qMallocAligned(alloc, alignment) : ::malloc(alloc);
Execution Count:1408382
1408382
317 ? qMallocAligned(alloc, alignment)
executed: return alignment > qMapAlignmentThreshold() ? qMallocAligned(alloc, alignment) : ::malloc(alloc);
Execution Count:1408382
1408382
318 : ::malloc(alloc);
executed: return alignment > qMapAlignmentThreshold() ? qMallocAligned(alloc, alignment) : ::malloc(alloc);
Execution Count:1408382
1408382
319} -
320 -
321static inline void qMapDeallocate(QMapNodeBase *node, int alignment) -
322{ -
323 if (alignment > qMapAlignmentThreshold())
evaluated: alignment > qMapAlignmentThreshold()
TRUEFALSE
yes
Evaluation Count:600
yes
Evaluation Count:1344540
600-1344540
324 qFreeAligned(node);
executed: qFreeAligned(node);
Execution Count:600
600
325 else -
326 ::free(node);
executed: ::free(node);
Execution Count:1344308
1344308
327} -
328 -
329QMapNodeBase *QMapDataBase::createNode(int alloc, int alignment, QMapNodeBase *parent, bool left) -
330{ -
331 QMapNodeBase *node = static_cast<QMapNodeBase *>(qMapAllocate(alloc, alignment));
executed (the execution status of this line is deduced): QMapNodeBase *node = static_cast<QMapNodeBase *>(qMapAllocate(alloc, alignment));
-
332 Q_CHECK_PTR(node);
never executed: qBadAlloc();
executed: }
Execution Count:1408884
partially evaluated: !(node)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1409177
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1408498
0-1409177
333 -
334 memset(node, 0, alloc);
executed (the execution status of this line is deduced): memset(node, 0, alloc);
-
335 ++size;
executed (the execution status of this line is deduced): ++size;
-
336 -
337 if (parent) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:1401954
yes
Evaluation Count:6590
6590-1401954
338 if (left) {
evaluated: left
TRUEFALSE
yes
Evaluation Count:816356
yes
Evaluation Count:585344
585344-816356
339 parent->left = node;
executed (the execution status of this line is deduced): parent->left = node;
-
340 if (parent == mostLeftNode)
evaluated: parent == mostLeftNode
TRUEFALSE
yes
Evaluation Count:773125
yes
Evaluation Count:42950
42950-773125
341 mostLeftNode = node;
executed: mostLeftNode = node;
Execution Count:773026
773026
342 } else {
executed: }
Execution Count:816215
816215
343 parent->right = node;
executed (the execution status of this line is deduced): parent->right = node;
-
344 }
executed: }
Execution Count:585344
585344
345 node->setParent(parent);
executed (the execution status of this line is deduced): node->setParent(parent);
-
346 rebalance(node);
executed (the execution status of this line is deduced): rebalance(node);
-
347 }
executed: }
Execution Count:1400839
1400839
348 return node;
executed: return node;
Execution Count:1407535
1407535
349} -
350 -
351void QMapDataBase::freeTree(QMapNodeBase *root, int alignment) -
352{ -
353 if (root->left)
evaluated: root->left
TRUEFALSE
yes
Evaluation Count:354179
yes
Evaluation Count:991468
354179-991468
354 freeTree(root->left, alignment);
executed: freeTree(root->left, alignment);
Execution Count:354179
354179
355 if (root->right)
evaluated: root->right
TRUEFALSE
yes
Evaluation Count:369062
yes
Evaluation Count:976640
369062-976640
356 freeTree(root->right, alignment);
executed: freeTree(root->right, alignment);
Execution Count:369062
369062
357 qMapDeallocate(root, alignment);
executed (the execution status of this line is deduced): qMapDeallocate(root, alignment);
-
358}
executed: }
Execution Count:1345114
1345114
359 -
360QMapDataBase *QMapDataBase::createData() -
361{ -
362 QMapDataBase *d = new QMapDataBase;
executed (the execution status of this line is deduced): QMapDataBase *d = new QMapDataBase;
-
363 -
364 d->ref.initializeOwned();
executed (the execution status of this line is deduced): d->ref.initializeOwned();
-
365 d->size = 0;
executed (the execution status of this line is deduced): d->size = 0;
-
366 -
367 d->header.p = 0;
executed (the execution status of this line is deduced): d->header.p = 0;
-
368 d->header.left = 0;
executed (the execution status of this line is deduced): d->header.left = 0;
-
369 d->header.right = 0;
executed (the execution status of this line is deduced): d->header.right = 0;
-
370 d->mostLeftNode = &(d->header);
executed (the execution status of this line is deduced): d->mostLeftNode = &(d->header);
-
371 -
372 return d;
executed: return d;
Execution Count:914551
914551
373} -
374 -
375void QMapDataBase::freeData(QMapDataBase *d) -
376{ -
377 delete d;
executed (the execution status of this line is deduced): delete d;
-
378}
executed: }
Execution Count:916805
916805
379 -
380/*! -
381 \class QMap -
382 \inmodule QtCore -
383 \brief The QMap class is a template class that provides a red-black-tree-based dictionary. -
384 -
385 \ingroup tools -
386 \ingroup shared -
387 -
388 \reentrant -
389 -
390 QMap\<Key, T\> is one of Qt's generic \l{container classes}. It -
391 stores (key, value) pairs and provides fast lookup of the -
392 value associated with a key. -
393 -
394 QMap and QHash provide very similar functionality. The -
395 differences are: -
396 -
397 \list -
398 \li QHash provides faster lookups than QMap. (See \l{Algorithmic -
399 Complexity} for details.) -
400 \li When iterating over a QHash, the items are arbitrarily ordered. -
401 With QMap, the items are always sorted by key. -
402 \li The key type of a QHash must provide operator==() and a global -
403 qHash(Key) function. The key type of a QMap must provide -
404 operator<() specifying a total order. -
405 \endlist -
406 -
407 Here's an example QMap with QString keys and \c int values: -
408 \snippet code/src_corelib_tools_qmap.cpp 0 -
409 -
410 To insert a (key, value) pair into the map, you can use operator[](): -
411 -
412 \snippet code/src_corelib_tools_qmap.cpp 1 -
413 -
414 This inserts the following three (key, value) pairs into the -
415 QMap: ("one", 1), ("three", 3), and ("seven", 7). Another way to -
416 insert items into the map is to use insert(): -
417 -
418 \snippet code/src_corelib_tools_qmap.cpp 2 -
419 -
420 To look up a value, use operator[]() or value(): -
421 -
422 \snippet code/src_corelib_tools_qmap.cpp 3 -
423 -
424 If there is no item with the specified key in the map, these -
425 functions return a \l{default-constructed value}. -
426 -
427 If you want to check whether the map contains a certain key, use -
428 contains(): -
429 -
430 \snippet code/src_corelib_tools_qmap.cpp 4 -
431 -
432 There is also a value() overload that uses its second argument as -
433 a default value if there is no item with the specified key: -
434 -
435 \snippet code/src_corelib_tools_qmap.cpp 5 -
436 -
437 In general, we recommend that you use contains() and value() -
438 rather than operator[]() for looking up a key in a map. The -
439 reason is that operator[]() silently inserts an item into the -
440 map if no item exists with the same key (unless the map is -
441 const). For example, the following code snippet will create 1000 -
442 items in memory: -
443 -
444 \snippet code/src_corelib_tools_qmap.cpp 6 -
445 -
446 To avoid this problem, replace \c map[i] with \c map.value(i) -
447 in the code above. -
448 -
449 If you want to navigate through all the (key, value) pairs stored -
450 in a QMap, you can use an iterator. QMap provides both -
451 \l{Java-style iterators} (QMapIterator and QMutableMapIterator) -
452 and \l{STL-style iterators} (QMap::const_iterator and -
453 QMap::iterator). Here's how to iterate over a QMap<QString, int> -
454 using a Java-style iterator: -
455 -
456 \snippet code/src_corelib_tools_qmap.cpp 7 -
457 -
458 Here's the same code, but using an STL-style iterator this time: -
459 -
460 \snippet code/src_corelib_tools_qmap.cpp 8 -
461 -
462 The items are traversed in ascending key order. -
463 -
464 Normally, a QMap allows only one value per key. If you call -
465 insert() with a key that already exists in the QMap, the -
466 previous value will be erased. For example: -
467 -
468 \snippet code/src_corelib_tools_qmap.cpp 9 -
469 -
470 However, you can store multiple values per key by using -
471 insertMulti() instead of insert() (or using the convenience -
472 subclass QMultiMap). If you want to retrieve all the values for a -
473 single key, you can use values(const Key &key), which returns a -
474 QList<T>: -
475 -
476 \snippet code/src_corelib_tools_qmap.cpp 10 -
477 -
478 The items that share the same key are available from most -
479 recently to least recently inserted. Another approach is to call -
480 find() to get the STL-style iterator for the first item with a -
481 key and iterate from there: -
482 -
483 \snippet code/src_corelib_tools_qmap.cpp 11 -
484 -
485 If you only need to extract the values from a map (not the keys), -
486 you can also use \l{foreach}: -
487 -
488 \snippet code/src_corelib_tools_qmap.cpp 12 -
489 -
490 Items can be removed from the map in several ways. One way is to -
491 call remove(); this will remove any item with the given key. -
492 Another way is to use QMutableMapIterator::remove(). In addition, -
493 you can clear the entire map using clear(). -
494 -
495 QMap's key and value data types must be \l{assignable data -
496 types}. This covers most data types you are likely to encounter, -
497 but the compiler won't let you, for example, store a QWidget as a -
498 value; instead, store a QWidget *. In addition, QMap's key type -
499 must provide operator<(). QMap uses it to keep its items sorted, -
500 and assumes that two keys \c x and \c y are equal if neither \c{x -
501 < y} nor \c{y < x} is true. -
502 -
503 Example: -
504 \snippet code/src_corelib_tools_qmap.cpp 13 -
505 -
506 In the example, we start by comparing the employees' names. If -
507 they're equal, we compare their dates of birth to break the tie. -
508 -
509 \sa QMapIterator, QMutableMapIterator, QHash, QSet -
510*/ -
511 -
512/*! \fn QMap::QMap() -
513 -
514 Constructs an empty map. -
515 -
516 \sa clear() -
517*/ -
518 -
519/*! \fn QMap::QMap(const QMap<Key, T> &other) -
520 -
521 Constructs a copy of \a other. -
522 -
523 This operation occurs in \l{constant time}, because QMap is -
524 \l{implicitly shared}. This makes returning a QMap from a -
525 function very fast. If a shared instance is modified, it will be -
526 copied (copy-on-write), and this takes \l{linear time}. -
527 -
528 \sa operator=() -
529*/ -
530 -
531/*! \fn QMap::QMap(const std::map<Key, T> & other) -
532 -
533 Constructs a copy of \a other. -
534 -
535 This function is only available if Qt is configured with STL -
536 compatibility enabled. -
537 -
538 \sa toStdMap() -
539*/ -
540 -
541/*! \fn std::map<Key, T> QMap::toStdMap() const -
542 -
543 Returns an STL map equivalent to this QMap. -
544 -
545 This function is only available if Qt is configured with STL -
546 compatibility enabled. -
547*/ -
548 -
549/*! \fn QMap::~QMap() -
550 -
551 Destroys the map. References to the values in the map, and all -
552 iterators over this map, become invalid. -
553*/ -
554 -
555/*! \fn QMap<Key, T> &QMap::operator=(const QMap<Key, T> &other) -
556 -
557 Assigns \a other to this map and returns a reference to this map. -
558*/ -
559 -
560/*! \fn void QMap::swap(QMap<Key, T> &other) -
561 \since 4.8 -
562 -
563 Swaps map \a other with this map. This operation is very -
564 fast and never fails. -
565*/ -
566 -
567/*! \fn void QMultiMap::swap(QMultiMap<Key, T> &other) -
568 \since 4.8 -
569 -
570 Swaps map \a other with this map. This operation is very -
571 fast and never fails. -
572*/ -
573 -
574/*! \fn bool QMap::operator==(const QMap<Key, T> &other) const -
575 -
576 Returns true if \a other is equal to this map; otherwise returns -
577 false. -
578 -
579 Two maps are considered equal if they contain the same (key, -
580 value) pairs. -
581 -
582 This function requires the value type to implement \c -
583 operator==(). -
584 -
585 \sa operator!=() -
586*/ -
587 -
588/*! \fn bool QMap::operator!=(const QMap<Key, T> &other) const -
589 -
590 Returns true if \a other is not equal to this map; otherwise -
591 returns false. -
592 -
593 Two maps are considered equal if they contain the same (key, -
594 value) pairs. -
595 -
596 This function requires the value type to implement \c -
597 operator==(). -
598 -
599 \sa operator==() -
600*/ -
601 -
602/*! \fn int QMap::size() const -
603 -
604 Returns the number of (key, value) pairs in the map. -
605 -
606 \sa isEmpty(), count() -
607*/ -
608 -
609/*! -
610 \fn bool QMap::isEmpty() const -
611 -
612 Returns true if the map contains no items; otherwise returns -
613 false. -
614 -
615 \sa size() -
616*/ -
617 -
618/*! \fn void QMap::detach() -
619 -
620 \internal -
621 -
622 Detaches this map from any other maps with which it may share -
623 data. -
624 -
625 \sa isDetached() -
626*/ -
627 -
628/*! \fn bool QMap::isDetached() const -
629 -
630 \internal -
631 -
632 Returns true if the map's internal data isn't shared with any -
633 other map object; otherwise returns false. -
634 -
635 \sa detach() -
636*/ -
637 -
638/*! \fn void QMap::setSharable(bool sharable) -
639 -
640 \internal -
641*/ -
642 -
643/*! \fn bool QMap::isSharedWith(const QMap<Key, T> &other) const -
644 -
645 \internal -
646*/ -
647 -
648/*! \fn void QMap::clear() -
649 -
650 Removes all items from the map. -
651 -
652 \sa remove() -
653*/ -
654 -
655/*! \fn int QMap::remove(const Key &key) -
656 -
657 Removes all the items that have the key \a key from the map. -
658 Returns the number of items removed which is usually 1 but will be -
659 0 if the key isn't in the map, or \> 1 if insertMulti() has been -
660 used with the \a key. -
661 -
662 \sa clear(), take(), QMultiMap::remove() -
663*/ -
664 -
665/*! \fn T QMap::take(const Key &key) -
666 -
667 Removes the item with the key \a key from the map and returns -
668 the value associated with it. -
669 -
670 If the item does not exist in the map, the function simply -
671 returns a \l{default-constructed value}. If there are multiple -
672 items for \a key in the map, only the most recently inserted one -
673 is removed and returned. -
674 -
675 If you don't use the return value, remove() is more efficient. -
676 -
677 \sa remove() -
678*/ -
679 -
680/*! \fn bool QMap::contains(const Key &key) const -
681 -
682 Returns true if the map contains an item with key \a key; -
683 otherwise returns false. -
684 -
685 \sa count(), QMultiMap::contains() -
686*/ -
687 -
688/*! \fn const T QMap::value(const Key &key, const T &defaultValue) const -
689 -
690 Returns the value associated with the key \a key. -
691 -
692 If the map contains no item with key \a key, the function returns -
693 \a defaultValue. If no \a defaultValue is specified, the function -
694 returns a \l{default-constructed value}. If there are multiple -
695 items for \a key in the map, the value of the most recently -
696 inserted one is returned. -
697 -
698 \sa key(), values(), contains(), operator[]() -
699*/ -
700 -
701/*! \fn T &QMap::operator[](const Key &key) -
702 -
703 Returns the value associated with the key \a key as a modifiable -
704 reference. -
705 -
706 If the map contains no item with key \a key, the function inserts -
707 a \l{default-constructed value} into the map with key \a key, and -
708 returns a reference to it. If the map contains multiple items -
709 with key \a key, this function returns a reference to the most -
710 recently inserted value. -
711 -
712 \sa insert(), value() -
713*/ -
714 -
715/*! \fn const T QMap::operator[](const Key &key) const -
716 -
717 \overload -
718 -
719 Same as value(). -
720*/ -
721 -
722/*! \fn QList<Key> QMap::uniqueKeys() const -
723 \since 4.2 -
724 -
725 Returns a list containing all the keys in the map in ascending -
726 order. Keys that occur multiple times in the map (because items -
727 were inserted with insertMulti(), or unite() was used) occur only -
728 once in the returned list. -
729 -
730 \sa keys(), values() -
731*/ -
732 -
733/*! \fn QList<Key> QMap::keys() const -
734 -
735 Returns a list containing all the keys in the map in ascending -
736 order. Keys that occur multiple times in the map (because items -
737 were inserted with insertMulti(), or unite() was used) also -
738 occur multiple times in the list. -
739 -
740 To obtain a list of unique keys, where each key from the map only -
741 occurs once, use uniqueKeys(). -
742 -
743 The order is guaranteed to be the same as that used by values(). -
744 -
745 \sa uniqueKeys(), values(), key() -
746*/ -
747 -
748/*! \fn QList<Key> QMap::keys(const T &value) const -
749 -
750 \overload -
751 -
752 Returns a list containing all the keys associated with value \a -
753 value in ascending order. -
754 -
755 This function can be slow (\l{linear time}), because QMap's -
756 internal data structure is optimized for fast lookup by key, not -
757 by value. -
758*/ -
759 -
760/*! -
761 \fn Key QMap::key(const T &value, const Key &defaultKey) const -
762 \since 4.3 -
763 \overload -
764 -
765 Returns the first key with value \a value, or \a defaultKey if -
766 the map contains no item with value \a value. If no \a defaultKey -
767 is provided the function returns a -
768 \l{default-constructed value}{default-constructed key}. -
769 -
770 This function can be slow (\l{linear time}), because QMap's -
771 internal data structure is optimized for fast lookup by key, not -
772 by value. -
773 -
774 \sa value(), keys() -
775*/ -
776 -
777/*! \fn QList<T> QMap::values() const -
778 -
779 Returns a list containing all the values in the map, in ascending -
780 order of their keys. If a key is associated with multiple values, -
781 all of its values will be in the list, and not just the most -
782 recently inserted one. -
783 -
784 \sa keys(), value() -
785*/ -
786 -
787/*! \fn QList<T> QMap::values(const Key &key) const -
788 -
789 \overload -
790 -
791 Returns a list containing all the values associated with key -
792 \a key, from the most recently inserted to the least recently -
793 inserted one. -
794 -
795 \sa count(), insertMulti() -
796*/ -
797 -
798/*! \fn int QMap::count(const Key &key) const -
799 -
800 Returns the number of items associated with key \a key. -
801 -
802 \sa contains(), insertMulti(), QMultiMap::count() -
803*/ -
804 -
805/*! \fn int QMap::count() const -
806 -
807 \overload -
808 -
809 Same as size(). -
810*/ -
811 -
812/*! \fn QMap::iterator QMap::begin() -
813 -
814 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in -
815 the map. -
816 -
817 \sa constBegin(), end() -
818*/ -
819 -
820/*! \fn QMap::const_iterator QMap::begin() const -
821 -
822 \overload -
823*/ -
824 -
825/*! \fn QMap::const_iterator QMap::cbegin() const -
826 \since 5.0 -
827 -
828 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item -
829 in the map. -
830 -
831 \sa begin(), cend() -
832*/ -
833 -
834/*! \fn QMap::const_iterator QMap::constBegin() const -
835 -
836 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item -
837 in the map. -
838 -
839 \sa begin(), constEnd() -
840*/ -
841 -
842/*! \fn QMap::iterator QMap::end() -
843 -
844 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item -
845 after the last item in the map. -
846 -
847 \sa begin(), constEnd() -
848*/ -
849 -
850/*! \fn QMap::const_iterator QMap::end() const -
851 -
852 \overload -
853*/ -
854 -
855/*! \fn QMap::const_iterator QMap::cend() const -
856 \since 5.0 -
857 -
858 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary -
859 item after the last item in the map. -
860 -
861 \sa cbegin(), end() -
862*/ -
863 -
864/*! \fn QMap::const_iterator QMap::constEnd() const -
865 -
866 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary -
867 item after the last item in the map. -
868 -
869 \sa constBegin(), end() -
870*/ -
871 -
872/*! \fn QMap::iterator QMap::erase(iterator pos) -
873 -
874 Removes the (key, value) pair pointed to by the iterator \a pos -
875 from the map, and returns an iterator to the next item in the -
876 map. -
877 -
878 \sa remove() -
879*/ -
880 -
881/*! \fn QMap::iterator QMap::find(const Key &key) -
882 -
883 Returns an iterator pointing to the item with key \a key in the -
884 map. -
885 -
886 If the map contains no item with key \a key, the function -
887 returns end(). -
888 -
889 If the map contains multiple items with key \a key, this -
890 function returns an iterator that points to the most recently -
891 inserted value. The other values are accessible by incrementing -
892 the iterator. For example, here's some code that iterates over all -
893 the items with the same key: -
894 -
895 \snippet code/src_corelib_tools_qmap.cpp 14 -
896 -
897 \sa constFind(), value(), values(), lowerBound(), upperBound(), QMultiMap::find() -
898*/ -
899 -
900/*! \fn QMap::const_iterator QMap::find(const Key &key) const -
901 -
902 \overload -
903*/ -
904 -
905/*! \fn QMap::const_iterator QMap::constFind(const Key &key) const -
906 \since 4.1 -
907 -
908 Returns an const iterator pointing to the item with key \a key in the -
909 map. -
910 -
911 If the map contains no item with key \a key, the function -
912 returns constEnd(). -
913 -
914 \sa find(), QMultiMap::constFind() -
915*/ -
916 -
917/*! \fn QMap::iterator QMap::lowerBound(const Key &key) -
918 -
919 Returns an iterator pointing to the first item with key \a key in -
920 the map. If the map contains no item with key \a key, the -
921 function returns an iterator to the nearest item with a greater -
922 key. -
923 -
924 Example: -
925 \snippet code/src_corelib_tools_qmap.cpp 15 -
926 -
927 If the map contains multiple items with key \a key, this -
928 function returns an iterator that points to the most recently -
929 inserted value. The other values are accessible by incrementing -
930 the iterator. For example, here's some code that iterates over all -
931 the items with the same key: -
932 -
933 \snippet code/src_corelib_tools_qmap.cpp 16 -
934 -
935 \sa upperBound(), find() -
936*/ -
937 -
938/*! \fn QMap::const_iterator QMap::lowerBound(const Key &key) const -
939 -
940 \overload -
941*/ -
942 -
943/*! \fn QMap::iterator QMap::upperBound(const Key &key) -
944 -
945 Returns an iterator pointing to the item that immediately follows -
946 the last item with key \a key in the map. If the map contains no -
947 item with key \a key, the function returns an iterator to the -
948 nearest item with a greater key. -
949 -
950 Example: -
951 \snippet code/src_corelib_tools_qmap.cpp 17 -
952 -
953 \sa lowerBound(), find() -
954*/ -
955 -
956/*! \fn QMap::const_iterator QMap::upperBound(const Key &key) const -
957 -
958 \overload -
959*/ -
960 -
961/*! \fn QMap::iterator QMap::insert(const Key &key, const T &value) -
962 -
963 Inserts a new item with the key \a key and a value of \a value. -
964 -
965 If there is already an item with the key \a key, that item's value -
966 is replaced with \a value. -
967 -
968 If there are multiple items with the key \a key, the most -
969 recently inserted item's value is replaced with \a value. -
970 -
971 \sa insertMulti() -
972*/ -
973 -
974/*! \fn QMap::iterator QMap::insertMulti(const Key &key, const T &value) -
975 -
976 Inserts a new item with the key \a key and a value of \a value. -
977 -
978 If there is already an item with the same key in the map, this -
979 function will simply create a new one. (This behavior is -
980 different from insert(), which overwrites the value of an -
981 existing item.) -
982 -
983 \sa insert(), values() -
984*/ -
985 -
986/*! \fn QMap<Key, T> &QMap::unite(const QMap<Key, T> &other) -
987 -
988 Inserts all the items in the \a other map into this map. If a -
989 key is common to both maps, the resulting map will contain the -
990 key multiple times. -
991 -
992 \sa insertMulti() -
993*/ -
994 -
995/*! \typedef QMap::Iterator -
996 -
997 Qt-style synonym for QMap::iterator. -
998*/ -
999 -
1000/*! \typedef QMap::ConstIterator -
1001 -
1002 Qt-style synonym for QMap::const_iterator. -
1003*/ -
1004 -
1005/*! \typedef QMap::difference_type -
1006 -
1007 Typedef for ptrdiff_t. Provided for STL compatibility. -
1008*/ -
1009 -
1010/*! \typedef QMap::key_type -
1011 -
1012 Typedef for Key. Provided for STL compatibility. -
1013*/ -
1014 -
1015/*! \typedef QMap::mapped_type -
1016 -
1017 Typedef for T. Provided for STL compatibility. -
1018*/ -
1019 -
1020/*! \typedef QMap::size_type -
1021 -
1022 Typedef for int. Provided for STL compatibility. -
1023*/ -
1024 -
1025/*! -
1026 \fn bool QMap::empty() const -
1027 -
1028 This function is provided for STL compatibility. It is equivalent -
1029 to isEmpty(), returning true if the map is empty; otherwise -
1030 returning false. -
1031*/ -
1032 -
1033/*! -
1034 \fn QPair<iterator, iterator> QMap::equal_range(const Key &key) -
1035 -
1036 Returns a pair of iterators delimiting the range of values that -
1037 are stored under \a key. -
1038*/ -
1039 -
1040 -
1041/*! \class QMap::iterator -
1042 \inmodule QtCore -
1043 \brief The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap. -
1044 -
1045 QMap features both \l{STL-style iterators} and \l{Java-style -
1046 iterators}. The STL-style iterators are more low-level and more -
1047 cumbersome to use; on the other hand, they are slightly faster -
1048 and, for developers who already know STL, have the advantage of -
1049 familiarity. -
1050 -
1051 QMap\<Key, T\>::iterator allows you to iterate over a QMap (or -
1052 QMultiMap) and to modify the value (but not the key) stored under -
1053 a particular key. If you want to iterate over a const QMap, you -
1054 should use QMap::const_iterator. It is generally good practice to -
1055 use QMap::const_iterator on a non-const QMap as well, unless you -
1056 need to change the QMap through the iterator. Const iterators are -
1057 slightly faster, and can improve code readability. -
1058 -
1059 The default QMap::iterator constructor creates an uninitialized -
1060 iterator. You must initialize it using a QMap function like -
1061 QMap::begin(), QMap::end(), or QMap::find() before you can -
1062 start iterating. Here's a typical loop that prints all the (key, -
1063 value) pairs stored in a map: -
1064 -
1065 \snippet code/src_corelib_tools_qmap.cpp 18 -
1066 -
1067 Unlike QHash, which stores its items in an arbitrary order, QMap -
1068 stores its items ordered by key. Items that share the same key -
1069 (because they were inserted using QMap::insertMulti(), or due to a -
1070 unite()) will appear consecutively, from the most recently to the -
1071 least recently inserted value. -
1072 -
1073 Let's see a few examples of things we can do with a -
1074 QMap::iterator that we cannot do with a QMap::const_iterator. -
1075 Here's an example that increments every value stored in the QMap -
1076 by 2: -
1077 -
1078 \snippet code/src_corelib_tools_qmap.cpp 19 -
1079 -
1080 Here's an example that removes all the items whose key is a -
1081 string that starts with an underscore character: -
1082 -
1083 \snippet code/src_corelib_tools_qmap.cpp 20 -
1084 -
1085 The call to QMap::erase() removes the item pointed to by the -
1086 iterator from the map, and returns an iterator to the next item. -
1087 Here's another way of removing an item while iterating: -
1088 -
1089 \snippet code/src_corelib_tools_qmap.cpp 21 -
1090 -
1091 It might be tempting to write code like this: -
1092 -
1093 \snippet code/src_corelib_tools_qmap.cpp 22 -
1094 -
1095 However, this will potentially crash in \c{++i}, because \c i is -
1096 a dangling iterator after the call to erase(). -
1097 -
1098 Multiple iterators can be used on the same map. If you add items -
1099 to the map, existing iterators will remain valid. If you remove -
1100 items from the map, iterators that point to the removed items -
1101 will become dangling iterators. -
1102 -
1103 \sa QMap::const_iterator, QMutableMapIterator -
1104*/ -
1105 -
1106/*! \typedef QMap::iterator::difference_type -
1107 -
1108 \internal -
1109*/ -
1110 -
1111/*! \typedef QMap::iterator::iterator_category -
1112 -
1113 A synonym for \e {std::bidirectional_iterator_tag} indicating -
1114 this iterator is a bidirectional iterator. -
1115*/ -
1116 -
1117/*! \typedef QMap::iterator::pointer -
1118 -
1119 \internal -
1120*/ -
1121 -
1122/*! \typedef QMap::iterator::reference -
1123 -
1124 \internal -
1125*/ -
1126 -
1127/*! \typedef QMap::iterator::value_type -
1128 -
1129 \internal -
1130*/ -
1131 -
1132/*! \fn QMap::iterator::iterator() -
1133 -
1134 Constructs an uninitialized iterator. -
1135 -
1136 Functions like key(), value(), and operator++() must not be -
1137 called on an uninitialized iterator. Use operator=() to assign a -
1138 value to it before using it. -
1139 -
1140 \sa QMap::begin(), QMap::end() -
1141*/ -
1142 -
1143/*! \fn QMap::iterator::iterator(Node *) -
1144 -
1145 \internal -
1146*/ -
1147 -
1148/*! \fn const Key &QMap::iterator::key() const -
1149 -
1150 Returns the current item's key as a const reference. -
1151 -
1152 There is no direct way of changing an item's key through an -
1153 iterator, although it can be done by calling QMap::erase() -
1154 followed by QMap::insert() or QMap::insertMulti(). -
1155 -
1156 \sa value() -
1157*/ -
1158 -
1159/*! \fn T &QMap::iterator::value() const -
1160 -
1161 Returns a modifiable reference to the current item's value. -
1162 -
1163 You can change the value of an item by using value() on -
1164 the left side of an assignment, for example: -
1165 -
1166 \snippet code/src_corelib_tools_qmap.cpp 23 -
1167 -
1168 \sa key(), operator*() -
1169*/ -
1170 -
1171/*! \fn T &QMap::iterator::operator*() const -
1172 -
1173 Returns a modifiable reference to the current item's value. -
1174 -
1175 Same as value(). -
1176 -
1177 \sa key() -
1178*/ -
1179 -
1180/*! \fn T *QMap::iterator::operator->() const -
1181 -
1182 Returns a pointer to the current item's value. -
1183 -
1184 \sa value() -
1185*/ -
1186 -
1187/*! -
1188 \fn bool QMap::iterator::operator==(const iterator &other) const -
1189 \fn bool QMap::iterator::operator==(const const_iterator &other) const -
1190 -
1191 Returns true if \a other points to the same item as this -
1192 iterator; otherwise returns false. -
1193 -
1194 \sa operator!=() -
1195*/ -
1196 -
1197/*! -
1198 \fn bool QMap::iterator::operator!=(const iterator &other) const -
1199 \fn bool QMap::iterator::operator!=(const const_iterator &other) const -
1200 -
1201 Returns true if \a other points to a different item than this -
1202 iterator; otherwise returns false. -
1203 -
1204 \sa operator==() -
1205*/ -
1206 -
1207/*! \fn QMap::iterator QMap::iterator::operator++() -
1208 -
1209 The prefix ++ operator (\c{++i}) advances the iterator to the -
1210 next item in the map and returns an iterator to the new current -
1211 item. -
1212 -
1213 Calling this function on QMap::end() leads to undefined results. -
1214 -
1215 \sa operator--() -
1216*/ -
1217 -
1218/*! \fn QMap::iterator QMap::iterator::operator++(int) -
1219 -
1220 \overload -
1221 -
1222 The postfix ++ operator (\c{i++}) advances the iterator to the -
1223 next item in the map and returns an iterator to the previously -
1224 current item. -
1225*/ -
1226 -
1227/*! \fn QMap::iterator QMap::iterator::operator--() -
1228 -
1229 The prefix -- operator (\c{--i}) makes the preceding item -
1230 current and returns an iterator pointing to the new current item. -
1231 -
1232 Calling this function on QMap::begin() leads to undefined -
1233 results. -
1234 -
1235 \sa operator++() -
1236*/ -
1237 -
1238/*! \fn QMap::iterator QMap::iterator::operator--(int) -
1239 -
1240 \overload -
1241 -
1242 The postfix -- operator (\c{i--}) makes the preceding item -
1243 current and returns an iterator pointing to the previously -
1244 current item. -
1245*/ -
1246 -
1247/*! \fn QMap::iterator QMap::iterator::operator+(int j) const -
1248 -
1249 Returns an iterator to the item at \a j positions forward from -
1250 this iterator. (If \a j is negative, the iterator goes backward.) -
1251 -
1252 This operation can be slow for large \a j values. -
1253 -
1254 \sa operator-() -
1255 -
1256*/ -
1257 -
1258/*! \fn QMap::iterator QMap::iterator::operator-(int j) const -
1259 -
1260 Returns an iterator to the item at \a j positions backward from -
1261 this iterator. (If \a j is negative, the iterator goes forward.) -
1262 -
1263 This operation can be slow for large \a j values. -
1264 -
1265 \sa operator+() -
1266*/ -
1267 -
1268/*! \fn QMap::iterator &QMap::iterator::operator+=(int j) -
1269 -
1270 Advances the iterator by \a j items. (If \a j is negative, the -
1271 iterator goes backward.) -
1272 -
1273 \sa operator-=(), operator+() -
1274*/ -
1275 -
1276/*! \fn QMap::iterator &QMap::iterator::operator-=(int j) -
1277 -
1278 Makes the iterator go back by \a j items. (If \a j is negative, -
1279 the iterator goes forward.) -
1280 -
1281 \sa operator+=(), operator-() -
1282*/ -
1283 -
1284/*! \class QMap::const_iterator -
1285 \inmodule QtCore -
1286 \brief The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap. -
1287 -
1288 QMap features both \l{STL-style iterators} and \l{Java-style -
1289 iterators}. The STL-style iterators are more low-level and more -
1290 cumbersome to use; on the other hand, they are slightly faster -
1291 and, for developers who already know STL, have the advantage of -
1292 familiarity. -
1293 -
1294 QMap\<Key, T\>::const_iterator allows you to iterate over a QMap -
1295 (or a QMultiMap). If you want to modify the QMap as you iterate -
1296 over it, you must use QMap::iterator instead. It is generally -
1297 good practice to use QMap::const_iterator on a non-const QMap as -
1298 well, unless you need to change the QMap through the iterator. -
1299 Const iterators are slightly faster, and can improve code -
1300 readability. -
1301 -
1302 The default QMap::const_iterator constructor creates an -
1303 uninitialized iterator. You must initialize it using a QMap -
1304 function like QMap::constBegin(), QMap::constEnd(), or -
1305 QMap::find() before you can start iterating. Here's a typical -
1306 loop that prints all the (key, value) pairs stored in a map: -
1307 -
1308 \snippet code/src_corelib_tools_qmap.cpp 24 -
1309 -
1310 Unlike QHash, which stores its items in an arbitrary order, QMap -
1311 stores its items ordered by key. Items that share the same key -
1312 (because they were inserted using QMap::insertMulti()) will -
1313 appear consecutively, from the most recently to the least -
1314 recently inserted value. -
1315 -
1316 Multiple iterators can be used on the same map. If you add items -
1317 to the map, existing iterators will remain valid. If you remove -
1318 items from the map, iterators that point to the removed items -
1319 will become dangling iterators. -
1320 -
1321 \sa QMap::iterator, QMapIterator -
1322*/ -
1323 -
1324/*! \typedef QMap::const_iterator::difference_type -
1325 -
1326 \internal -
1327*/ -
1328 -
1329/*! \typedef QMap::const_iterator::iterator_category -
1330 -
1331 A synonym for \e {std::bidirectional_iterator_tag} indicating -
1332 this iterator is a bidirectional iterator. -
1333*/ -
1334 -
1335/*! \typedef QMap::const_iterator::pointer -
1336 -
1337 \internal -
1338*/ -
1339 -
1340/*! \typedef QMap::const_iterator::reference -
1341 -
1342 \internal -
1343*/ -
1344 -
1345/*! \typedef QMap::const_iterator::value_type -
1346 -
1347 \internal -
1348*/ -
1349 -
1350/*! \fn QMap::const_iterator::const_iterator() -
1351 -
1352 Constructs an uninitialized iterator. -
1353 -
1354 Functions like key(), value(), and operator++() must not be -
1355 called on an uninitialized iterator. Use operator=() to assign a -
1356 value to it before using it. -
1357 -
1358 \sa QMap::constBegin(), QMap::constEnd() -
1359*/ -
1360 -
1361/*! \fn QMap::const_iterator::const_iterator(const Node *) -
1362 -
1363 \internal -
1364*/ -
1365 -
1366/*! \fn QMap::const_iterator::const_iterator(const iterator &other) -
1367 -
1368 Constructs a copy of \a other. -
1369*/ -
1370 -
1371/*! \fn const Key &QMap::const_iterator::key() const -
1372 -
1373 Returns the current item's key. -
1374 -
1375 \sa value() -
1376*/ -
1377 -
1378/*! \fn const T &QMap::const_iterator::value() const -
1379 -
1380 Returns the current item's value. -
1381 -
1382 \sa key(), operator*() -
1383*/ -
1384 -
1385/*! \fn const T &QMap::const_iterator::operator*() const -
1386 -
1387 Returns the current item's value. -
1388 -
1389 Same as value(). -
1390 -
1391 \sa key() -
1392*/ -
1393 -
1394/*! \fn const T *QMap::const_iterator::operator->() const -
1395 -
1396 Returns a pointer to the current item's value. -
1397 -
1398 \sa value() -
1399*/ -
1400 -
1401/*! \fn bool QMap::const_iterator::operator==(const const_iterator &other) const -
1402 -
1403 Returns true if \a other points to the same item as this -
1404 iterator; otherwise returns false. -
1405 -
1406 \sa operator!=() -
1407*/ -
1408 -
1409/*! \fn bool QMap::const_iterator::operator!=(const const_iterator &other) const -
1410 -
1411 Returns true if \a other points to a different item than this -
1412 iterator; otherwise returns false. -
1413 -
1414 \sa operator==() -
1415*/ -
1416 -
1417/*! \fn QMap::const_iterator QMap::const_iterator::operator++() -
1418 -
1419 The prefix ++ operator (\c{++i}) advances the iterator to the -
1420 next item in the map and returns an iterator to the new current -
1421 item. -
1422 -
1423 Calling this function on QMap::end() leads to undefined results. -
1424 -
1425 \sa operator--() -
1426*/ -
1427 -
1428/*! \fn QMap::const_iterator QMap::const_iterator::operator++(int) -
1429 -
1430 \overload -
1431 -
1432 The postfix ++ operator (\c{i++}) advances the iterator to the -
1433 next item in the map and returns an iterator to the previously -
1434 current item. -
1435*/ -
1436 -
1437/*! \fn QMap::const_iterator &QMap::const_iterator::operator--() -
1438 -
1439 The prefix -- operator (\c{--i}) makes the preceding item -
1440 current and returns an iterator pointing to the new current item. -
1441 -
1442 Calling this function on QMap::begin() leads to undefined -
1443 results. -
1444 -
1445 \sa operator++() -
1446*/ -
1447 -
1448/*! \fn QMap::const_iterator QMap::const_iterator::operator--(int) -
1449 -
1450 \overload -
1451 -
1452 The postfix -- operator (\c{i--}) makes the preceding item -
1453 current and returns an iterator pointing to the previously -
1454 current item. -
1455*/ -
1456 -
1457/*! \fn QMap::const_iterator QMap::const_iterator::operator+(int j) const -
1458 -
1459 Returns an iterator to the item at \a j positions forward from -
1460 this iterator. (If \a j is negative, the iterator goes backward.) -
1461 -
1462 This operation can be slow for large \a j values. -
1463 -
1464 \sa operator-() -
1465*/ -
1466 -
1467/*! \fn QMap::const_iterator QMap::const_iterator::operator-(int j) const -
1468 -
1469 Returns an iterator to the item at \a j positions backward from -
1470 this iterator. (If \a j is negative, the iterator goes forward.) -
1471 -
1472 This operation can be slow for large \a j values. -
1473 -
1474 \sa operator+() -
1475*/ -
1476 -
1477/*! \fn QMap::const_iterator &QMap::const_iterator::operator+=(int j) -
1478 -
1479 Advances the iterator by \a j items. (If \a j is negative, the -
1480 iterator goes backward.) -
1481 -
1482 This operation can be slow for large \a j values. -
1483 -
1484 \sa operator-=(), operator+() -
1485*/ -
1486 -
1487/*! \fn QMap::const_iterator &QMap::const_iterator::operator-=(int j) -
1488 -
1489 Makes the iterator go back by \a j items. (If \a j is negative, -
1490 the iterator goes forward.) -
1491 -
1492 This operation can be slow for large \a j values. -
1493 -
1494 \sa operator+=(), operator-() -
1495*/ -
1496 -
1497/*! \fn QDataStream &operator<<(QDataStream &out, const QMap<Key, T> &map) -
1498 \relates QMap -
1499 -
1500 Writes the map \a map to stream \a out. -
1501 -
1502 This function requires the key and value types to implement \c -
1503 operator<<(). -
1504 -
1505 \sa{Serializing Qt Data Types}{Format of the QDataStream operators} -
1506*/ -
1507 -
1508/*! \fn QDataStream &operator>>(QDataStream &in, QMap<Key, T> &map) -
1509 \relates QMap -
1510 -
1511 Reads a map from stream \a in into \a map. -
1512 -
1513 This function requires the key and value types to implement \c -
1514 operator>>(). -
1515 -
1516 \sa{Serializing Qt Data Types}{Format of the QDataStream operators} -
1517*/ -
1518 -
1519/*! \class QMultiMap -
1520 \inmodule QtCore -
1521 \brief The QMultiMap class is a convenience QMap subclass that provides multi-valued maps. -
1522 -
1523 \ingroup tools -
1524 \ingroup shared -
1525 -
1526 \reentrant -
1527 -
1528 QMultiMap\<Key, T\> is one of Qt's generic \l{container classes}. -
1529 It inherits QMap and extends it with a few convenience functions -
1530 that make it more suitable than QMap for storing multi-valued -
1531 maps. A multi-valued map is a map that allows multiple values -
1532 with the same key; QMap normally doesn't allow that, unless you -
1533 call QMap::insertMulti(). -
1534 -
1535 Because QMultiMap inherits QMap, all of QMap's functionality also -
1536 applies to QMultiMap. For example, you can use isEmpty() to test -
1537 whether the map is empty, and you can traverse a QMultiMap using -
1538 QMap's iterator classes (for example, QMapIterator). But in -
1539 addition, it provides an insert() function that corresponds to -
1540 QMap::insertMulti(), and a replace() function that corresponds to -
1541 QMap::insert(). It also provides convenient operator+() and -
1542 operator+=(). -
1543 -
1544 Example: -
1545 \snippet code/src_corelib_tools_qmap.cpp 25 -
1546 -
1547 Unlike QMap, QMultiMap provides no operator[]. Use value() or -
1548 replace() if you want to access the most recently inserted item -
1549 with a certain key. -
1550 -
1551 If you want to retrieve all the values for a single key, you can -
1552 use values(const Key &key), which returns a QList<T>: -
1553 -
1554 \snippet code/src_corelib_tools_qmap.cpp 26 -
1555 -
1556 The items that share the same key are available from most -
1557 recently to least recently inserted. -
1558 -
1559 If you prefer the STL-style iterators, you can call find() to get -
1560 the iterator for the first item with a key and iterate from -
1561 there: -
1562 -
1563 \snippet code/src_corelib_tools_qmap.cpp 27 -
1564 -
1565 QMultiMap's key and value data types must be \l{assignable data -
1566 types}. This covers most data types you are likely to encounter, -
1567 but the compiler won't let you, for example, store a QWidget as a -
1568 value; instead, store a QWidget *. In addition, QMultiMap's key type -
1569 must provide operator<(). See the QMap documentation for details. -
1570 -
1571 \sa QMap, QMapIterator, QMutableMapIterator, QMultiHash -
1572*/ -
1573 -
1574/*! \fn QMultiMap::QMultiMap() -
1575 -
1576 Constructs an empty map. -
1577*/ -
1578 -
1579/*! \fn QMultiMap::QMultiMap(const QMap<Key, T> &other) -
1580 -
1581 Constructs a copy of \a other (which can be a QMap or a -
1582 QMultiMap). -
1583 -
1584 \sa operator=() -
1585*/ -
1586 -
1587/*! \fn QMultiMap::iterator QMultiMap::replace(const Key &key, const T &value) -
1588 -
1589 Inserts a new item with the key \a key and a value of \a value. -
1590 -
1591 If there is already an item with the key \a key, that item's value -
1592 is replaced with \a value. -
1593 -
1594 If there are multiple items with the key \a key, the most -
1595 recently inserted item's value is replaced with \a value. -
1596 -
1597 \sa insert() -
1598*/ -
1599 -
1600/*! \fn QMultiMap::iterator QMultiMap::insert(const Key &key, const T &value) -
1601 -
1602 Inserts a new item with the key \a key and a value of \a value. -
1603 -
1604 If there is already an item with the same key in the map, this -
1605 function will simply create a new one. (This behavior is -
1606 different from replace(), which overwrites the value of an -
1607 existing item.) -
1608 -
1609 \sa replace() -
1610*/ -
1611 -
1612/*! \fn QMultiMap &QMultiMap::operator+=(const QMultiMap &other) -
1613 -
1614 Inserts all the items in the \a other map into this map and -
1615 returns a reference to this map. -
1616 -
1617 \sa insert(), operator+() -
1618*/ -
1619 -
1620/*! \fn QMultiMap QMultiMap::operator+(const QMultiMap &other) const -
1621 -
1622 Returns a map that contains all the items in this map in -
1623 addition to all the items in \a other. If a key is common to both -
1624 maps, the resulting map will contain the key multiple times. -
1625 -
1626 \sa operator+=() -
1627*/ -
1628 -
1629/*! -
1630 \fn bool QMultiMap::contains(const Key &key, const T &value) const -
1631 \since 4.3 -
1632 -
1633 Returns true if the map contains an item with key \a key and -
1634 value \a value; otherwise returns false. -
1635 -
1636 \sa QMap::contains() -
1637*/ -
1638 -
1639/*! -
1640 \fn bool QMultiMap::contains(const Key &key) const -
1641 \overload -
1642 \sa QMap::contains() -
1643*/ -
1644 -
1645/*! -
1646 \fn int QMultiMap::remove(const Key &key, const T &value) -
1647 \since 4.3 -
1648 -
1649 Removes all the items that have the key \a key and the value \a -
1650 value from the map. Returns the number of items removed. -
1651 -
1652 \sa QMap::remove() -
1653*/ -
1654 -
1655/*! -
1656 \fn int QMultiMap::remove(const Key &key) -
1657 \overload -
1658 \sa QMap::remove() -
1659*/ -
1660 -
1661/*! -
1662 \fn int QMultiMap::count(const Key &key, const T &value) const -
1663 \since 4.3 -
1664 -
1665 Returns the number of items with key \a key and value \a value. -
1666 -
1667 \sa QMap::count() -
1668*/ -
1669 -
1670/*! -
1671 \fn int QMultiMap::count(const Key &key) const -
1672 \overload -
1673 \sa QMap::count() -
1674*/ -
1675 -
1676/*! -
1677 \fn int QMultiMap::count() const -
1678 \overload -
1679 \sa QMap::count() -
1680*/ -
1681 -
1682/*! -
1683 \fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key, const T &value) -
1684 \since 4.3 -
1685 -
1686 Returns an iterator pointing to the item with key \a key and -
1687 value \a value in the map. -
1688 -
1689 If the map contains no such item, the function returns end(). -
1690 -
1691 If the map contains multiple items with key \a key, this -
1692 function returns an iterator that points to the most recently -
1693 inserted value. -
1694 -
1695 \sa QMap::find() -
1696*/ -
1697 -
1698/*! -
1699 \fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key) -
1700 \overload -
1701 \sa QMap::find() -
1702*/ -
1703 -
1704/*! -
1705 \fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key, const T &value) const -
1706 \since 4.3 -
1707 \overload -
1708 -
1709 Returns a const iterator pointing to the item with the given \a key and -
1710 \a value in the map. -
1711 -
1712 If the map contains no such item, the function returns end(). -
1713 -
1714 If the map contains multiple items with the specified \a key, this -
1715 function returns a const iterator that points to the most recently -
1716 inserted value. -
1717 -
1718 \sa QMap::find() -
1719*/ -
1720 -
1721/*! -
1722 \fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key) const -
1723 \since 4.3 -
1724 \overload -
1725 \sa QMap::find() -
1726*/ -
1727 -
1728/*! -
1729 \fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key, const T &value) const -
1730 \since 4.3 -
1731 -
1732 Returns an iterator pointing to the item with key \a key and the -
1733 value \a value in the map. -
1734 -
1735 If the map contains no such item, the function returns -
1736 constEnd(). -
1737 -
1738 \sa QMap::constFind() -
1739*/ -
1740 -
1741/*! -
1742 \fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key) const -
1743 \overload -
1744 \sa QMap::constFind() -
1745*/ -
1746 -
1747QT_END_NAMESPACE -
1748 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial