⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qasciidict.3qt

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 3QT
字号:
.TH QAsciiDict 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 NAMEQAsciiDict \- Template class that provides a dictionary based on \fCchar*\fR keys.SH SYNOPSIS.br.PP\fC#include <qasciidict.h>\fR.PPInherits QGDict..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQAsciiDict\fR ( int " "size" "=17, bool " "caseSensitive" "=TRUE, bool " "copyKeys" "=TRUE ) ".br.ti -1c.BI "\fBQAsciiDict\fR ( const QAsciiDict<type> & dict ) ".br.ti -1c.BI "\fB~QAsciiDict\fR () ".br.ti -1c.BI "QAsciiDict<type>& \fBoperator=\fR ( const QAsciiDict<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 char * " "key" ", const type * item ) ".br.ti -1c.BI "void \fBreplace\fR ( const char * " "key" ", const type * item ) ".br.ti -1c.BI "bool \fBremove\fR ( const char * key ) ".br.ti -1c.BI "type* \fBtake\fR ( const char * key ) ".br.ti -1c.BI "type* \fBfind\fR ( const char * key ) const".br.ti -1c.BI "type* \fBoperator[]\fR ( const char * 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 QAsciiDict class is a template class that provides a dictionary based on \fCchar*\fR keys..PPQAsciiDict is implemented as a template class. Define a template instance QAsciiDict<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. QAsciiDict has \fCchar*\fR keys. QAsciiDict cannot handle Unicode keys, instead use the QDict template which uses QString keys. 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 char* ==> char* (case insensitive).br        QAsciiDict<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 \fCchar*\fR keys to \fCchar*\fR items. Note that the mapping is case insensitive (specified in the constructor). QAsciiDict implements the [] operator to lookup an item..PPQAsciiDict 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 QAsciiDict 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 char* ==> char* (case sensitive).br        QAsciiDict<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 QAsciiDictIterator 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. QAsciiDict's default implementation is to delete the item if auto-deletion is enabled..PPSee also QAsciiDictIterator, QDict, QIntDict, QPtrDict and Collection Classes.SH MEMBER FUNCTION DOCUMENTATION.SH "QAsciiDict::QAsciiDict ( const QAsciiDict<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 "QAsciiDict::QAsciiDict ( int size=17, bool caseSensitive=TRUE, bool copyKeys=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..TP\fIcopyKeys\fR specifies whether to copy the key strings. 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 only the 26 standard letters A..Z, not French or German accents or Scandinavian letters..PPSetting \fIcopyKeys\fR to TRUE will make the dictionary copy the key when an item is inserted. Setting it to FALSE will make the dictionary only use the pointer to the key..SH "QAsciiDict::~QAsciiDict ()"Removes all items from the dictionary and destroys it..PPAll iterators that access this dictionary will be reset..PPSee also setAutoDelete()..SH "void QAsciiDict::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 QAsciiDict::count () const \fC[virtual]\fR"Returns the number of items in the dictionary..PPSee also isEmpty()..PPReimplemented from QCollection..SH "type * QAsciiDict::find ( const char * 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 QAsciiDict::insert ( const char * 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 QAsciiDict::isEmpty () const"Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE otherwise..PPSee also count()..SH "QAsciiDict<type> & QAsciiDict::operator= ( const QAsciiDict<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 * QAsciiDict::operator[] ( const char * 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 QAsciiDict::remove ( const char * 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 QAsciiDict::replace ( const char * 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    QAsciiDict<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 QAsciiDict::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 QAsciiDict::size () const"Returns the size of the internal hash array (as specified in the constructor)..PPSee also count()..SH "void QAsciiDict::statistics () const"Debugging-only function that prints out the dictionary distribution using qDebug()..SH "type * QAsciiDict::take ( const char * 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/qasciidict.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 + -