1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \class Q3IntDict
|
---|
30 | \brief The Q3IntDict class is a template class that provides a dictionary based on long keys.\
|
---|
31 | \compat
|
---|
32 |
|
---|
33 | Q3IntDict is implemented as a template class. Define a template
|
---|
34 | instance Q3IntDict\<X\> to create a dictionary that operates on
|
---|
35 | pointers to X (X*).
|
---|
36 |
|
---|
37 | A dictionary is a collection of key-value pairs. The key is an \c
|
---|
38 | long used for insertion, removal and lookup. The value is a
|
---|
39 | pointer. Dictionaries provide very fast insertion and lookup.
|
---|
40 |
|
---|
41 | Example:
|
---|
42 | \snippet doc/src/snippets/code/doc_src_q3intdict.qdoc 0
|
---|
43 |
|
---|
44 | See Q3Dict for full details, including the choice of dictionary
|
---|
45 | size, and how deletions are handled.
|
---|
46 |
|
---|
47 | \sa Q3IntDictIterator, Q3Dict, Q3AsciiDict, Q3PtrDict
|
---|
48 | */
|
---|
49 |
|
---|
50 |
|
---|
51 | /*!
|
---|
52 | \fn Q3IntDict::Q3IntDict( int size )
|
---|
53 |
|
---|
54 | Constructs a dictionary using an internal hash array of size \a
|
---|
55 | size.
|
---|
56 |
|
---|
57 | Setting \a size to a suitably large prime number (equal to or
|
---|
58 | greater than the expected number of entries) makes the hash
|
---|
59 | distribution better which leads to faster lookup.
|
---|
60 | */
|
---|
61 |
|
---|
62 | /*!
|
---|
63 | \fn Q3IntDict::Q3IntDict( const Q3IntDict<type> &dict )
|
---|
64 |
|
---|
65 | Constructs a copy of \a dict.
|
---|
66 |
|
---|
67 | Each item in \a dict is inserted into this dictionary. Only the
|
---|
68 | pointers are copied (shallow copy).
|
---|
69 | */
|
---|
70 |
|
---|
71 | /*!
|
---|
72 | \fn Q3IntDict::~Q3IntDict()
|
---|
73 |
|
---|
74 | Removes all items from the dictionary and destroys it.
|
---|
75 |
|
---|
76 | All iterators that access this dictionary will be reset.
|
---|
77 |
|
---|
78 | \sa setAutoDelete()
|
---|
79 | */
|
---|
80 |
|
---|
81 | /*!
|
---|
82 | \fn Q3IntDict<type> &Q3IntDict::operator=(const Q3IntDict<type> &dict)
|
---|
83 |
|
---|
84 | Assigns \a dict to this dictionary and returns a reference to this
|
---|
85 | dictionary.
|
---|
86 |
|
---|
87 | This dictionary is first cleared and then each item in \a dict is
|
---|
88 | inserted into this dictionary. Only the pointers are copied
|
---|
89 | (shallow copy), unless newItem() has been reimplemented.
|
---|
90 | */
|
---|
91 |
|
---|
92 | /*!
|
---|
93 | \fn uint Q3IntDict::count() const
|
---|
94 |
|
---|
95 | Returns the number of items in the dictionary.
|
---|
96 |
|
---|
97 | \sa isEmpty()
|
---|
98 | */
|
---|
99 |
|
---|
100 | /*!
|
---|
101 | \fn uint Q3IntDict::size() const
|
---|
102 |
|
---|
103 | Returns the size of the internal hash array (as specified in the
|
---|
104 | constructor).
|
---|
105 |
|
---|
106 | \sa count()
|
---|
107 | */
|
---|
108 |
|
---|
109 | /*!
|
---|
110 | \fn void Q3IntDict::resize( uint newsize )
|
---|
111 |
|
---|
112 | Changes the size of the hashtable to \a newsize. The contents of
|
---|
113 | the dictionary are preserved, but all iterators on the dictionary
|
---|
114 | become invalid.
|
---|
115 | */
|
---|
116 |
|
---|
117 | /*!
|
---|
118 | \fn bool Q3IntDict::isEmpty() const
|
---|
119 |
|
---|
120 | Returns TRUE if the dictionary is empty; otherwise returns FALSE.
|
---|
121 |
|
---|
122 | \sa count()
|
---|
123 | */
|
---|
124 |
|
---|
125 | /*!
|
---|
126 | \fn void Q3IntDict::insert( long key, const type *item )
|
---|
127 |
|
---|
128 | Insert item \a item into the dictionary using key \a key.
|
---|
129 |
|
---|
130 | Multiple items can have the same key, in which case only the last
|
---|
131 | item will be accessible using \l operator[]().
|
---|
132 |
|
---|
133 | \a item may not be 0.
|
---|
134 |
|
---|
135 | \sa replace()
|
---|
136 | */
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | \fn void Q3IntDict::replace( long key, const type *item )
|
---|
140 |
|
---|
141 | If the dictionary has key \a key, this key's item is replaced with
|
---|
142 | \a item. If the dictionary doesn't contain key \a key, \a item is
|
---|
143 | inserted into the dictionary using key \a key.
|
---|
144 |
|
---|
145 | \a item may not be 0.
|
---|
146 |
|
---|
147 | Equivalent to:
|
---|
148 | \snippet doc/src/snippets/code/doc_src_q3intdict.qdoc 1
|
---|
149 |
|
---|
150 | If there are two or more items with equal keys, then the most
|
---|
151 | recently inserted item will be replaced.
|
---|
152 |
|
---|
153 | \sa insert()
|
---|
154 | */
|
---|
155 |
|
---|
156 | /*!
|
---|
157 | \fn bool Q3IntDict::remove( long key )
|
---|
158 |
|
---|
159 | Removes the item associated with \a key from the dictionary.
|
---|
160 | Returns TRUE if successful, i.e. if the \a key is in the
|
---|
161 | dictionary; otherwise returns FALSE.
|
---|
162 |
|
---|
163 | If there are two or more items with equal keys, then the most
|
---|
164 | recently inserted item will be removed.
|
---|
165 |
|
---|
166 | The removed item is deleted if \link
|
---|
167 | Q3PtrCollection::setAutoDelete() auto-deletion\endlink is enabled.
|
---|
168 |
|
---|
169 | All dictionary iterators that refer to the removed item will be
|
---|
170 | set to point to the next item in the dictionary's traversal
|
---|
171 | order.
|
---|
172 |
|
---|
173 | \sa take(), clear(), setAutoDelete()
|
---|
174 | */
|
---|
175 |
|
---|
176 | /*!
|
---|
177 | \fn type *Q3IntDict::take( long key )
|
---|
178 |
|
---|
179 | Takes the item associated with \a key out of the dictionary
|
---|
180 | without deleting it (even if \link Q3PtrCollection::setAutoDelete()
|
---|
181 | auto-deletion\endlink is enabled).
|
---|
182 |
|
---|
183 | If there are two or more items with equal keys, then the most
|
---|
184 | recently inserted item will be taken.
|
---|
185 |
|
---|
186 | Returns a pointer to the item taken out, or 0 if the key does not
|
---|
187 | exist in the dictionary.
|
---|
188 |
|
---|
189 | All dictionary iterators that refer to the taken item will be set
|
---|
190 | to point to the next item in the dictionary's traversing order.
|
---|
191 |
|
---|
192 | \sa remove(), clear(), setAutoDelete()
|
---|
193 | */
|
---|
194 |
|
---|
195 | /*!
|
---|
196 | \fn void Q3IntDict::clear()
|
---|
197 |
|
---|
198 | Removes all items from the dictionary.
|
---|
199 |
|
---|
200 | The removed items are deleted if \link
|
---|
201 | Q3PtrCollection::setAutoDelete() auto-deletion\endlink is enabled.
|
---|
202 |
|
---|
203 | All dictionary iterators that access this dictionary will be reset.
|
---|
204 |
|
---|
205 | \sa remove(), take(), setAutoDelete()
|
---|
206 | */
|
---|
207 |
|
---|
208 | /*!
|
---|
209 | \fn type *Q3IntDict::find( long key ) const
|
---|
210 |
|
---|
211 | Returns the item associated with \a key, or 0 if the key does not
|
---|
212 | exist in the dictionary.
|
---|
213 |
|
---|
214 | If there are two or more items with equal keys, then the most
|
---|
215 | recently inserted item will be found.
|
---|
216 |
|
---|
217 | Equivalent to operator[].
|
---|
218 |
|
---|
219 | \sa operator[]()
|
---|
220 | */
|
---|
221 |
|
---|
222 | /*!
|
---|
223 | \fn type *Q3IntDict::operator[]( long key ) const
|
---|
224 |
|
---|
225 | Returns the item associated with \a key, or 0 if the key does not
|
---|
226 | exist in the dictionary.
|
---|
227 |
|
---|
228 | If there are two or more items with equal keys, then the most
|
---|
229 | recently inserted item will be found.
|
---|
230 |
|
---|
231 | Equivalent to the find() function.
|
---|
232 |
|
---|
233 | \sa find()
|
---|
234 | */
|
---|
235 |
|
---|
236 | /*!
|
---|
237 | \fn void Q3IntDict::statistics() const
|
---|
238 |
|
---|
239 | Debugging-only function that prints out the dictionary
|
---|
240 | distribution using qDebug().
|
---|
241 | */
|
---|
242 |
|
---|
243 | /*!
|
---|
244 | \fn QDataStream& Q3IntDict::read( QDataStream &s, Q3PtrCollection::Item &item )
|
---|
245 |
|
---|
246 | Reads a dictionary item from the stream \a s and returns a
|
---|
247 | reference to the stream.
|
---|
248 |
|
---|
249 | The default implementation sets \a item to 0.
|
---|
250 |
|
---|
251 | \sa write()
|
---|
252 | */
|
---|
253 |
|
---|
254 | /*!
|
---|
255 | \fn QDataStream& Q3IntDict::write( QDataStream &s, Q3PtrCollection::Item item ) const
|
---|
256 |
|
---|
257 | Writes a dictionary \a item to the stream \a s and returns a
|
---|
258 | reference to the stream.
|
---|
259 |
|
---|
260 | \sa read()
|
---|
261 | */
|
---|
262 |
|
---|
263 | /*!
|
---|
264 | \class Q3IntDictIterator
|
---|
265 | \brief The Q3IntDictIterator class provides an iterator for Q3IntDict collections.
|
---|
266 | \compat
|
---|
267 |
|
---|
268 | Q3IntDictIterator is implemented as a template class. Define a
|
---|
269 | template instance Q3IntDictIterator\<X\> to create a dictionary
|
---|
270 | iterator that operates on Q3IntDict\<X\> (dictionary of X*).
|
---|
271 |
|
---|
272 | Example:
|
---|
273 | \snippet doc/src/snippets/code/doc_src_q3intdict.qdoc 2
|
---|
274 |
|
---|
275 | Note that the traversal order is arbitrary; you are not guaranteed the
|
---|
276 | order shown above.
|
---|
277 |
|
---|
278 | Multiple iterators may independently traverse the same dictionary.
|
---|
279 | A Q3IntDict knows about all the iterators that are operating on the
|
---|
280 | dictionary. When an item is removed from the dictionary, Q3IntDict
|
---|
281 | updates all iterators that refer the removed item to point to the
|
---|
282 | next item in the traversal order.
|
---|
283 |
|
---|
284 | \sa Q3IntDict
|
---|
285 | */
|
---|
286 |
|
---|
287 | /*!
|
---|
288 | \fn Q3IntDictIterator::Q3IntDictIterator( const Q3IntDict<type> &dict )
|
---|
289 |
|
---|
290 | Constructs an iterator for \a dict. The current iterator item is
|
---|
291 | set to point to the 'first' item in the \a dict. The first item
|
---|
292 | refers to the first item in the dictionary's arbitrary internal
|
---|
293 | ordering.
|
---|
294 | */
|
---|
295 |
|
---|
296 | /*!
|
---|
297 | \fn Q3IntDictIterator::~Q3IntDictIterator()
|
---|
298 |
|
---|
299 | Destroys the iterator.
|
---|
300 | */
|
---|
301 |
|
---|
302 | /*!
|
---|
303 | \fn uint Q3IntDictIterator::count() const
|
---|
304 |
|
---|
305 | Returns the number of items in the dictionary this iterator
|
---|
306 | operates over.
|
---|
307 |
|
---|
308 | \sa isEmpty()
|
---|
309 | */
|
---|
310 |
|
---|
311 | /*!
|
---|
312 | \fn bool Q3IntDictIterator::isEmpty() const
|
---|
313 |
|
---|
314 | Returns TRUE if the dictionary is empty; otherwise eturns FALSE.
|
---|
315 |
|
---|
316 | \sa count()
|
---|
317 | */
|
---|
318 |
|
---|
319 | /*!
|
---|
320 | \fn type *Q3IntDictIterator::toFirst()
|
---|
321 |
|
---|
322 | Sets the current iterator item to point to the first item in the
|
---|
323 | dictionary and returns a pointer to the item. The first item
|
---|
324 | refers to the first item in the dictionary's arbitrary internal
|
---|
325 | ordering. If the dictionary is empty it sets the current item to
|
---|
326 | 0 and returns 0.
|
---|
327 | */
|
---|
328 |
|
---|
329 | /*!
|
---|
330 | \fn Q3IntDictIterator::operator type *() const
|
---|
331 |
|
---|
332 | Cast operator. Returns a pointer to the current iterator item.
|
---|
333 | Same as current().
|
---|
334 | */
|
---|
335 |
|
---|
336 | /*!
|
---|
337 | \fn type *Q3IntDictIterator::current() const
|
---|
338 |
|
---|
339 | Returns a pointer to the current iterator item.
|
---|
340 | */
|
---|
341 |
|
---|
342 | /*!
|
---|
343 | \fn long Q3IntDictIterator::currentKey() const
|
---|
344 |
|
---|
345 | Returns the key for the current iterator item.
|
---|
346 | */
|
---|
347 |
|
---|
348 | /*!
|
---|
349 | \fn type *Q3IntDictIterator::operator()()
|
---|
350 |
|
---|
351 | Makes the succeeding item current and returns the original current
|
---|
352 | item.
|
---|
353 |
|
---|
354 | If the current iterator item was the last item in the dictionary
|
---|
355 | or if it was 0, 0 is returned.
|
---|
356 | */
|
---|
357 |
|
---|
358 | /*!
|
---|
359 | \fn type *Q3IntDictIterator::operator++()
|
---|
360 |
|
---|
361 | Prefix ++ makes the succeeding item current and returns the new
|
---|
362 | current item.
|
---|
363 |
|
---|
364 | If the current iterator item was the last item in the dictionary
|
---|
365 | or if it was 0, 0 is returned.
|
---|
366 | */
|
---|
367 |
|
---|
368 | /*!
|
---|
369 | \fn type *Q3IntDictIterator::operator+=( uint jump )
|
---|
370 |
|
---|
371 | Sets the current item to the item \a jump positions after the
|
---|
372 | current item, and returns a pointer to that item.
|
---|
373 |
|
---|
374 | If that item is beyond the last item or if the dictionary is
|
---|
375 | empty, it sets the current item to 0 and returns 0.
|
---|
376 | */
|
---|