📄 qintdict.3qt
字号:
.TH QIntDict 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 NAMEQIntDict \- Template class that provides a dictionary based on \fClong\fR keys.SH SYNOPSIS.br.PP\fC#include <qintdict.h>\fR.PPInherits QGDict..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQIntDict\fR ( int " "size" "=17 ) ".br.ti -1c.BI "\fBQIntDict\fR ( const QIntDict<type> & dict ) ".br.ti -1c.BI "\fB~QIntDict\fR () ".br.ti -1c.BI "QIntDict<type>& \fBoperator=\fR ( const QIntDict<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.SH DESCRIPTIONThe QIntDict class is a template class that provides a dictionary based on \fClong\fR keys..PPQIntDict is implemented as a template class. Define a template instance QIntDict<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. QIntDict has \fClong\fR keys..PPThe dictionary has very fast insertion and lookup..PPExample:.PP.nf.br #include <qintdict.h>.br #include <stdio.h>.br.br void main().br {.br QIntDict<char> dict; // maps long ==> char*.br.br dict.insert( 33, "France" );.br dict.insert( 7, "Russia" );.br dict.insert( 49, "Norway" );.br.br printf( "%s\\n", dict[49] );.br printf( "%s\\n", dict[33] );.br printf( "%s\\n", dict[7] );.br.br if ( !dict[39] ).br printf( "39 not defined\\n" );.br }.fi.PPProgram output:.PP.nf.br Norway.br France.br Russia.br 39 not defined.fi.PPThe dictionary in our example maps \fClong\fR keys to \fCchar*\fR items. QIntDict implements the [] operator to lookup an item..PPQIntDict 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 using the \fCmod\fR operation. 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 QIntDict 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 <qintdict.h>.br #include <stdio.h>.br.br void main().br {.br QIntDict<char> dict; // maps long ==> char*.br.br dict.insert( 7, "Russia" );.br dict.insert( 7, "USSR" );.br.br printf( "%s\\n", dict[7] );.br dict.remove( 7 ); // Gorbie was here.br printf( "%s\\n", dict[7] );.br }.fi.PPProgram output:.PP.nf.br USSR.br Russia.fi.PPThe QIntDictIterator 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. QIntDict's default implementation is to delete the item if auto-deletion is enabled..PPSee also QIntDictIterator, QDict, QAsciiDict, QPtrDict and Collection Classes.SH MEMBER FUNCTION DOCUMENTATION.SH "QIntDict::QIntDict ( const QIntDict<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 "QIntDict::QIntDict ( int size=17 )"Constructs a dictionary using an internal hash array with the size \fIsize.\fR.PPSetting \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..SH "QIntDict::~QIntDict ()"Removes all items from the dictionary and destroys it..PPAll iterators that access this dictionary will be reset..PPSee also setAutoDelete()..SH "void QIntDict::clear () \fC[virtual]\fR"Removes all items from the dictionary..PPThe removed items are deleted if auto-deletion is enabled..PPAll dictionary iterators that access this dictionary will be reset..PPSee also remove(), take() and setAutoDelete()..PPReimplemented from QCollection..SH "uint QIntDict::count () const \fC[virtual]\fR"Returns the number of items in the dictionary..PPSee also isEmpty()..PPReimplemented from QCollection..SH "type * QIntDict::find ( long 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 QIntDict::insert ( long 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 QIntDict::isEmpty () const"Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE otherwise..PPSee also count()..SH "QIntDict<type> & QIntDict::operator= ( const QIntDict<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 * QIntDict::operator[] ( long 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 QIntDict::remove ( long 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 QIntDict::replace ( long 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 QIntDict<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 QIntDict::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 QIntDict::size () const"Returns the size of the internal hash array (as specified in the constructor)..PPSee also count()..SH "void QIntDict::statistics () const"Debugging-only function that prints out the dictionary distribution using qDebug()..SH "type * QIntDict::take ( long 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 traversing order..PPSee also remove(), clear() and setAutoDelete()..SH "SEE ALSO".BR http://doc.trolltech.com/qintdict.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 + -