The QIntDict class is a template class that provides a dictionary based on long keys.
.PP
QMap is an STL-compatible alternative to this class.
.PP
QIntDict is implemented as a template class. Define a template instance QIntDict<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
QIntDict<QLineEdit> fields; // long int keys, QLineEdit* values
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 QDict for full details, including the choice of dictionary size, and how deletions are handled.
.PP
See also QIntDictIterator, QDict, QAsciiDict, QPtrDict, Collection Classes, Collection Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QIntDict::QIntDict ( 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.
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 * QIntDict::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.
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 QIntDict::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 QIntDict::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
QIntDict<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 QIntDict::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.
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 QIntDict::size () const"
Returns the size of the internal hash array (as specified in the constructor).