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

« back to all changes in this revision

Viewing changes to doc/html/q3dict.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/q3dict.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: Q3Dict 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">Q3Dict Class Reference</h1>
 
21
<p>The Q3Dict class is a template class that provides a dictionary based on <a href="qstring.html">QString</a> keys. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;Q3Dict&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="q3dict-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="q3dict.html#Q3Dict">Q3Dict</a></b> ( int <i>size</i> = 17, bool <i>caseSensitive</i> = true )</li>
 
32
<li><div class="fn"/><b><a href="q3dict.html#Q3Dict-2">Q3Dict</a></b> ( const Q3Dict&lt;type&gt; &amp; <i>dict</i> )</li>
 
33
<li><div class="fn"/><b><a href="q3dict.html#dtor.Q3Dict">~Q3Dict</a></b> ()</li>
 
34
<li><div class="fn"/>virtual void <b><a href="q3dict.html#clear">clear</a></b> ()</li>
 
35
<li><div class="fn"/>virtual uint <b><a href="q3dict.html#count">count</a></b> () const</li>
 
36
<li><div class="fn"/>type * <b><a href="q3dict.html#find">find</a></b> ( const QString &amp; <i>key</i> ) const</li>
 
37
<li><div class="fn"/>void <b><a href="q3dict.html#insert">insert</a></b> ( const QString &amp; <i>key</i>, const type * <i>item</i> )</li>
 
38
<li><div class="fn"/>bool <b><a href="q3dict.html#isEmpty">isEmpty</a></b> () const</li>
 
39
<li><div class="fn"/>bool <b><a href="q3dict.html#remove">remove</a></b> ( const QString &amp; <i>key</i> )</li>
 
40
<li><div class="fn"/>void <b><a href="q3dict.html#replace">replace</a></b> ( const QString &amp; <i>key</i>, const type * <i>item</i> )</li>
 
41
<li><div class="fn"/>void <b><a href="q3dict.html#resize">resize</a></b> ( uint <i>newsize</i> )</li>
 
42
<li><div class="fn"/>uint <b><a href="q3dict.html#size">size</a></b> () const</li>
 
43
<li><div class="fn"/>void <b><a href="q3dict.html#statistics">statistics</a></b> () const</li>
 
44
<li><div class="fn"/>type * <b><a href="q3dict.html#take">take</a></b> ( const QString &amp; <i>key</i> )</li>
 
45
<li><div class="fn"/>Q3Dict&lt;type&gt; &amp; <b><a href="q3dict.html#operator-eq">operator=</a></b> ( const Q3Dict&lt;type&gt; &amp; <i>dict</i> )</li>
 
46
<li><div class="fn"/>type * <b><a href="q3dict.html#operator-5b-5d">operator[]</a></b> ( const QString &amp; <i>key</i> ) const</li>
 
47
</ul>
 
48
<ul>
 
49
<li><div class="fn"/>4 public functions inherited from <a href="q3ptrcollection.html#public-functions">Q3PtrCollection</a></li>
 
50
</ul>
 
51
<a name="protected-functions"></a>
 
52
<h3>Protected Functions</h3>
 
53
<ul>
 
54
<li><div class="fn"/>virtual QDataStream &amp; <b><a href="q3dict.html#read">read</a></b> ( QDataStream &amp; <i>s</i>, Q3PtrCollection::Item &amp; <i>item</i> )</li>
 
55
<li><div class="fn"/>virtual QDataStream &amp; <b><a href="q3dict.html#write">write</a></b> ( QDataStream &amp; <i>s</i>, Q3PtrCollection::Item <i>item</i> ) const</li>
 
56
</ul>
 
57
<ul>
 
58
<li><div class="fn"/>2 protected functions inherited from <a href="q3ptrcollection.html#protected-functions">Q3PtrCollection</a></li>
 
59
</ul>
 
60
<a name="details"></a>
 
61
<hr />
 
62
<h2>Detailed Description</h2>
 
63
<p>The Q3Dict class is a template class that provides a dictionary based on <a href="qstring.html">QString</a> keys.</p>
 
64
<p>Q3Dict is implemented as a template class. Define a template instance Q3Dict&lt;X&gt; to create a dictionary that operates on pointers to X (X *).</p>
 
65
<p>A dictionary is a collection of key-value pairs. The key is a <a href="qstring.html">QString</a> used for insertion, removal and lookup. The value is a pointer. Dictionaries provide very fast insertion and lookup.</p>
 
66
<p>If you want to use non-Unicode, plain 8-bit <tt>char*</tt> keys, use the <a href="q3asciidict.html">Q3AsciiDict</a> template. A Q3Dict has the same performance as a <a href="q3asciidict.html">Q3AsciiDict</a>. If you want to have a dictionary that maps QStrings to QStrings use <a href="qmap.html">QMap</a>.</p>
 
67
<p>The <a href="q3dict.html#size">size</a>() of the dictionary 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. Size is set in the constructor but may be changed with <a href="q3dict.html#resize">resize</a>().</p>
 
68
<p>Items are inserted with <a href="q3dict.html#insert">insert</a>(); 0 pointers cannot be inserted. Items are removed with <a href="q3dict.html#remove">remove</a>(). All the items in a dictionary can be removed with <a href="q3dict.html#clear">clear</a>(). The number of items in the dictionary is returned by <a href="q3dict.html#count">count</a>(). If the dictionary contains no items <a href="q3dict.html#isEmpty">isEmpty</a>() returns TRUE. You can change an item's value with <a href="q3dict.html#replace">replace</a>(). Items are looked up with operator[](), or with <a href="q3dict.html#find">find</a>() which return a pointer to the value or 0 if the given key does not exist. You can take an item out of the dictionary with <a href="q3dict.html#take">take</a>().</p>
 
69
<p>Calling setAutoDelete(TRUE) for a dictionary tells it to delete items that are removed. The default behaviour is not to delete items when they are removed.</p>
 
70
<p>When an item is inserted, the key is converted (hashed) to an integer index into an internal hash array. This makes lookup very fast.</p>
 
71
<p>Items with equal keys are allowed. When inserting two items with the same key, only the last inserted item will be accessible (last in, first out) until it is removed.</p>
 
72
<p>The <a href="q3dictiterator.html">Q3DictIterator</a> class can traverse the dictionary, but only in an arbitrary order. Multiple iterators may independently traverse the same dictionary.</p>
 
73
<p>When inserting an item into a dictionary, only the pointer is copied, not the item itself, i.e. a shallow copy is made. It is possible to make the dictionary copy all of the item's data (a deep copy) when an item is inserted. <a href="q3dict.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>
 
74
<p>When removing a dictionary item, the virtual function <a href="q3ptrcollection.html#deleteItem">Q3PtrCollection::deleteItem</a>() is called. Q3Dict's default implementation is to delete the item if auto-deletion is enabled.</p>
 
75
<p>See also <a href="q3dictiterator.html">Q3DictIterator</a>, <a href="q3asciidict.html">Q3AsciiDict</a>, <a href="q3intdict.html">Q3IntDict</a>, and <a href="q3ptrdict.html">Q3PtrDict</a>.</p>
 
76
<hr />
 
77
<h2>Member Function Documentation</h2>
 
78
<h3 class="fn"><a name="Q3Dict"></a>Q3Dict::Q3Dict ( int <i>size</i> = 17, bool <i>caseSensitive</i> = true )</h3>
 
79
<p>Constructs a dictionary optimized for less than <i>size</i> entries.</p>
 
80
<p>We recommend setting <i>size</i> to a suitably large prime number (e.g. a prime that's slightly larger than the expected number of entries). This makes the hash distribution better which will lead to faster lookup.</p>
 
81
<p>If <i>caseSensitive</i> is TRUE (the default), keys which differ only by case are considered different.</p>
 
82
<h3 class="fn"><a name="Q3Dict-2"></a>Q3Dict::Q3Dict ( const Q3Dict&lt;type&gt; &amp; <i>dict</i> )</h3>
 
83
<p>Constructs a copy of <i>dict</i>.</p>
 
84
<p>Each item in <i>dict</i> is inserted into this dictionary. Only the pointers are copied (shallow copy).</p>
 
85
<h3 class="fn"><a name="dtor.Q3Dict"></a>Q3Dict::~Q3Dict ()</h3>
 
86
<p>Removes all items from the dictionary and destroys it. If <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>() is TRUE, each value is deleted. All iterators that access this dictionary will be reset.</p>
 
87
<p>See also <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
 
88
<h3 class="fn"><a name="clear"></a>void Q3Dict::clear ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
89
<p>Removes all items from the dictionary.</p>
 
90
<p>The removed items are deleted if <a href="q3ptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.</p>
 
91
<p>All dictionary iterators that operate on the dictionary are reset.</p>
 
92
<p>Reimplemented from <a href="q3ptrcollection.html#clear">Q3PtrCollection</a>.</p>
 
93
<p>See also <a href="q3dict.html#remove">remove</a>(), <a href="q3dict.html#take">take</a>(), and <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
 
94
<h3 class="fn"><a name="count"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3Dict::count () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
95
<p>Returns the number of items in the dictionary.</p>
 
96
<p>Reimplemented from <a href="q3ptrcollection.html#count">Q3PtrCollection</a>.</p>
 
97
<p>See also <a href="q3dict.html#isEmpty">isEmpty</a>().</p>
 
98
<h3 class="fn"><a name="find"></a>type * Q3Dict::find ( const <a href="qstring.html">QString</a> &amp; <i>key</i> ) const</h3>
 
99
<p>Returns the item with key <i>key</i>, or 0 if the key does not exist in the dictionary.</p>
 
100
<p>If there are two or more items with equal keys, then the most recently inserted item will be found.</p>
 
101
<p>Equivalent to the [] operator.</p>
 
102
<p>See also <a href="q3dict.html#operator-5b-5d">operator[]</a>().</p>
 
103
<h3 class="fn"><a name="insert"></a>void Q3Dict::insert ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const type * <i>item</i> )</h3>
 
104
<p>Inserts the key <i>key</i> with value <i>item</i> into the dictionary.</p>
 
105
<p>Multiple items can have the same key, in which case only the last item will be accessible using <a href="q3dict.html#operator-5b-5d">operator[]</a>().</p>
 
106
<p><i>item</i> may not be 0.</p>
 
107
<p>See also <a href="q3dict.html#replace">replace</a>().</p>
 
108
<h3 class="fn"><a name="isEmpty"></a>bool Q3Dict::isEmpty () const</h3>
 
109
<p>Returns TRUE if the dictionary is empty, i.e. <a href="q3dict.html#count">count</a>() == 0; otherwise returns FALSE.</p>
 
110
<p>See also <a href="q3dict.html#count">count</a>().</p>
 
111
<h3 class="fn"><a name="read"></a><a href="qdatastream.html">QDataStream</a> &amp; Q3Dict::read ( <a href="qdatastream.html">QDataStream</a> &amp; <i>s</i>, <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> &amp; <i>item</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
112
<p>Reads a dictionary item from the stream <i>s</i> and returns a reference to the stream.</p>
 
113
<p>The default implementation sets <i>item</i> to 0.</p>
 
114
<p>See also <a href="q3dict.html#write">write</a>().</p>
 
115
<h3 class="fn"><a name="remove"></a>bool Q3Dict::remove ( const <a href="qstring.html">QString</a> &amp; <i>key</i> )</h3>
 
116
<p>Removes the item with <i>key</i> from the dictionary. Returns TRUE if successful, i.e. if the item is in the dictionary; otherwise returns FALSE.</p>
 
117
<p>If there are two or more items with equal keys, then the last item that was inserted will be removed.</p>
 
118
<p>The removed item is deleted if <a href="q3ptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.</p>
 
119
<p>All dictionary iterators that refer to the removed item will be set to point to the next item in the dictionary's traversal order.</p>
 
120
<p>See also <a href="q3dict.html#take">take</a>(), <a href="q3dict.html#clear">clear</a>(), and <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
 
121
<h3 class="fn"><a name="replace"></a>void Q3Dict::replace ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const type * <i>item</i> )</h3>
 
122
<p>Replaces the value of the key, <i>key</i> with <i>item</i>.</p>
 
123
<p>If the item does not already exist, it will be inserted.</p>
 
124
<p><i>item</i> may not be 0.</p>
 
125
<p>Equivalent to:</p>
 
126
<pre>&nbsp;   Q3Dict&lt;char&gt; dict;
 
127
        ...
 
128
    if ( dict.find( key ) )
 
129
        dict.remove( key );
 
130
    dict.insert( key, item );</pre>
 
131
<p>If there are two or more items with equal keys, then the last item that was inserted will be replaced.</p>
 
132
<p>See also <a href="q3dict.html#insert">insert</a>().</p>
 
133
<h3 class="fn"><a name="resize"></a>void Q3Dict::resize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>newsize</i> )</h3>
 
134
<p>Changes the size of the hash table to <i>newsize</i>. The contents of the dictionary are preserved, but all iterators on the dictionary become invalid.</p>
 
135
<h3 class="fn"><a name="size"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3Dict::size () const</h3>
 
136
<p>Returns the size of the internal hash array (as specified in the constructor).</p>
 
137
<p>See also <a href="q3dict.html#count">count</a>().</p>
 
138
<h3 class="fn"><a name="statistics"></a>void Q3Dict::statistics () const</h3>
 
139
<p>Debugging-only function that prints out the dictionary distribution using <a href="qtglobal.html#qDebug">qDebug</a>().</p>
 
140
<h3 class="fn"><a name="take"></a>type * Q3Dict::take ( const <a href="qstring.html">QString</a> &amp; <i>key</i> )</h3>
 
141
<p>Takes the item with <i>key</i> out of the dictionary without deleting it (even if <a href="q3ptrcollection.html#setAutoDelete">auto-deletion</a> is enabled).</p>
 
142
<p>If there are two or more items with equal keys, then the last item that was inserted will be taken.</p>
 
143
<p>Returns a pointer to the item taken out, or 0 if the key does not exist in the dictionary.</p>
 
144
<p>All dictionary iterators that refer to the taken item will be set to point to the next item in the dictionary traversal order.</p>
 
145
<p>See also <a href="q3dict.html#remove">remove</a>(), <a href="q3dict.html#clear">clear</a>(), and <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>().</p>
 
146
<h3 class="fn"><a name="write"></a><a href="qdatastream.html">QDataStream</a> &amp; Q3Dict::write ( <a href="qdatastream.html">QDataStream</a> &amp; <i>s</i>, <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> <i>item</i> ) const&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
147
<p>Writes a dictionary <i>item</i> to the stream <i>s</i> and returns a reference to the stream.</p>
 
148
<p>See also <a href="q3dict.html#read">read</a>().</p>
 
149
<h3 class="fn"><a name="operator-eq"></a>Q3Dict&lt;type&gt; &amp; Q3Dict::operator= ( const Q3Dict&lt;type&gt; &amp; <i>dict</i> )</h3>
 
150
<p>Assigns <i>dict</i> to this dictionary and returns a reference to this dictionary.</p>
 
151
<p>This dictionary is first cleared, then each item in <i>dict</i> is inserted into this dictionary. Only the pointers are copied (shallow copy), unless <a href="q3ptrcollection.html#newItem">newItem</a>() has been reimplemented.</p>
 
152
<h3 class="fn"><a name="operator-5b-5d"></a>type * Q3Dict::operator[] ( const <a href="qstring.html">QString</a> &amp; <i>key</i> ) const</h3>
 
153
<p>Returns the item with key <i>key</i>, or 0 if the key does not exist in the dictionary.</p>
 
154
<p>If there are two or more items with equal keys, then the most recently inserted item will be found.</p>
 
155
<p>Equivalent to the <a href="q3dict.html#find">find</a>() function.</p>
 
156
<p>See also <a href="q3dict.html#find">find</a>().</p>
 
157
<p /><address><hr /><div align="center">
 
158
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
159
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
160
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
161
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
162
</tr></table></div></address></body>
 
163
</html>