summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqintdict.3qt
blob: d38f85605c4049d706dd39c830faabc986bfa3a3 (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
'\" t
.TH TQIntDict 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQIntDict \- Template class that provides a dictionary based on long keys
.SH SYNOPSIS
\fC#include <tqintdict.h>\fR
.PP
Inherits TQPtrCollection.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQIntDict\fR ( int size = 17 )"
.br
.ti -1c
.BI "\fBTQIntDict\fR ( const TQIntDict<type> & dict )"
.br
.ti -1c
.BI "\fB~TQIntDict\fR ()"
.br
.ti -1c
.BI "TQIntDict<type> & \fBoperator=\fR ( const TQIntDict<type> & dict )"
.br
.ti -1c
.BI "virtual uint \fBcount\fR () const"
.br
.ti -1c
.BI "uint \fBsize\fR () const"
.br
.ti -1c
.BI "bool \fBisEmpty\fR () const"
.br
.ti -1c
.BI "void \fBinsert\fR ( long key, const type * item )"
.br
.ti -1c
.BI "void \fBreplace\fR ( long key, const type * item )"
.br
.ti -1c
.BI "bool \fBremove\fR ( long key )"
.br
.ti -1c
.BI "type * \fBtake\fR ( long key )"
.br
.ti -1c
.BI "type * \fBfind\fR ( long key ) const"
.br
.ti -1c
.BI "type * \fBoperator[]\fR ( long key ) const"
.br
.ti -1c
.BI "virtual void \fBclear\fR ()"
.br
.ti -1c
.BI "void \fBresize\fR ( uint newsize )"
.br
.ti -1c
.BI "void \fBstatistics\fR () const"
.br
.in -1c
.SS "Important Inherited Members"
.in +1c
.ti -1c
.BI "bool \fBautoDelete\fR () const"
.br
.ti -1c
.BI "void \fBsetAutoDelete\fR ( bool enable )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual TQDataStream & \fBread\fR ( TQDataStream & s, TQPtrCollection::Item & item )"
.br
.ti -1c
.BI "virtual TQDataStream & \fBwrite\fR ( TQDataStream & s, TQPtrCollection::Item ) const"
.br
.in -1c
.SH DESCRIPTION
The TQIntDict class is a template class that provides a dictionary based on long keys.
.PP
TQMap is an STL-compatible alternative to this class.
.PP
TQIntDict is implemented as a template class. Define a template instance TQIntDict<X> to create a dictionary that operates on pointers to X (X*).
.PP
A dictionary is a collection of key-value pairs. The key is an \fClong\fR used for insertion, removal and lookup. The value is a pointer. Dictionaries provide very fast insertion and lookup.
.PP
Example:
.PP
.nf
.br
    TQIntDict<TQLineEdit> fields; // long int keys, TQLineEdit* values
.br
    for ( int i = 0; i < 3; i++ )
.br
        fields.insert( i, new TQLineEdit( this ) );
.br
.br
    fields[0]->setText( "Homer" );
.br
    fields[1]->setText( "Simpson" );
.br
    fields[2]->setText( "45" );
.br
.br
    TQIntDictIterator<TQLineEdit> it( fields );
.br
    for ( ; it.current(); ++it )
.br
        cout << it.currentKey() << ": " << it.current()->text() << endl;
.br
.br
    for ( int i = 0; i < 3; i++ )
.br
        cout << fields[i]->text() << " "; // Prints "Homer Simpson 45"
.br
    cout << endl;
.br
.br
    fields.remove( 1 ); // Does not delete the line edit
.br
    for ( int i = 0; i < 3; i++ )
.br
        if ( fields[i] )
.br
            cout << fields[i]->text() << " "; // Prints "Homer 45"
.br
.fi
.PP
See TQDict for full details, including the choice of dictionary size, and how deletions are handled.
.PP
See also TQIntDictIterator, TQDict, TQAsciiDict, TQPtrDict, Collection Classes, Collection Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQIntDict::TQIntDict ( int size = 17 )"
Constructs a dictionary using an internal hash array of size \fIsize\fR.
.PP
Setting \fIsize\fR to a suitably large prime number (equal to or greater than the expected number of entries) makes the hash distribution better which leads to faster lookup.
.SH "TQIntDict::TQIntDict ( const TQIntDict<type> & dict )"
Constructs a copy of \fIdict\fR.
.PP
Each item in \fIdict\fR is inserted into this dictionary. Only the pointers are copied (shallow copy).
.SH "TQIntDict::~TQIntDict ()"
Removes all items from the dictionary and destroys it.
.PP
All iterators that access this dictionary will be reset.
.PP
See also setAutoDelete().
.SH "bool TQPtrCollection::autoDelete () const"
Returns the setting of the auto-delete option. The default is FALSE.
.PP
See also setAutoDelete().
.SH "void TQIntDict::clear ()\fC [virtual]\fR"
Removes all items from the dictionary.
.PP
The removed items are deleted if auto-deletion is enabled.
.PP
All dictionary iterators that access this dictionary will be reset.
.PP
See also remove(), take(), and setAutoDelete().
.PP
Reimplemented from TQPtrCollection.
.SH "uint TQIntDict::count () const\fC [virtual]\fR"
Returns the number of items in the dictionary.
.PP
See also isEmpty().
.PP
Reimplemented from TQPtrCollection.
.SH "type * TQIntDict::find ( long key ) const"
Returns the item associated with \fIkey\fR, or 0 if the key does not exist in the dictionary.
.PP
If there are two or more items with equal keys, then the most recently inserted item will be found.
.PP
Equivalent to operator[].
.PP
See also operator[]().
.PP
Example: table/bigtable/main.cpp.
.SH "void TQIntDict::insert ( long key, const type * item )"
Insert item \fIitem\fR into the dictionary using key \fIkey\fR.
.PP
Multiple items can have the same key, in which case only the last item will be accessible using operator[]().
.PP
\fIitem\fR may not be 0.
.PP
See also replace().
.PP
Example: scribble/scribble.cpp.
.SH "bool TQIntDict::isEmpty () const"
Returns TRUE if the dictionary is empty; otherwise returns FALSE.
.PP
See also count().
.SH "TQIntDict<type> & TQIntDict::operator= ( const TQIntDict<type> & dict )"
Assigns \fIdict\fR to this dictionary and returns a reference to this dictionary.
.PP
This dictionary is first cleared and then each item in \fIdict\fR is inserted into this dictionary. Only the pointers are copied (shallow copy), unless newItem() has been reimplemented.
.SH "type * TQIntDict::operator[] ( long key ) const"
Returns the item associated with \fIkey\fR, or 0 if the key does not exist in the dictionary.
.PP
If there are two or more items with equal keys, then the most recently inserted item will be found.
.PP
Equivalent to the find() function.
.PP
See also find().
.SH "TQDataStream & TQIntDict::read ( TQDataStream & s, TQPtrCollection::Item & item )\fC [virtual protected]\fR"
Reads a dictionary item from the stream \fIs\fR and returns a reference to the stream.
.PP
The default implementation sets \fIitem\fR to 0.
.PP
See also write().
.SH "bool TQIntDict::remove ( long key )"
Removes the item associated with \fIkey\fR from the dictionary. Returns TRUE if successful, i.e. if the \fIkey\fR is in the dictionary; otherwise returns FALSE.
.PP
If there are two or more items with equal keys, then the most recently inserted item will be removed.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
All dictionary iterators that refer to the removed item will be set to point to the next item in the dictionary's traversal order.
.PP
See also take(), clear(), and setAutoDelete().
.PP
Example: table/bigtable/main.cpp.
.SH "void TQIntDict::replace ( long key, const type * item )"
If the dictionary has key \fIkey\fR, this key's item is replaced with \fIitem\fR. If the dictionary doesn't contain key \fIkey\fR, \fIitem\fR is inserted into the dictionary using key \fIkey\fR.
.PP
\fIitem\fR may not be 0.
.PP
Equivalent to:
.PP
.nf
.br
        TQIntDict<char> dict;
.br
        //      ...
.br
        if ( dict.find(key) )
.br
            dict.remove( key );
.br
        dict.insert( key, item );
.br
.fi
.PP
If there are two or more items with equal keys, then the most recently inserted item will be replaced.
.PP
See also insert().
.PP
Example: table/bigtable/main.cpp.
.SH "void TQIntDict::resize ( uint newsize )"
Changes the size of the hashtable to \fInewsize\fR. The contents of the dictionary are preserved, but all iterators on the dictionary become invalid.
.SH "void TQPtrCollection::setAutoDelete ( bool enable )"
Sets the collection to auto-delete its contents if \fIenable\fR is TRUE and to never delete them if \fIenable\fR is FALSE.
.PP
If auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items.
.PP
The default setting is FALSE, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items.
.PP
Note that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item.
.PP
See also autoDelete().
.PP
Examples:
.)l grapher/grapher.cpp, scribble/scribble.cpp, and table/bigtable/main.cpp.
.SH "uint TQIntDict::size () const"
Returns the size of the internal hash array (as specified in the constructor).
.PP
See also count().
.SH "void TQIntDict::statistics () const"
Debugging-only function that prints out the dictionary distribution using tqDebug().
.SH "type * TQIntDict::take ( long key )"
Takes the item associated with \fIkey\fR out of the dictionary without deleting it (even if auto-deletion is enabled).
.PP
If there are two or more items with equal keys, then the most recently inserted item will be taken.
.PP
Returns a pointer to the item taken out, or 0 if the key does not exist in the dictionary.
.PP
All dictionary iterators that refer to the taken item will be set to point to the next item in the dictionary's traversing order.
.PP
See also remove(), clear(), and setAutoDelete().
.PP
Example: table/bigtable/main.cpp.
.SH "TQDataStream & TQIntDict::write ( TQDataStream & s, TQPtrCollection::Item ) const\fC [virtual protected]\fR"
Writes a dictionary item to the stream \fIs\fR and returns a reference to the stream.
.PP
See also read().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqintdict.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqintdict.3qt) and the Qt
version (3.3.8).