The QPtrDict class is a template class that provides a dictionary based on void* keys.
.PP
QPtrDict is implemented as a template class. Define a template instance QPtrDict<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 a void* used for insertion, removal and lookup. The value is a pointer. Dictionaries provide very fast insertion and lookup.
fields.remove( le1 ); // Removes le1 from the dictionary
.br
cout << le1->text() << endl; // Prints "Simpson"
.br
.fi
In this example we use a dictionary to add an extra property (a char*) to the line edits we're using.
.PP
See QDict for full details, including the choice of dictionary size, and how deletions are handled.
.PP
See also QPtrDictIterator, QDict, QAsciiDict, QIntDict, Collection Classes, Collection Classes, and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QPtrDict::QPtrDict ( int size = 17 )"
Constructs a dictionary using an internal hash array with the 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 and improves lookup performance.
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 the dictionary. Only the pointers are copied (shallow copy), unless newItem() has been reimplemented.
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 QPtrDict::remove ( void * key )"
Removes the item associated with \fIkey\fR from the dictionary. Returns TRUE if successful, i.e. if \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 traversal order.
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
QPtrDict<ItemType> 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().
.SH "void QPtrDict::resize ( uint newsize )"
Changes the size of the hash table 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 QPtrDict::size () const"
Returns the size of the internal hash table (as specified in the constructor).