📄 qcache.3qt
字号:
'\" t.TH QCache 3qt "24 January 2005" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQCache \- Template class that provides a cache based on.br.PP\fC#include <qcache.h>\fR.PPInherits QGCache..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQCache\fR ( const QCache<type> & c ) (internal)".br.ti -1c.BI "\fBQCache\fR ( int " "maxCost" "=100, int " "size" "=17, bool " "caseSensitive" "=TRUE ) ".br.ti -1c.BI "\fB~QCache\fR () ".br.ti -1c.BI "QCache<type>& \fBoperator=\fR ( const QCache<type> & c ) (internal)".br.ti -1c.BI "int \fBmaxCost\fR () const".br.ti -1c.BI "int \fBtotalCost\fR () const".br.ti -1c.BI "void \fBsetMaxCost\fR ( int m ) ".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 "virtual void \fBclear\fR () ".br.ti -1c.BI "bool \fBinsert\fR ( const QString & " "k" ", const type * " "d" ", int " "c" "=1, int " "p" "=0 ) ".br.ti -1c.BI "bool \fBremove\fR ( const QString & k ) ".br.ti -1c.BI "type* \fBtake\fR ( const QString & k ) ".br.ti -1c.BI "type* \fBfind\fR ( const QString & " "k" ", bool " "ref" "=TRUE ) const".br.ti -1c.BI "type* \fBoperator[]\fR ( const QString & k ) const".br.ti -1c.BI "void \fBstatistics\fR () const".br.in -1c.SH DESCRIPTIONThe QCache class is a template class that provides a cache based on \fCQString\fR keys..PPA cache is a least recently used (LRU) list of cache items. Each cache item has a key and a certain cost. The sum of item costs, totalCost(), never exceeds the maximum cache cost, maxCost(). If inserting a new item would cause the total cost to exceed the maximum cost, the least recently used items in the cache are removed..PPQCache is a template class. QCache<X> defines a cache that operates on pointers to X, or X*..PPApart from insert(), by far the most important function is find() (which also exists as operator[]()). This function looks up an item, returns it, and by default marks it as being the most recently used item..PPThere are also methods to remove() or take() an object from the cache. Calling setAutoDelete(TRUE) for a cache tells it to delete items that are removed. The default is to not delete items when then are removed (i.e. remove() and take() are equivalent)..PPWhen inserting an item into the cache, 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 cache item, the virtual function QCollection::deleteItem() is called. The default implementation deletes the item if auto-deletion is enabled, and does nothing otherwise..PPThere is a QCacheIterator which may be used to traverse the items in the cache in arbitrary order..PPIn QCache, the cache items are accessed via QString keys, which are Unicode strings. If you want to use non-Unicode, plain 8-bit \fCchar*\fR keys, use the QAsciiCache template. A QCache has the same performace as a QAsciiCache..PPSee also QCacheIterator, QAsciiCache, QIntCache and Collection Classes.SH MEMBER FUNCTION DOCUMENTATION.SH "QCache::QCache ( int maxCost=100, int size=17, bool caseSensitive=TRUE )"Constructs a cache with the following properties:.PPArguments:.TP\fImaxCost\fR is the maximum allowed total cost..TP\fIsize\fR is the size of the internal hash array..TP\fIcaseSensitive\fR specifies whether to use case sensitive lookup or not. Each inserted item is associated with a cost. When inserting a new item, if the total cost of all items in the cache will exceeds \fImaxCost,\fR the cache will start throwing out the older (recently least used) items until there is room enough for the new item to be inserted..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..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 "QCache::~QCache ()"Removes all items from the cache and destroys it. All iterators that access this cache will be reset..SH "void QCache::clear () \fC[virtual]\fR"Removes all items from the cache, and deletes them if auto-deletion has been enabled..PPAll cache iterators that operate this on cache are reset..PPSee also remove() and take()..PPReimplemented from QCollection..SH "uint QCache::count () const \fC[virtual]\fR"Returns the number of items in the cache..PPSee also totalCost()..PPReimplemented from QCollection..SH "type * QCache::find ( const QString & k, bool ref=TRUE ) const"Returns the item associated with \fIk,\fR or null if the key does not exist in the cache. If \fIref\fR is TRUE (the default), the item is moved to the front of the LRU list..PPIf there are two or more items with equal keys, then the one that was inserted last is returned..SH "bool QCache::insert ( const QString & k, const type * d, int c=1, int p=0 )"Inserts the item \fId\fR into the cache with key \fIk\fR and cost \fIc.\fR Returns TRUE if it is successful and FALSE if it fails..PPThe cache's size is limited, and if the total cost is too high, QCache will remove old, least-used items until there is room for this new item..PPThe parameter \fIp\fR is internal and should be left at the default value (0)..PP\fBWarning:\fR If this function returns FALSE, you must delete \fId\fR yourself. Additionally, be very careful about using \fId\fR after calling this function, as any other insertions into the cache, from anywhere in the application, or within Qt itself, could cause the object to be discarded from the cache, and the pointer to become invalid..SH "bool QCache::isEmpty () const"Returns TRUE if the cache is empty, or FALSE if there is at least one object in it..SH "int QCache::maxCost () const"Returns the maximum allowed total cost of the cache..PPSee also setMaxCost() and totalCost()..SH "type * QCache::operator[] ( const QString & k ) const"Returns the item associated with \fIk,\fR or null if \fIk\fR does not exist in the cache, and moves the item to the front of the LRU list..PPIf there are two or more items with equal keys, then the one that was inserted last is returned..PPThis is the same as find( k, TRUE )..PPSee also find()..SH "bool QCache::remove ( const QString & k )"Removes the item associated with \fIk,\fR and returns TRUE if the item was present in the cache or FALSE if it was not..PPThe item is deleted if auto-deletion has been enabled, i.e. you have called setAutoDelete(TRUE)..PPIf there are two or more items with equal keys, then the one that was inserted last is is removed..PPAll iterators that refer to the removed item are set to point to the next item in the cache's traversal order..PPSee also take() and clear()..SH "void QCache::setMaxCost ( int m )"Sets the maximum allowed total cost of the cache to \fIm.\fR If the current total cost is above \fIm,\fR some items are deleted immediately..PPSee also maxCost() and totalCost()..SH "uint QCache::size () const"Returns the size of the hash array used to implement the cache. This should be a bit bigger than count() is likely to be..SH "void QCache::statistics () const"A debug-only utility function. Prints out cache usage, hit/miss, and distribution information using qDebug(). This function does nothing in the release library..SH "type * QCache::take ( const QString & k )"Takes the item associated with \fIk\fR out of the cache without deleting it, and returns a pointer to the item taken out, or null if the key does not exist in the cache..PPIf there are two or more items with equal keys, then the one that was inserted last is taken..PPAll iterators that refer to the taken item are set to point to the next item in the cache's traversal order..PPSee also remove() and clear()..SH "int QCache::totalCost () const"Returns the total cost of the items in the cache. This is an integer in the range 0 to maxCost()..PPSee also setMaxCost()..SH "QCache::QCache ( const QCache<type> & c )"For internal use only..SH "QCache<type>& QCache::operator= ( const QCache<type> & c )"For internal use only..SH "SEE ALSO".BR http://doc.trolltech.com/qcache.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qcache.3qt) and the Qtversion (2.3.10).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -