summaryrefslogtreecommitdiffstats
path: root/doc/html/qmap-h.html
blob: 6760d02b8835dfa67b94fe0c7abf7a9888e956c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/include/ntqmap.h:1 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ntqmap.h Include File</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>ntqmap.h</h1>

<p>This is the verbatim text of the ntqmap.h include file. It is provided only for illustration; the copyright remains with Trolltech.
<hr>
<pre>
/****************************************************************************
** $Id: qt/ntqmap.h   3.3.8   edited Jan 11 14:38 $
**
** Definition of TQMap class
**
** Created : 990406
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of the tools module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Alternatively you may (at your option) use any
** later version of the GNU General Public License if such license has
** been publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#ifndef TQMAP_H
#define TQMAP_H

#ifndef QT_H
#include "ntqglobal.h"
#include "ntqshared.h"
#include "ntqdatastream.h"
#include "ntqpair.h"
#include "ntqvaluelist.h"
#endif // QT_H

#ifndef TQT_NO_STL
#include &lt;iterator&gt;
#include &lt;map&gt;
#endif

//#define QT_CHECK_MAP_RANGE

struct Q_EXPORT TQMapNodeBase
{
    enum Color { Red, Black };

    TQMapNodeBase* left;
    TQMapNodeBase* right;
    TQMapNodeBase* parent;

    Color color;

    TQMapNodeBase* minimum() {
	TQMapNodeBase* x = this;
	while ( x-&gt;left )
	    x = x-&gt;left;
	return x;
    }

    TQMapNodeBase* maximum() {
	TQMapNodeBase* x = this;
	while ( x-&gt;right )
	    x = x-&gt;right;
	return x;
    }
};


template &lt;class K, class T&gt;
struct TQMapNode : public TQMapNodeBase
{
    TQMapNode( const K&amp; _key, const T&amp; _data ) { data = _data; key = _key; }
    TQMapNode( const K&amp; _key )	   { key = _key; }
    TQMapNode( const TQMapNode&lt;K,T&gt;&amp; _n ) { key = _n.key; data = _n.data; }
    TQMapNode() { }
    T data;
    K key;
};


template&lt;class K, class T&gt;
class TQMapIterator
{
 public:
    /**
     * Typedefs
     */
    typedef TQMapNode&lt; K, T &gt;* NodePtr;
#ifndef TQT_NO_STL
    typedef std::bidirectional_iterator_tag  iterator_category;
#endif
    typedef T          value_type;
#ifndef TQT_NO_STL
    typedef ptrdiff_t  difference_type;
#else
    typedef int difference_type;
#endif
    typedef T*         pointer;
    typedef T&amp;         reference;

    /**
     * Variables
     */
    TQMapNode&lt;K,T&gt;* node;

    /**
     * Functions
     */
    TQMapIterator() : node( 0 ) {}
    TQMapIterator( TQMapNode&lt;K,T&gt;* p ) : node( p ) {}
    TQMapIterator( const TQMapIterator&lt;K,T&gt;&amp; it ) : node( it.node ) {}

    bool operator==( const TQMapIterator&lt;K,T&gt;&amp; it ) const { return node == it.node; }
    bool operator!=( const TQMapIterator&lt;K,T&gt;&amp; it ) const { return node != it.node; }
    T&amp; operator*() { return node-&gt;data; }
    const T&amp; operator*() const { return node-&gt;data; }
    // UDT for T = x*
    // T* operator-&gt;() const { return &amp;node-&gt;data; }

    const K&amp; key() const { return node-&gt;key; }
    T&amp; data() { return node-&gt;data; }
    const T&amp; data() const { return node-&gt;data; }

private:
    int inc();
    int dec();

public:
    TQMapIterator&lt;K,T&gt;&amp; operator++() {
	inc();
	return *this;
    }

    TQMapIterator&lt;K,T&gt; operator++(int) {
	TQMapIterator&lt;K,T&gt; tmp = *this;
	inc();
	return tmp;
    }

    TQMapIterator&lt;K,T&gt;&amp; operator--() {
	dec();
	return *this;
    }

    TQMapIterator&lt;K,T&gt; operator--(int) {
	TQMapIterator&lt;K,T&gt; tmp = *this;
	dec();
	return tmp;
    }
};

template &lt;class K, class T&gt;
Q_INLINE_TEMPLATES int TQMapIterator&lt;K,T&gt;::inc()
{
    TQMapNodeBase* tmp = node;
    if ( tmp-&gt;right ) {
	tmp = tmp-&gt;right;
	while ( tmp-&gt;left )
	    tmp = tmp-&gt;left;
    } else {
	TQMapNodeBase* y = tmp-&gt;parent;
	while (tmp == y-&gt;right) {
	    tmp = y;
	    y = y-&gt;parent;
	}
	if (tmp-&gt;right != y)
	    tmp = y;
    }
    node = (NodePtr)tmp;
    return 0;
}

template &lt;class K, class T&gt;
Q_INLINE_TEMPLATES int TQMapIterator&lt;K,T&gt;::dec()
{
    TQMapNodeBase* tmp = node;
    if (tmp-&gt;color == TQMapNodeBase::Red &amp;&amp;
	tmp-&gt;parent-&gt;parent == tmp ) {
	tmp = tmp-&gt;right;
    } else if (tmp-&gt;left != 0) {
	TQMapNodeBase* y = tmp-&gt;left;
	while ( y-&gt;right )
	    y = y-&gt;right;
	tmp = y;
    } else {
	TQMapNodeBase* y = tmp-&gt;parent;
	while (tmp == y-&gt;left) {
	    tmp = y;
	    y = y-&gt;parent;
	}
	tmp = y;
    }
    node = (NodePtr)tmp;
    return 0;
}

template&lt;class K, class T&gt;
class TQMapConstIterator
{
 public:
    /**
     * Typedefs
     */
    typedef TQMapNode&lt; K, T &gt;* NodePtr;
#ifndef TQT_NO_STL
    typedef std::bidirectional_iterator_tag  iterator_category;
#endif
    typedef T          value_type;
#ifndef TQT_NO_STL
    typedef ptrdiff_t  difference_type;
#else
    typedef int difference_type;
#endif
    typedef const T*   pointer;
    typedef const T&amp;   reference;


    /**
     * Variables
     */
    TQMapNode&lt;K,T&gt;* node;

    /**
     * Functions
     */
    TQMapConstIterator() : node( 0 ) {}
    TQMapConstIterator( TQMapNode&lt;K,T&gt;* p ) : node( p ) {}
    TQMapConstIterator( const TQMapConstIterator&lt;K,T&gt;&amp; it ) : node( it.node ) {}
    TQMapConstIterator( const TQMapIterator&lt;K,T&gt;&amp; it ) : node( it.node ) {}

    bool operator==( const TQMapConstIterator&lt;K,T&gt;&amp; it ) const { return node == it.node; }
    bool operator!=( const TQMapConstIterator&lt;K,T&gt;&amp; it ) const { return node != it.node; }
    const T&amp; operator*()  const { return node-&gt;data; }
    // UDT for T = x*
    // const T* operator-&gt;() const { return &amp;node-&gt;data; }

    const K&amp; key() const { return node-&gt;key; }
    const T&amp; data() const { return node-&gt;data; }

private:
    int inc();
    int dec();

public:
    TQMapConstIterator&lt;K,T&gt;&amp; operator++() {
	inc();
	return *this;
    }

    TQMapConstIterator&lt;K,T&gt; operator++(int) {
	TQMapConstIterator&lt;K,T&gt; tmp = *this;
	inc();
	return tmp;
    }

    TQMapConstIterator&lt;K,T&gt;&amp; operator--() {
	dec();
	return *this;
    }

    TQMapConstIterator&lt;K,T&gt; operator--(int) {
	TQMapConstIterator&lt;K,T&gt; tmp = *this;
	dec();
	return tmp;
    }
};

template &lt;class K, class T&gt;
Q_INLINE_TEMPLATES int TQMapConstIterator&lt;K,T&gt;::inc()
{
    TQMapNodeBase* tmp = node;
    if ( tmp-&gt;right ) {
	tmp = tmp-&gt;right;
	while ( tmp-&gt;left )
	    tmp = tmp-&gt;left;
    } else {
	TQMapNodeBase* y = tmp-&gt;parent;
	while (tmp == y-&gt;right) {
	    tmp = y;
	    y = y-&gt;parent;
	}
	if (tmp-&gt;right != y)
	    tmp = y;
    }
    node = (NodePtr)tmp;
    return 0;
}

template &lt;class K, class T&gt;
Q_INLINE_TEMPLATES int TQMapConstIterator&lt;K,T&gt;::dec()
{
    TQMapNodeBase* tmp = node;
    if (tmp-&gt;color == TQMapNodeBase::Red &amp;&amp;
	tmp-&gt;parent-&gt;parent == tmp ) {
	tmp = tmp-&gt;right;
    } else if (tmp-&gt;left != 0) {
	TQMapNodeBase* y = tmp-&gt;left;
	while ( y-&gt;right )
	    y = y-&gt;right;
	tmp = y;
    } else {
	TQMapNodeBase* y = tmp-&gt;parent;
	while (tmp == y-&gt;left) {
	    tmp = y;
	    y = y-&gt;parent;
	}
	tmp = y;
    }
    node = (NodePtr)tmp;
    return 0;
}

// ### 4.0: rename to something without Private in it. Not really internal.
class Q_EXPORT TQMapPrivateBase : public TQShared
{
public:
    TQMapPrivateBase() {
	node_count = 0;
    }
    TQMapPrivateBase( const TQMapPrivateBase* _map) {
	node_count = _map-&gt;node_count;
    }

    /**
     * Implementations of basic tree algorithms
     */
    void rotateLeft( TQMapNodeBase* x, TQMapNodeBase*&amp; root);
    void rotateRight( TQMapNodeBase* x, TQMapNodeBase*&amp; root );
    void rebalance( TQMapNodeBase* x, TQMapNodeBase*&amp; root );
    TQMapNodeBase* removeAndRebalance( TQMapNodeBase* z, TQMapNodeBase*&amp; root,
				      TQMapNodeBase*&amp; leftmost,
				      TQMapNodeBase*&amp; rightmost );

    /**
     * Variables
     */
    int node_count;
};


template &lt;class Key, class T&gt;
class TQMapPrivate : public TQMapPrivateBase
{
public:
    /**
     * Typedefs
     */
    typedef TQMapIterator&lt; Key, T &gt; Iterator;
    typedef TQMapConstIterator&lt; Key, T &gt; ConstIterator;
    typedef TQMapNode&lt; Key, T &gt; Node;
    typedef TQMapNode&lt; Key, T &gt;* NodePtr;

    /**
     * Functions
     */
    TQMapPrivate();
    TQMapPrivate( const TQMapPrivate&lt; Key, T &gt;* _map );
    ~TQMapPrivate() { clear(); delete header; }

    NodePtr copy( NodePtr p );
    void clear();
    void clear( NodePtr p );

    Iterator begin()	{ return Iterator( (NodePtr)(header-&gt;left ) ); }
    Iterator end()	{ return Iterator( header ); }
    ConstIterator begin() const { return ConstIterator( (NodePtr)(header-&gt;left ) ); }
    ConstIterator end() const { return ConstIterator( header ); }

    ConstIterator find(const Key&amp; k) const;

    void remove( Iterator it ) {
	NodePtr del = (NodePtr) removeAndRebalance( it.node, header-&gt;parent, header-&gt;left, header-&gt;right );
	delete del;
	--node_count;
    }

#ifdef QT_QMAP_DEBUG
    void inorder( TQMapNodeBase* x = 0, int level = 0 ){
	if ( !x )
	    x = header-&gt;parent;
	if ( x-&gt;left )
	    inorder( x-&gt;left, level + 1 );
    //cout &lt;&lt; level &lt;&lt; " Key=" &lt;&lt; key(x) &lt;&lt; " Value=" &lt;&lt; ((NodePtr)x)-&gt;data &lt;&lt; endl;
	if ( x-&gt;right )
	    inorder( x-&gt;right, level + 1 );
    }
#endif

#if 0
    Iterator insertMulti(const Key&amp; v){
	TQMapNodeBase* y = header;
	TQMapNodeBase* x = header-&gt;parent;
	while (x != 0){
	    y = x;
	    x = ( v &lt; key(x) ) ? x-&gt;left : x-&gt;right;
	}
	return insert(x, y, v);
    }
#endif

    Iterator insertSingle( const Key&amp; k );
    Iterator insert( TQMapNodeBase* x, TQMapNodeBase* y, const Key&amp; k );

protected:
    /**
     * Helpers
     */
    const Key&amp; key( TQMapNodeBase* b ) const { return ((NodePtr)b)-&gt;key; }

    /**
     * Variables
     */
    NodePtr header;
};


template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES TQMapPrivate&lt;Key,T&gt;::TQMapPrivate() {
    header = new Node;
    header-&gt;color = TQMapNodeBase::Red; // Mark the header
    header-&gt;parent = 0;
    header-&gt;left = header-&gt;right = header;
}
template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES TQMapPrivate&lt;Key,T&gt;::TQMapPrivate( const TQMapPrivate&lt; Key, T &gt;* _map ) : TQMapPrivateBase( _map ) {
    header = new Node;
    header-&gt;color = TQMapNodeBase::Red; // Mark the header
    if ( _map-&gt;header-&gt;parent == 0 ) {
	header-&gt;parent = 0;
	header-&gt;left = header-&gt;right = header;
    } else {
	header-&gt;parent = copy( (NodePtr)(_map-&gt;header-&gt;parent) );
	header-&gt;parent-&gt;parent = header;
	header-&gt;left = header-&gt;parent-&gt;minimum();
	header-&gt;right = header-&gt;parent-&gt;maximum();
    }
}

template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::NodePtr TQMapPrivate&lt;Key,T&gt;::copy( Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::NodePtr p )
{
    if ( !p )
	return 0;
    NodePtr n = new Node( *p );
    n-&gt;color = p-&gt;color;
    if ( p-&gt;left ) {
	n-&gt;left = copy( (NodePtr)(p-&gt;left) );
	n-&gt;left-&gt;parent = n;
    } else {
	n-&gt;left = 0;
    }
    if ( p-&gt;right ) {
	n-&gt;right = copy( (NodePtr)(p-&gt;right) );
	n-&gt;right-&gt;parent = n;
    } else {
	n-&gt;right = 0;
    }
    return n;
}

template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMapPrivate&lt;Key,T&gt;::clear()
{
    clear( (NodePtr)(header-&gt;parent) );
    header-&gt;color = TQMapNodeBase::Red;
    header-&gt;parent = 0;
    header-&gt;left = header-&gt;right = header;
    node_count = 0;
}

template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMapPrivate&lt;Key,T&gt;::clear( Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::NodePtr p )
{
    while ( p != 0 ) {
	clear( (NodePtr)p-&gt;right );
	NodePtr y = (NodePtr)p-&gt;left;
	delete p;
	p = y;
    }
}

template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::ConstIterator TQMapPrivate&lt;Key,T&gt;::find(const Key&amp; k) const
{
    TQMapNodeBase* y = header;        // Last node
    TQMapNodeBase* x = header-&gt;parent; // Root node.

    while ( x != 0 ) {
	// If as k &lt;= key(x) go left
	if ( !( key(x) &lt; k ) ) {
	    y = x;
	    x = x-&gt;left;
	} else {
	    x = x-&gt;right;
	}
    }

    // Was k bigger/smaller then the biggest/smallest
    // element of the tree ? Return end()
    if ( y == header || k &lt; key(y) )
	return ConstIterator( header );
    return ConstIterator( (NodePtr)y );
}

template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::Iterator TQMapPrivate&lt;Key,T&gt;::insertSingle( const Key&amp; k )
{
    // Search correct position in the tree
    TQMapNodeBase* y = header;
    TQMapNodeBase* x = header-&gt;parent;
    bool result = TRUE;
    while ( x != 0 ) {
	result = ( k &lt; key(x) );
	y = x;
	x = result ? x-&gt;left : x-&gt;right;
    }
    // Get iterator on the last not empty one
    Iterator j( (NodePtr)y );
    if ( result ) {
	// Smaller then the leftmost one ?
	if ( j == begin() ) {
	    return insert(x, y, k );
	} else {
	    // Perhaps daddy is the right one ?
	    --j;
	}
    }
    // Really bigger ?
    if ( (j.node-&gt;key) &lt; k )
	return insert(x, y, k );
    // We are going to replace a node
    return j;
}


template &lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMapPrivate&lt;Key,T&gt;::Iterator TQMapPrivate&lt;Key,T&gt;::insert( TQMapNodeBase* x, TQMapNodeBase* y, const Key&amp; k )
{
    NodePtr z = new Node( k );
    if (y == header || x != 0 || k &lt; key(y) ) {
	y-&gt;left = z;                // also makes leftmost = z when y == header
	if ( y == header ) {
	    header-&gt;parent = z;
	    header-&gt;right = z;
	} else if ( y == header-&gt;left )
	    header-&gt;left = z;           // maintain leftmost pointing to min node
    } else {
	y-&gt;right = z;
	if ( y == header-&gt;right )
	    header-&gt;right = z;          // maintain rightmost pointing to max node
    }
    z-&gt;parent = y;
    z-&gt;left = 0;
    z-&gt;right = 0;
    rebalance( z, header-&gt;parent );
    ++node_count;
    return Iterator(z);
}


#ifdef QT_CHECK_RANGE
# if !defined( QT_NO_DEBUG ) &amp;&amp; defined( QT_CHECK_MAP_RANGE )
#  define QT_CHECK_INVALID_MAP_ELEMENT if ( empty() ) tqWarning( "TQMap: Warning invalid element" )
#  define QT_CHECK_INVALID_MAP_ELEMENT_FATAL Q_ASSERT( !empty() );
# else
#  define QT_CHECK_INVALID_MAP_ELEMENT
#  define QT_CHECK_INVALID_MAP_ELEMENT_FATAL
# endif
#else
# define QT_CHECK_INVALID_MAP_ELEMENT
# define QT_CHECK_INVALID_MAP_ELEMENT_FATAL
#endif

template &lt;class T&gt; class TQDeepCopy;

template&lt;class Key, class T&gt;
class TQMap
{
public:
    /**
     * Typedefs
     */
    typedef Key key_type;
    typedef T mapped_type;
    typedef TQPair&lt;const key_type, mapped_type&gt; value_type;
    typedef value_type* pointer;
    typedef const value_type* const_pointer;
    typedef value_type&amp; reference;
    typedef const value_type&amp; const_reference;
#ifndef TQT_NO_STL
    typedef ptrdiff_t  difference_type;
#else
    typedef int difference_type;
#endif
    typedef size_t      size_type;
    typedef TQMapIterator&lt;Key,T&gt; iterator;
    typedef TQMapConstIterator&lt;Key,T&gt; const_iterator;
    typedef TQPair&lt;iterator,bool&gt; insert_pair;

    typedef TQMapIterator&lt; Key, T &gt; Iterator;
    typedef TQMapConstIterator&lt; Key, T &gt; ConstIterator;
    typedef T ValueType;
    typedef TQMapPrivate&lt; Key, T &gt; Priv;

    /**
     * API
     */
    TQMap()
    {
	sh = new TQMapPrivate&lt; Key, T &gt;;
    }
    TQMap( const TQMap&lt;Key,T&gt;&amp; m )
    {
	sh = m.sh; sh-&gt;ref();
    }

#ifndef TQT_NO_STL
    TQMap( const std::map&lt;Key,T&gt;&amp; m )
    {
	sh = new TQMapPrivate&lt;Key,T&gt;;
	Q_TYPENAME std::map&lt;Key,T&gt;::const_iterator it = m.begin();
	for ( ; it != m.end(); ++it ) {
	    value_type p( (*it).first, (*it).second );
	    insert( p );
	}
    }
#endif
    ~TQMap()
    {
	if ( sh-&gt;deref() )
	    delete sh;
    }
    TQMap&lt;Key,T&gt;&amp; operator= ( const TQMap&lt;Key,T&gt;&amp; m );
#ifndef TQT_NO_STL
    TQMap&lt;Key,T&gt;&amp; operator= ( const std::map&lt;Key,T&gt;&amp; m )
    {
	clear();
	Q_TYPENAME std::map&lt;Key,T&gt;::const_iterator it = m.begin();
	for ( ; it != m.end(); ++it ) {
	    value_type p( (*it).first, (*it).second );
	    insert( p );
	}
	return *this;
    }
#endif

    iterator begin() { detach(); return sh-&gt;begin(); }
    iterator end() { detach(); return sh-&gt;end(); }
    const_iterator begin() const { return ((const Priv*)sh)-&gt;begin(); }
    const_iterator end() const { return ((const Priv*)sh)-&gt;end(); }
    const_iterator constBegin() const { return begin(); }
    const_iterator constEnd() const { return end(); }

    iterator replace( const Key&amp; k, const T&amp; v )
    {
	remove( k );
	return insert( k, v );
    }

    size_type size() const
    {
	return sh-&gt;node_count;
    }
    bool empty() const
    {
	return sh-&gt;node_count == 0;
    }
    TQPair&lt;iterator,bool&gt; insert( const value_type&amp; x );

    void erase( iterator it )
    {
	detach();
	sh-&gt;remove( it );
    }
    void erase( const key_type&amp; k );
    size_type count( const key_type&amp; k ) const;
    T&amp; operator[] ( const Key&amp; k );
    void clear();

    iterator find ( const Key&amp; k )
    {
	detach();
	return iterator( sh-&gt;find( k ).node );
    }
    const_iterator find ( const Key&amp; k ) const {	return sh-&gt;find( k ); }

    const T&amp; operator[] ( const Key&amp; k ) const
	{ QT_CHECK_INVALID_MAP_ELEMENT; return sh-&gt;find( k ).data(); }
    bool contains ( const Key&amp; k ) const
	{ return find( k ) != end(); }
	//{ return sh-&gt;find( k ) != ((const Priv*)sh)-&gt;end(); }

    size_type count() const { return sh-&gt;node_count; }

    TQValueList&lt;Key&gt; keys() const {
	TQValueList&lt;Key&gt; r;
	for (const_iterator i=begin(); i!=end(); ++i)
	    r.append(i.key());
	return r;
    }

    TQValueList&lt;T&gt; values() const {
	TQValueList&lt;T&gt; r;
	for (const_iterator i=begin(); i!=end(); ++i)
	    r.append(*i);
	return r;
    }

    bool isEmpty() const { return sh-&gt;node_count == 0; }

    iterator insert( const Key&amp; key, const T&amp; value, bool overwrite = TRUE );
    void remove( iterator it ) { detach(); sh-&gt;remove( it ); }
    void remove( const Key&amp; k );

#if defined(Q_FULL_TEMPLATE_INSTANTIATION)
    bool operator==( const TQMap&lt;Key,T&gt;&amp; ) const { return FALSE; }
#ifndef TQT_NO_STL
    bool operator==( const std::map&lt;Key,T&gt;&amp; ) const { return FALSE; }
#endif
#endif

protected:
    /**
     * Helpers
     */
    void detach() {  if ( sh-&gt;count &gt; 1 ) detachInternal(); }

    Priv* sh;
private:
    void detachInternal();

    friend class TQDeepCopy&lt; TQMap&lt;Key,T&gt; &gt;;
};

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES TQMap&lt;Key,T&gt;&amp; TQMap&lt;Key,T&gt;::operator= ( const TQMap&lt;Key,T&gt;&amp; m )
{
    m.sh-&gt;ref();
    if ( sh-&gt;deref() )
	delete sh;
    sh = m.sh;
    return *this;
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMap&lt;Key,T&gt;::insert_pair TQMap&lt;Key,T&gt;::insert( const Q_TYPENAME TQMap&lt;Key,T&gt;::value_type&amp; x )
{
    detach();
    size_type n = size();
    iterator it = sh-&gt;insertSingle( x.first );
    bool inserted = FALSE;
    if ( n &lt; size() ) {
	inserted = TRUE;
	it.data() = x.second;
    }
    return TQPair&lt;iterator,bool&gt;( it, inserted );
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMap&lt;Key,T&gt;::erase( const Key&amp; k )
{
    detach();
    iterator it( sh-&gt;find( k ).node );
    if ( it != end() )
	sh-&gt;remove( it );
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMap&lt;Key,T&gt;::size_type TQMap&lt;Key,T&gt;::count( const Key&amp; k ) const
{
    const_iterator it( sh-&gt;find( k ).node );
    if ( it != end() ) {
	size_type c = 0;
	while ( it != end() ) {
	    ++it;
	    ++c;
	}
	return c;
    }
    return 0;
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES T&amp; TQMap&lt;Key,T&gt;::operator[] ( const Key&amp; k )
{
    detach();
    TQMapNode&lt;Key,T&gt;* p = sh-&gt;find( k ).node;
    if ( p != sh-&gt;end().node )
	return p-&gt;data;
    return insert( k, T() ).data();
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMap&lt;Key,T&gt;::clear()
{
    if ( sh-&gt;count == 1 )
	sh-&gt;clear();
    else {
	sh-&gt;deref();
	sh = new TQMapPrivate&lt;Key,T&gt;;
    }
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES Q_TYPENAME TQMap&lt;Key,T&gt;::iterator TQMap&lt;Key,T&gt;::insert( const Key&amp; key, const T&amp; value, bool overwrite )
{
    detach();
    size_type n = size();
    iterator it = sh-&gt;insertSingle( key );
    if ( overwrite || n &lt; size() )
	it.data() = value;
    return it;
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMap&lt;Key,T&gt;::remove( const Key&amp; k )
{
    detach();
    iterator it( sh-&gt;find( k ).node );
    if ( it != end() )
	sh-&gt;remove( it );
}

template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES void TQMap&lt;Key,T&gt;::detachInternal()
{
    sh-&gt;deref(); sh = new TQMapPrivate&lt;Key,T&gt;( sh );
}


#ifndef QT_NO_DATASTREAM
template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES TQDataStream&amp; operator&gt;&gt;( TQDataStream&amp; s, TQMap&lt;Key,T&gt;&amp; m ) {
    m.clear();
    TQ_UINT32 c;
    s &gt;&gt; c;
    for( TQ_UINT32 i = 0; i &lt; c; ++i ) {
	Key k; T t;
	s &gt;&gt; k &gt;&gt; t;
	m.insert( k, t );
	if ( s.atEnd() )
	    break;
    }
    return s;
}


template&lt;class Key, class T&gt;
Q_INLINE_TEMPLATES TQDataStream&amp; operator&lt;&lt;( TQDataStream&amp; s, const TQMap&lt;Key,T&gt;&amp; m ) {
    s &lt;&lt; (TQ_UINT32)m.size();
    TQMapConstIterator&lt;Key,T&gt; it = m.begin();
    for( ; it != m.end(); ++it )
	s &lt;&lt; it.key() &lt;&lt; it.data();
    return s;
}
#endif

#define Q_DEFINED_QMAP
#include "ntqwinexport.h"
#endif // TQMAP_H
</pre>
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>