qintcache.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 237 行

HTML
237
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/doc/qintcache.doc:41 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QIntCache Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QIntCache Class Reference</h1><p>The QIntCache class is a template class that provides a cache based on long keys.<a href="#details">More...</a><p><tt>#include &lt;<a href="qintcache-h.html">qintcache.h</a>&gt;</tt><p><a href="qintcache-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QIntCache-2"><b>QIntCache</b></a> ( int&nbsp;maxCost = 100, int&nbsp;size = 17 )</div></li><li><div class=fn><a href="#~QIntCache"><b>~QIntCache</b></a> ()</div></li><li><div class=fn>int <a href="#maxCost"><b>maxCost</b></a> () const</div></li><li><div class=fn>int <a href="#totalCost"><b>totalCost</b></a> () const</div></li><li><div class=fn>void <a href="#setMaxCost"><b>setMaxCost</b></a> ( int&nbsp;m )</div></li><li><div class=fn>virtual uint <a href="#count"><b>count</b></a> () const</div></li><li><div class=fn>uint <a href="#size"><b>size</b></a> () const</div></li><li><div class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</div></li><li><div class=fn>bool <a href="#insert"><b>insert</b></a> ( long&nbsp;k, const&nbsp;type&nbsp;*&nbsp;d, int&nbsp;c = 1, int&nbsp;p = 0 )</div></li><li><div class=fn>bool <a href="#remove"><b>remove</b></a> ( long&nbsp;k )</div></li><li><div class=fn>type * <a href="#take"><b>take</b></a> ( long&nbsp;k )</div></li><li><div class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</div></li><li><div class=fn>type * <a href="#find"><b>find</b></a> ( long&nbsp;k, bool&nbsp;ref = TRUE ) const</div></li><li><div class=fn>type * <a href="#operator[]"><b>operator[]</b></a> ( long&nbsp;k ) const</div></li><li><div class=fn>void <a href="#statistics"><b>statistics</b></a> () const</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2><p> The QIntCache class is a template class that provides a cache based on long keys.<p> <p> QIntCache is implemented as a template class. Define atemplate instance QIntCache&lt;X&gt; to create a cache that operates onpointers to X, or X*.<p> A cache is a least recently used (LRU) list of cache items, accessedvia <tt>long</tt> keys.  Each cache item has a cost.  The sum of item costs,<a href="#totalCost">totalCost</a>(), will not exceed the maximum cache cost, <a href="#maxCost">maxCost</a>().If inserting a new item would cause the total cost to exceed themaximum cost, the least recently used items in the cache are removed.<p> Apart from <a href="#insert">insert</a>(), by far the most important function is <a href="#find">find</a>()(which also exists as operator[]).  This function looks up an item,returns it, and by default marks it as being the most recently useditem.<p> There are also methods to <a href="#remove">remove</a>() or <a href="#take">take</a>() an object from thecache.  Calling setAutoDelete(TRUE) for a cache tells it to deleteitems that are removed.  The default is to not delete items whenthey are removed (i.e. remove() and take() are equivalent).<p> When inserting an item into the cache, only the pointer is copied, notthe item itself. This is called a <a href="shclass.html#shallow-copy">shallow copy</a>. It is possible to make thedictionary copy all of the item's data (known as a <a href="shclass.html#deep-copy">deep copy</a>) when anitem is inserted.  insert() calls the virtual function<a href="qptrcollection.html#newItem">QPtrCollection::newItem</a>() for the item to be inserted.Inherit a dictionary and reimplement it if you want deep copies.<p> When removing a cache item if auto-deletion is enabled the item willbe automatically deleted.<p> There is a <a href="qintcacheiterator.html">QIntCacheIterator</a> which may be used to traverse theitems in the cache in arbitrary order.<p> <p>See also <a href="qintcacheiterator.html">QIntCacheIterator</a>, <a href="qcache.html">QCache</a>, <a href="qasciicache.html">QAsciiCache</a>, <a href="collection.html">Collection Classes</a> and <a href="tools.html">Non-GUI Classes</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QIntCache-2"></a>QIntCache::QIntCache ( int&nbsp;maxCost = 100, int&nbsp;size = 17 )</h3><p> Constructs a cache whose contents will never have a total costgreater than <em>maxCost</em> and which is expected to contain less than<em>size</em> items.<p> <em>size</em> is actually the size of an internal hash array; it's usuallybest to make it prime and at least 50% bigger than the largestexpected number of items in the cache.<p> Each inserted item is associated with a cost.  When inserting a newitem, if the total cost of all items in the cache will exceed <em>maxCost</em>, the cache will start throwing out the older (least recentlyused) items until there is enough room for the new item to beinserted.<h3 class=fn><a name="~QIntCache"></a>QIntCache::~QIntCache ()</h3><p> Removes all items from the cache and then destroys the int cache.If auto-deletion is enabled the cache's items are deleted.All iterators that access this cache will be reset.<h3 class=fn>void <a name="clear"></a>QIntCache::clear ()<tt> [virtual]</tt></h3><p> Removes all items from the cache, and deletes them if auto-deletionhas been enabled.<p> All cache iterators that operate this on cache are reset.<p> <p>See also <a href="#remove">remove</a>() and <a href="#take">take</a>().<h3 class=fn>uint <a name="count"></a>QIntCache::count () const<tt> [virtual]</tt></h3><p> Returns the number of items in the cache.<p> <p>See also <a href="#totalCost">totalCost</a>().<h3 class=fn>type * <a name="find"></a>QIntCache::find ( long&nbsp;k, bool&nbsp;ref = TRUE ) const</h3><p> Returns the item associated with <em>k</em>, or null if the key does notexist in the cache.  If <em>ref</em> is TRUE (the default), the item ismoved to the front of the LRU list.<p> If there are two or more items with equal keys, the one thatwas inserted last is returned.<h3 class=fn>bool <a name="insert"></a>QIntCache::insert ( long&nbsp;k, const&nbsp;type&nbsp;*&nbsp;d, int&nbsp;c = 1, int&nbsp;p = 0 )</h3><p> Inserts the item <em>d</em> into the cache with key <em>k</em> and cost <em>c</em>(default 1).  Returns TRUE if it succeeds and FALSE if it fails.<p> The cache's size is limited, and if the total cost is too high,QIntCache will remove old, least-used items until there is room forthis new item.<p> The parameter <em>p</em> is internal and should be left at the defaultvalue (0).<p> <b>Warning:</b> If this function returns FALSE, you must delete <em>d</em>yourself.  Additionally, be very careful about using <em>d</em> aftercalling this function. Any other insertions into the cache, fromanywhere in the application or within Qt itself, could cause theobject to be discarded from the cache and the pointer to becomeinvalid.<h3 class=fn>bool <a name="isEmpty"></a>QIntCache::isEmpty () const</h3><p> Returns TRUE if the cache is empty; otherwise returns FALSE.<h3 class=fn>int <a name="maxCost"></a>QIntCache::maxCost () const</h3><p> Returns the maximum allowed total cost of the cache.<p>See also <a href="#setMaxCost">setMaxCost</a>() and <a href="#totalCost">totalCost</a>().<h3 class=fn>type * <a name="operator[]"></a>QIntCache::operator[] ( long&nbsp;k ) const</h3><p> Returns the item associated with <em>k</em>, or null if <em>k</em> does notexist in the cache, and moves the item to the front of the LRU list.<p> If there are two or more items with equal keys, the one thatwas inserted last is returned.<p> This is the same as <a href="#find">find</a>( k, TRUE ).<p> <p>See also <a href="#find">find</a>().<h3 class=fn>bool <a name="remove"></a>QIntCache::remove ( long&nbsp;k )</h3><p> Removes the item associated with <em>k</em>, and returns TRUE if the itemwas present in the cache or FALSE if it was not.<p> The item is deleted if auto-deletion has been enabled, i.e. if you havecalled setAutoDelete(TRUE).<p> If there are two or more items with equal keys, the one thatwas inserted last is removed.<p> All iterators that refer to the removed item are set to point to thenext item in the cache's traversal order.<p> <p>See also <a href="#take">take</a>() and <a href="#clear">clear</a>().<h3 class=fn>void <a name="setMaxCost"></a>QIntCache::setMaxCost ( int&nbsp;m )</h3><p> Sets the maximum allowed total cost of the cache to <em>m</em>.  If thecurrent total cost is above <em>m</em>, some items are removedimmediately.<p> <p>See also <a href="#maxCost">maxCost</a>() and <a href="#totalCost">totalCost</a>().<h3 class=fn>uint <a name="size"></a>QIntCache::size () const</h3><p> Returns the size of the hash array used to implement the cache.This should be a bit larger than <a href="#count">count</a>() is likely to be.<h3 class=fn>void <a name="statistics"></a>QIntCache::statistics () const</h3><p> A debug-only utility function. Prints out cache usage, hit/miss, anddistribution information using <a href="qapplication.html#qDebug">qDebug</a>(). This function does nothingin the release library.<h3 class=fn>type * <a name="take"></a>QIntCache::take ( long&nbsp;k )</h3><p> Takes the item associated with <em>k</em> out of the cache withoutdeleting it, and returns a pointer to the item taken out or null ifthe key does not exist in the cache.<p> If there are two or more items with equal keys, the one thatwas inserted last is taken.<p> All iterators that refer to the taken item are set to point to thenext item in the cache's traversal order.<p> <p>See also <a href="#remove">remove</a>() and <a href="#clear">clear</a>().<h3 class=fn>int <a name="totalCost"></a>QIntCache::totalCost () const</h3><p> Returns the total cost of the items in the cache.  This is aninteger in the range 0 to <a href="#maxCost">maxCost</a>().<p> <p>See also <a href="#setMaxCost">setMaxCost</a>().<!-- eof --><hr><p>This file is part of the <a href="index.html">Qt toolkit</a>.Copyright &copy; 1995-2002<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright &copy; 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?