📄 qdict.3qt
字号:
.TH QDict 3qt "10 November 2000" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2000 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQDict \- Template class that provides a dictionary based on \fCQString\fR keys.SH SYNOPSIS.br.PP\fC#include <qdict.h>\fR.PPInherits QGDict..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQDict\fR ( int " "size" "=17, bool " "caseSensitive" "=TRUE ) ".br.ti -1c.BI "\fBQDict\fR ( const QDict<type> & dict ) ".br.ti -1c.BI "\fB~QDict\fR () ".br.ti -1c.BI "QDict<type>& \fBoperator=\fR ( const QDict<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 ( const QString & " "key" ", const type * item ) ".br.ti -1c.BI "void \fBreplace\fR ( const QString & " "key" ", const type * item ) ".br.ti -1c.BI "bool \fBremove\fR ( const QString & key ) ".br.ti -1c.BI "type* \fBtake\fR ( const QString & key ) ".br.ti -1c.BI "type* \fBfind\fR ( const QString & key ) const".br.ti -1c.BI "type* \fBoperator[]\fR ( const QString & 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.SH DESCRIPTIONThe QDict class is a template class that provides a dictionary based on \fCQString\fR keys..PPQDict is implemented as a template class. Define a template instance QDict<X> to create a dictionary that operates on pointers to X, or X*..PPA dictionary is a collection that associates an item with a key. The key is used for inserting and looking up an item. QDict has QString keys, which are Unicode strings. If you want to use non-Unicode, plain 8-bit \fCchar*\fR keys, use the QAsciiDict template. A QDict has the same performace as a QAsciiDict..PPThe dictionary has very fast insertion and lookup..PPExample:.PP.nf.br #include <qdict.h>.br #include <stdio.h>.br.br void main().br {.br // Creates a dictionary that maps QString ==> char* (case insensitive).br QDict<char> dict( 17, FALSE );.br.br dict.insert( "France", "Paris" );.br dict.insert( "Russia", "Moscow" );.br dict.insert( "Norway", "Oslo" );.br.br printf( "%s\\n", dict["Norway"] );.br printf( "%s\\n", dict["FRANCE"] );.br printf( "%s\\n", dict["russia"] );.br.br if ( !dict["Italy"] ).br printf( "Italy not defined\\n" );.br }.fi.PPProgram output:.PP.nf.br Oslo.br Paris.br Moscow.br Italy not defined.fi.PPThe dictionary in our example maps \fCQString\fR keys to \fCchar*\fR items. Note that the mapping is case insensitive (specified in the constructor). QDict implements the [] operator to lookup an item..PPQDict is implemented by QGDict as a hash array with a fixed number of entries. Each array entry points to a singly linked list of buckets, in which the dictionary items are stored..PPWhen an item is inserted with a key, the key is converted (hashed) to an integer index into the hash array. The item is inserted before the first bucket in the list of buckets..PPLooking up an item is normally very fast. The key is again hashed to an array index. Then QDict scans the list of buckets and returns the item found or null if the item was not found. You cannot insert null pointers into a dictionary..PPThe size of the hash array is very important. In order to get good performance, you should use a suitably large prime number. Suitable means equal to or larger than the maximum expected number of dictionary items..PPItems with equal keys are allowed. When inserting two items with the same key, only the last inserted item will be visible (last in, first out) until it is removed..PPExample:.PP.nf.br #include <qdict.h>.br #include <stdio.h>.br.br void main().br {.br // Creates a dictionary that maps QString ==> char* (case sensitive).br QDict<char> dict;.br.br dict.insert( "Germany", "Berlin" );.br dict.insert( "Germany", "Bonn" );.br.br printf( "%s\\n", dict["Germany"] );.br dict.remove( "Germany" ); // Oct 3rd 1990.br printf( "%s\\n", dict["Germany"] );.br }.fi.PPProgram output:.PP.nf.br Bonn.br Berlin.fi.PPThe QDictIterator class can traverse the dictionary contents, but only in an arbitrary order. Multiple iterators may independently traverse the same dictionary..PPCalling setAutoDelete(TRUE) for a dictionary tells it to delete items that are removed . The default is to not delete items when they are removed..PPWhen inserting an item into a dictionary, only the pointer is copied, not the item itself. This is called a shallow copy. It is possible to make the dictionary copy all of the item's data (known as a deep copy) when an item is inserted. insert() calls the virtual function QCollection::newItem() for the item to be inserted. Inherit a dictionary and reimplement it if you want deep copies..PPWhen removing a dictionary item, the virtual function QCollection::deleteItem() is called. QDict's default implementation is to delete the item if auto-deletion is enabled..PPSee also QDictIterator, QAsciiDict, QIntDict, QPtrDict and Collection Classes.SH MEMBER FUNCTION DOCUMENTATION.SH "QDict::QDict ( const QDict<type> & dict )"Constructs a copy of \fIdict.\fR.PPEach item in \fIdict\fR are inserted into this dictionary. Only the pointers are copied (shallow copy)..SH "QDict::QDict ( int size=17, bool caseSensitive=TRUE )"Constructs a dictionary with the following properties:.PPArguments:.TP\fIsize\fR is the size of the internal hash array..TP\fIcaseSensitive\fR specifies whether to use case sensitive lookup or not. 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 hence the loopup faster..PPSetting \fIcaseSensitive\fR to TRUE will treat "abc" and "Abc" as different keys. Setting it to FALSE will make the dictionary ignore case. Case insensitive comparison includes the whole Unicode alphabeth..SH "QDict::~QDict ()"Removes all items from the dictionary and destroys it. All iterators that access this dictionary will be reset..PPSee also setAutoDelete()..SH "void QDict::clear () \fC[virtual]\fR"Removes all items from the dictionary..PPThe removed items are deleted if auto-deletion is enabled..PPAll dictionary iterators that operate on dictionary are reset..PPSee also remove(), take() and setAutoDelete()..PPReimplemented from QCollection..SH "uint QDict::count () const \fC[virtual]\fR"Returns the number of items in the dictionary..PPSee also isEmpty()..PPReimplemented from QCollection..SH "type * QDict::find ( const QString & key ) const"Returns the item associated with \fIkey,\fR or null if the key does not exist in the dictionary..PPThis function uses an internal hashing algorithm to optimize lookup..PPIf there are two or more items with equal keys, then the last inserted of these will be found..PPEquivalent to the [] operator..PPSee also operator[]()..SH "void QDict::insert ( const QString & key, const type * item )"Inserts the \fIkey\fR with the \fIitem\fR into the dictionary..PPThe key does not have to be a unique dictionary key. If multiple items are inserted with the same key, only the last item will be visible..PPNull items are not allowed..PPSee also replace()..SH "bool QDict::isEmpty () const"Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE otherwise..PPSee also count()..SH "QDict<type> & QDict::operator= ( const QDict<type> & dict )"Assigns \fIdict\fR to this dictionary and returns a reference to this dictionary..PPThis dictionary is first cleared, 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 * QDict::operator[] ( const QString & key ) const"Returns the item associated with \fIkey,\fR or null if the key does not exist in the dictionary..PPThis function uses an internal hashing algorithm to optimize lookup..PPIf there are two or more items with equal keys, then the last inserted of these will be found..PPEquivalent to the find() function..PPSee also find()..SH "bool QDict::remove ( const QString & key )"Removes the item associated with \fIkey\fR from the dictionary. Returns TRUE if successful, or FALSE if the key does not exist in the dictionary..PPIf there are two or more items with equal keys, then the last inserted of these will be removed..PPThe removed item is deleted if auto-deletion is enabled..PPAll dictionary iterators that refer to the removed item will be set to point to the next item in the dictionary traversing order..PPSee also take(), clear() and setAutoDelete()..SH "void QDict::replace ( const QString & key, const type * item )"Replaces an item which has a key equal to \fIkey\fR with \fIitem.\fR.PPIf the item does not already exist, it will be inserted..PPNull items are not allowed..PPEquivalent to:.PP.nf.br QDict<char> dict;.br ....br if ( dict.find(key) ).br dict.remove( key );.br dict.insert( key, item );.fi.PPIf there are two or more items with equal keys, then the last inserted of these will be replaced..PPSee also insert()..SH "void QDict::resize ( uint newsize )"Changes the size of the hashtable the \fInewsize.\fR The contents of the dictionary are preserved, but all iterators on the dictionary become invalid..SH "uint QDict::size () const"Returns the size of the internal hash array (as specified in the constructor)..PPSee also count()..SH "void QDict::statistics () const"Debugging-only function that prints out the dictionary distribution using qDebug()..SH "type * QDict::take ( const QString & key )"Takes the item associated with \fIkey\fR out of the dictionary without deleting it (even if auto-deletion is enabled)..PPIf there are two or more items with equal keys, then the last inserted of these will be taken..PPReturns a pointer to the item taken out, or null if the key does not exist in the dictionary..PPAll dictionary iterators that refer to the taken item will be set to point to the next item in the dictionary traversal order..PPSee also remove(), clear() and setAutoDelete()..SH "SEE ALSO".BR http://doc.trolltech.com/qdict.html.SH COPYRIGHTCopyright 1992-2000 Trolltech AS, http://www.trolltech.com/. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -