~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/q3intcache.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/q3intcache.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: Q3IntCache Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">Q3IntCache Class Reference</h1>
 
21
<p>The Q3IntCache class is a template class that provides a cache based on long keys. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;Q3IntCache&gt;</pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See the <a href="porting4.html">Porting Guide</a> for more information.</p>
 
23
<p>Part of the <a href="qt3support.html">Qt3Support</a> module.</p>
 
24
<p>Inherits <a href="q3ptrcollection.html">Q3PtrCollection</a>.</p>
 
25
<ul>
 
26
<li><a href="q3intcache-members.html">List of all members, including inherited members</a></li>
 
27
</ul>
 
28
<a name="public-functions"></a>
 
29
<h3>Public Functions</h3>
 
30
<ul>
 
31
<li><div class="fn"/><b><a href="q3intcache.html#Q3IntCache-2">Q3IntCache</a></b> ( int <i>maxCost</i> = 100, int <i>size</i> = 17 )</li>
 
32
<li><div class="fn"/><b><a href="q3intcache.html#dtor.Q3IntCache">~Q3IntCache</a></b> ()</li>
 
33
<li><div class="fn"/>virtual void <b><a href="q3intcache.html#clear">clear</a></b> ()</li>
 
34
<li><div class="fn"/>virtual uint <b><a href="q3intcache.html#count">count</a></b> () const</li>
 
35
<li><div class="fn"/>type * <b><a href="q3intcache.html#find">find</a></b> ( long <i>k</i>, bool <i>ref</i> = true ) const</li>
 
36
<li><div class="fn"/>bool <b><a href="q3intcache.html#insert">insert</a></b> ( long <i>k</i>, const type * <i>d</i>, int <i>c</i> = 1, int <i>p</i> = 0 )</li>
 
37
<li><div class="fn"/>bool <b><a href="q3intcache.html#isEmpty">isEmpty</a></b> () const</li>
 
38
<li><div class="fn"/>int <b><a href="q3intcache.html#maxCost">maxCost</a></b> () const</li>
 
39
<li><div class="fn"/>bool <b><a href="q3intcache.html#remove">remove</a></b> ( long <i>k</i> )</li>
 
40
<li><div class="fn"/>void <b><a href="q3intcache.html#setMaxCost">setMaxCost</a></b> ( int <i>m</i> )</li>
 
41
<li><div class="fn"/>uint <b><a href="q3intcache.html#size">size</a></b> () const</li>
 
42
<li><div class="fn"/>void <b><a href="q3intcache.html#statistics">statistics</a></b> () const</li>
 
43
<li><div class="fn"/>type * <b><a href="q3intcache.html#take">take</a></b> ( long <i>k</i> )</li>
 
44
<li><div class="fn"/>int <b><a href="q3intcache.html#totalCost">totalCost</a></b> () const</li>
 
45
<li><div class="fn"/>type * <b><a href="q3intcache.html#operator-5b-5d">operator[]</a></b> ( long <i>k</i> ) const</li>
 
46
</ul>
 
47
<ul>
 
48
<li><div class="fn"/>4 public functions inherited from <a href="q3ptrcollection.html#public-functions">Q3PtrCollection</a></li>
 
49
</ul>
 
50
<h3>Additional Inherited Members</h3>
 
51
<ul>
 
52
<li><div class="fn"/>2 protected functions inherited from <a href="q3ptrcollection.html#protected-functions">Q3PtrCollection</a></li>
 
53
</ul>
 
54
<a name="details"></a>
 
55
<hr />
 
56
<h2>Detailed Description</h2>
 
57
<p>The Q3IntCache class is a template class that provides a cache based on long keys.</p>
 
58
<p>Q3IntCache is implemented as a template class. Define a template instance Q3IntCache&lt;X&gt; to create a cache that operates on pointers to X, or X*.</p>
 
59
<p>A cache is a least recently used (LRU) list of cache items, accessed via <tt>long</tt> keys. Each cache item has a cost. The sum of item costs, <a href="q3intcache.html#totalCost">totalCost</a>(), will not exceed the maximum cache cost, <a href="q3intcache.html#maxCost">maxCost</a>(). 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.</p>
 
60
<p>Apart from <a href="q3intcache.html#insert">insert</a>(), by far the most important function is <a href="q3intcache.html#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 used item.</p>
 
61
<p>There are also methods to <a href="q3intcache.html#remove">remove</a>() or <a href="q3intcache.html#take">take</a>() 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 they are removed (i.e. <a href="q3intcache.html#remove">remove</a>() and <a href="q3intcache.html#take">take</a>() are equivalent).</p>
 
62
<p>When 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 cache copy all of the item's data (known as a deep copy) when an item is inserted. <a href="q3intcache.html#insert">insert</a>() calls the virtual function <a href="q3ptrcollection.html#newItem">Q3PtrCollection::newItem</a>() for the item to be inserted. Inherit a dictionary and reimplement <a href="q3ptrcollection.html#newItem">newItem</a>() if you want deep copies.</p>
 
63
<p>When removing a cache item, the item will be automatically deleted if auto-deletion is enabled.</p>
 
64
<p>There is a <a href="q3intcacheiterator.html">Q3IntCacheIterator</a> which may be used to traverse the items in the cache in arbitrary order.</p>
 
65
<p>See also <a href="q3intcacheiterator.html">Q3IntCacheIterator</a>, <a href="q3cache.html">Q3Cache</a>, and <a href="q3asciicache.html">Q3AsciiCache</a>.</p>
 
66
<hr />
 
67
<h2>Member Function Documentation</h2>
 
68
<h3 class="fn"><a name="Q3IntCache-2"></a>Q3IntCache::Q3IntCache ( int <i>maxCost</i> = 100, int <i>size</i> = 17 )</h3>
 
69
<p>Constructs a cache whose contents will never have a total cost greater than <i>maxCost</i> and which is expected to contain less than <i>size</i> items.</p>
 
70
<p><i>size</i> is actually the size of an internal hash array; it's usually best to make it prime and at least 50% bigger than the largest expected number of items in the cache.</p>
 
71
<p>Each inserted item is associated with a cost. When inserting a new item, if the total cost of all items in the cache will exceed <i>maxCost</i>, the cache will start throwing out the older (least recently used) items until there is enough room for the new item to be inserted.</p>
 
72
<h3 class="fn"><a name="dtor.Q3IntCache"></a>Q3IntCache::~Q3IntCache ()</h3>
 
73
<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.</p>
 
74
<h3 class="fn"><a name="clear"></a>void Q3IntCache::clear ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
75
<p>Removes all items from the cache, and deletes them if auto-deletion has been enabled.</p>
 
76
<p>All cache iterators that operate this on cache are reset.</p>
 
77
<p>Reimplemented from <a href="q3ptrcollection.html#clear">Q3PtrCollection</a>.</p>
 
78
<p>See also <a href="q3intcache.html#remove">remove</a>() and <a href="q3intcache.html#take">take</a>().</p>
 
79
<h3 class="fn"><a name="count"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3IntCache::count () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
80
<p>Returns the number of items in the cache.</p>
 
81
<p>Reimplemented from <a href="q3ptrcollection.html#count">Q3PtrCollection</a>.</p>
 
82
<p>See also <a href="q3intcache.html#totalCost">totalCost</a>().</p>
 
83
<h3 class="fn"><a name="find"></a>type * Q3IntCache::find ( long <i>k</i>, bool <i>ref</i> = true ) const</h3>
 
84
<p>Returns the item associated with <i>k</i>, or 0 if the key does not exist in the cache. If <i>ref</i> is TRUE (the default), the item is moved to the front of the least recently used list.</p>
 
85
<p>If there are two or more items with equal keys, the one that was inserted most recently is returned.</p>
 
86
<h3 class="fn"><a name="insert"></a>bool Q3IntCache::insert ( long <i>k</i>, const type * <i>d</i>, int <i>c</i> = 1, int <i>p</i> = 0 )</h3>
 
87
<p>Inserts the item <i>d</i> into the cache with key <i>k</i> and assigns it a cost of <i>c</i> (default 1). Returns TRUE if it succeeds; otherwise returns FALSE.</p>
 
88
<p>The cache's size is limited, and if the total cost is too high, <a href="q3intcache.html">Q3IntCache</a> will remove old, least-used items until there is room for this new item.</p>
 
89
<p>The parameter <i>p</i> is internal and should be left at the default value (0).</p>
 
90
<p><b>Warning:</b> If this function returns FALSE (for example, the cost <tt>,</tt> exceeds <a href="q3intcache.html#maxCost">maxCost</a>()), you must delete <i>d</i> yourself. Additionally, be very careful about using <i>d</i> after calling this function. 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.</p>
 
91
<h3 class="fn"><a name="isEmpty"></a>bool Q3IntCache::isEmpty () const</h3>
 
92
<p>Returns TRUE if the cache is empty; otherwise returns FALSE.</p>
 
93
<h3 class="fn"><a name="maxCost"></a>int Q3IntCache::maxCost () const</h3>
 
94
<p>Returns the maximum allowed total cost of the cache.</p>
 
95
<p>See also <a href="q3intcache.html#setMaxCost">setMaxCost</a>() and <a href="q3intcache.html#totalCost">totalCost</a>().</p>
 
96
<h3 class="fn"><a name="remove"></a>bool Q3IntCache::remove ( long <i>k</i> )</h3>
 
97
<p>Removes the item associated with <i>k</i>, and returns TRUE if the item was present in the cache; otherwise returns FALSE.</p>
 
98
<p>The item is deleted if auto-deletion has been enabled, i.e. if you have called setAutoDelete(TRUE).</p>
 
99
<p>If there are two or more items with equal keys, the one that was inserted most recently is removed.</p>
 
100
<p>All iterators that refer to the removed item are set to point to the next item in the cache's traversal order.</p>
 
101
<p>See also <a href="q3intcache.html#take">take</a>() and <a href="q3intcache.html#clear">clear</a>().</p>
 
102
<h3 class="fn"><a name="setMaxCost"></a>void Q3IntCache::setMaxCost ( int <i>m</i> )</h3>
 
103
<p>Sets the maximum allowed total cost of the cache to <i>m</i>. If the current total cost is greater than <i>m</i>, some items are removed immediately.</p>
 
104
<p>See also <a href="q3intcache.html#maxCost">maxCost</a>() and <a href="q3intcache.html#totalCost">totalCost</a>().</p>
 
105
<h3 class="fn"><a name="size"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3IntCache::size () const</h3>
 
106
<p>Returns the size of the hash array used to implement the cache. This should be a bit larger than <a href="q3intcache.html#count">count</a>() is likely to be.</p>
 
107
<h3 class="fn"><a name="statistics"></a>void Q3IntCache::statistics () const</h3>
 
108
<p>A debug-only utility function. Prints out cache usage, hit/miss, and distribution information using <a href="qtglobal.html#qDebug">qDebug</a>(). This function does nothing in the release library.</p>
 
109
<h3 class="fn"><a name="take"></a>type * Q3IntCache::take ( long <i>k</i> )</h3>
 
110
<p>Takes the item associated with <i>k</i> out of the cache without deleting it, and returns a pointer to the item taken out or 0 if the key does not exist in the cache.</p>
 
111
<p>If there are two or more items with equal keys, the one that was inserted most recently is taken.</p>
 
112
<p>All iterators that refer to the taken item are set to point to the next item in the cache's traversal order.</p>
 
113
<p>See also <a href="q3intcache.html#remove">remove</a>() and <a href="q3intcache.html#clear">clear</a>().</p>
 
114
<h3 class="fn"><a name="totalCost"></a>int Q3IntCache::totalCost () const</h3>
 
115
<p>Returns the total cost of the items in the cache. This is an integer in the range 0 to <a href="q3intcache.html#maxCost">maxCost</a>().</p>
 
116
<p>See also <a href="q3intcache.html#setMaxCost">setMaxCost</a>().</p>
 
117
<h3 class="fn"><a name="operator-5b-5d"></a>type * Q3IntCache::operator[] ( long <i>k</i> ) const</h3>
 
118
<p>Returns the item associated with <i>k</i>, or 0 if <i>k</i> does not exist in the cache, and moves the item to the front of the least recently used list.</p>
 
119
<p>If there are two or more items with equal keys, the one that was inserted most recently is returned.</p>
 
120
<p>This is the same as find( k, TRUE ).</p>
 
121
<p>See also <a href="q3intcache.html#find">find</a>().</p>
 
122
<p /><address><hr /><div align="center">
 
123
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
124
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
125
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
126
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
127
</tr></table></div></address></body>
 
128
</html>