<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csutil/hash.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csutil/hash.h</h1><a href="hash_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 2003 by Mat Sutcliffe <oktal@gmx.co.uk></span> <a name="l00003"></a>00003 <span class="comment"></span> <a name="l00004"></a>00004 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00005"></a>00005 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span> <a name="l00006"></a>00006 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00007"></a>00007 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00010"></a>00010 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00011"></a>00011 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00012"></a>00012 <span class="comment"> Library General Public License for more details.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00015"></a>00015 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00016"></a>00016 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00017"></a>00017 <span class="comment">*/</span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#ifndef __CS_UTIL_HASH_H__</span> <a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define __CS_UTIL_HASH_H__</span> <a name="l00021"></a>00021 <span class="preprocessor"></span> <a name="l00026"></a>00026 <span class="preprocessor">#include "csextern.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="csutil_2array_8h.html" title="Generic Array Template.">csutil/array.h</a>"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="comparator_8h.html" title="Template providing various comparison and ordering functions.">csutil/comparator.h</a>"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="util_8h.html" title="Miscellaneous utilities.">csutil/util.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="tuple_8h.html" title="A tuple (fixed size collection of elements).">csutil/tuple.h</a>"</span> <a name="l00031"></a>00031 <a name="l00041"></a>00041 CS_CRYSTALSPACE_EXPORT <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="group__util__containers.html#gb805c6e597fbb1d73233fecf4c050a6e" title="Compute a hash key for a null-terminated string.">csHashCompute</a> (<span class="keywordtype">char</span> <span class="keyword">const</span>*); <a name="l00042"></a>00042 <a name="l00049"></a>00049 CS_CRYSTALSPACE_EXPORT <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="group__util__containers.html#gb805c6e597fbb1d73233fecf4c050a6e" title="Compute a hash key for a null-terminated string.">csHashCompute</a> (<span class="keywordtype">char</span> <span class="keyword">const</span>*, <span class="keywordtype">size_t</span> length); <a name="l00050"></a>00050 <a name="l00055"></a>00055 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00056"></a><a class="code" href="classcsHashComputer.html">00056</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a> <a name="l00057"></a>00057 { <a name="l00058"></a>00058 <span class="keyword">public</span>: <a name="l00060"></a><a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b">00060</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">ComputeHash</a> (<span class="keyword">const</span> T& key) <a name="l00061"></a>00061 { <a name="l00062"></a>00062 <span class="keywordflow">return</span> key.GetHash(); <a name="l00063"></a>00063 } <a name="l00064"></a>00064 }; <a name="l00065"></a>00065 <a name="l00070"></a>00070 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00071"></a><a class="code" href="classcsHashComputerIntegral.html">00071</a> <span class="keyword">class </span><a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a> <a name="l00072"></a>00072 { <a name="l00073"></a>00073 <span class="keyword">public</span>: <a name="l00075"></a><a class="code" href="classcsHashComputerIntegral.html#35cb1f6cc37aea67763556e66549362a">00075</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputerIntegral.html#35cb1f6cc37aea67763556e66549362a" title="Compute a hash value for key.">ComputeHash</a> (<span class="keyword">const</span> T& key) <a name="l00076"></a>00076 { <a name="l00077"></a>00077 <span class="keywordflow">return</span> (<a class="code" href="group__util.html#g728e973c799f206f0151c8a3bd1e5699" title="Unsigned integer at least as wide as a pointer.">uintptr_t</a>)key; <a name="l00078"></a>00078 } <a name="l00079"></a>00079 }; <a name="l00080"></a>00080 <a name="l00082"></a>00082 <a name="l00085"></a>00085 <span class="keyword">template</span><> <a name="l00086"></a><a class="code" href="classcsHashComputer_3_01void_01_5_01_4.html">00086</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><void*> : <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral<void*></a> {}; <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keyword">template</span><> <a name="l00089"></a><a class="code" href="classcsHashComputer_3_01int_01_4.html">00089</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><int> : <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><int> {}; <a name="l00090"></a>00090 <span class="keyword">template</span><> <a name="l00091"></a><a class="code" href="classcsHashComputer_3_01unsigned_01int_01_4.html">00091</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><unsigned int> : <a name="l00092"></a>00092 <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><unsigned int> {}; <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keyword">template</span><> <a name="l00095"></a><a class="code" href="classcsHashComputer_3_01long_01_4.html">00095</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><long> : <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><long> {}; <a name="l00096"></a>00096 <span class="keyword">template</span><> <a name="l00097"></a><a class="code" href="classcsHashComputer_3_01unsigned_01long_01_4.html">00097</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><unsigned long> : <a name="l00098"></a>00098 <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><unsigned long> {}; <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="preprocessor">#if (CS_LONG_SIZE < 8) </span> <a name="l00101"></a>00101 <span class="preprocessor"></span><span class="keyword">template</span><> <a name="l00102"></a><a class="code" href="classcsHashComputer_3_01longlong_01_4.html">00102</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><<a class="code" href="group__util.html#g574e57efdc7bcebd6e3b5e043fdeb28c" title="Type to pass to cs_snprintf() as an argument to the &quot;%lld&quot; format specifier...">longlong</a>> : <a name="l00103"></a>00103 <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><longlong> {}; <a name="l00104"></a>00104 <span class="keyword">template</span><> <a name="l00105"></a><a class="code" href="classcsHashComputer_3_01ulonglong_01_4.html">00105</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><<a class="code" href="group__util.html#g8c42bcc74c4498c45586ad15fab3b829" title="Type to pass to cs_snprintf() as an argument to the &quot;%llu&quot; format specifier...">ulonglong</a>> : <a name="l00106"></a>00106 <span class="keyword">public</span> <a class="code" href="classcsHashComputerIntegral.html" title="Template for hash value computing, suitable for integral types and types that can...">csHashComputerIntegral</a><ulonglong> {}; <a name="l00107"></a>00107 <span class="preprocessor">#endif</span> <a name="l00108"></a>00108 <span class="preprocessor"></span> <a name="l00109"></a>00109 <span class="keyword">template</span><> <a name="l00110"></a><a class="code" href="classcsHashComputer_3_01float_01_4.html">00110</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><float> <a name="l00111"></a>00111 { <a name="l00112"></a>00112 <span class="keyword">public</span>: <a name="l00114"></a><a class="code" href="classcsHashComputer_3_01float_01_4.html#bc111aad97ee04714cf17776d9baa2bf">00114</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">ComputeHash</a> (<span class="keywordtype">float</span> key) <a name="l00115"></a>00115 { <a name="l00116"></a>00116 <span class="keyword">union</span> <a name="l00117"></a>00117 { <a name="l00118"></a>00118 <span class="keywordtype">float</span> f; <a name="l00119"></a>00119 <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> u; <a name="l00120"></a>00120 } float2uint; <a name="l00121"></a>00121 float2uint.f = key; <a name="l00122"></a>00122 <span class="keywordflow">return</span> float2uint.u; <a name="l00123"></a>00123 } <a name="l00124"></a>00124 }; <a name="l00125"></a>00125 <span class="keyword">template</span><> <a name="l00126"></a><a class="code" href="classcsHashComputer_3_01double_01_4.html">00126</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><double> <a name="l00127"></a>00127 { <a name="l00128"></a>00128 <span class="keyword">public</span>: <a name="l00130"></a><a class="code" href="classcsHashComputer_3_01double_01_4.html#dfd748088ec0d2eeec39c0be00cb4e22">00130</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">ComputeHash</a> (<span class="keywordtype">double</span> key) <a name="l00131"></a>00131 { <a name="l00132"></a>00132 <span class="keyword">union</span> <a name="l00133"></a>00133 { <a name="l00134"></a>00134 <span class="keywordtype">double</span> f; <a name="l00135"></a>00135 <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> u; <a name="l00136"></a>00136 } double2uint; <a name="l00137"></a>00137 double2uint.f = key; <a name="l00138"></a>00138 <span class="keywordflow">return</span> double2uint.u; <a name="l00139"></a>00139 } <a name="l00140"></a>00140 }; <a name="l00142"></a>00142 <a name="l00146"></a>00146 <span class="keyword">template</span> <<span class="keyword">typename</span> T> <a name="l00147"></a><a class="code" href="classcsPtrKey.html">00147</a> <span class="keyword">class </span><a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a> <a name="l00148"></a>00148 { <a name="l00149"></a>00149 T* ptr; <a name="l00150"></a>00150 <span class="keyword">public</span>: <a name="l00151"></a><a class="code" href="classcsPtrKey.html#eae11e6ae13001f4c60c1dbbf08c9c0b">00151</a> <a class="code" href="classcsPtrKey.html#eae11e6ae13001f4c60c1dbbf08c9c0b">csPtrKey</a> () : ptr(0) {} <a name="l00152"></a><a class="code" href="classcsPtrKey.html#3c8649bce031e48b041ac4c77f634eaa">00152</a> <a class="code" href="classcsPtrKey.html#eae11e6ae13001f4c60c1dbbf08c9c0b">csPtrKey</a> (T* ptr) : ptr(ptr) {} <a name="l00153"></a><a class="code" href="classcsPtrKey.html#1b7afa39ef74f3e12e5d5ed3579da73d">00153</a> <a class="code" href="classcsPtrKey.html#eae11e6ae13001f4c60c1dbbf08c9c0b">csPtrKey</a> (<a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a> <span class="keyword">const</span>& other) : ptr (other.ptr) {} <a name="l00154"></a>00154 <a name="l00155"></a><a class="code" href="classcsPtrKey.html#0fb8bb56e6726dcce047032d14f84da4">00155</a> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsPtrKey.html#0fb8bb56e6726dcce047032d14f84da4">GetHash</a> ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (<a class="code" href="group__util.html#g728e973c799f206f0151c8a3bd1e5699" title="Unsigned integer at least as wide as a pointer.">uintptr_t</a>)ptr; } <a name="l00156"></a><a class="code" href="classcsPtrKey.html#377c0848a42b5f546bbe107e0fb94308">00156</a> <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> <a class="code" href="classcsPtrKey.html#377c0848a42b5f546bbe107e0fb94308">operator < </a>(<span class="keyword">const</span> <a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a>& r1, <span class="keyword">const</span> <a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a>& r2) <a name="l00157"></a>00157 { <span class="keywordflow">return</span> r1.<a class="code" href="classcsPtrKey.html#076271593404c1e8188c4992200a752f">ptr</a> < r2.<a class="code" href="classcsPtrKey.html#076271593404c1e8188c4992200a752f">ptr</a>; } <a name="l00158"></a><a class="code" href="classcsPtrKey.html#556bf63cb74ad42ba6d097d51493da35">00158</a> <a class="code" href="classcsPtrKey.html#556bf63cb74ad42ba6d097d51493da35">operator T* </a>()<span class="keyword"> const</span> <a name="l00159"></a>00159 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ptr; } <a name="l00160"></a><a class="code" href="classcsPtrKey.html#caf3ede480d9099b9857f3ad2a107940">00160</a> T* <a class="code" href="classcsPtrKey.html#caf3ede480d9099b9857f3ad2a107940">operator -> </a>()<span class="keyword"> const</span> <a name="l00161"></a>00161 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ptr; } <a name="l00162"></a><a class="code" href="classcsPtrKey.html#f53ac175e6242f0eba86689147a68dd2">00162</a> <a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a>& <a class="code" href="classcsPtrKey.html#f53ac175e6242f0eba86689147a68dd2">operator = </a>(<a class="code" href="classcsPtrKey.html" title="A helper template to use pointers as keys for hashes.">csPtrKey</a> <span class="keyword">const</span>& other) <a name="l00163"></a>00163 { ptr = other.<a class="code" href="classcsPtrKey.html#076271593404c1e8188c4992200a752f">ptr</a>; <span class="keywordflow">return</span> *<span class="keyword">this</span>; } <a name="l00164"></a>00164 }; <a name="l00165"></a>00165 <a name="l00169"></a>00169 <span class="keyword">template</span> <<span class="keyword">typename</span> T> <a name="l00170"></a><a class="code" href="classcsConstPtrKey.html">00170</a> <span class="keyword">class </span><a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a> <a name="l00171"></a>00171 { <a name="l00172"></a>00172 <span class="keyword">const</span> T* ptr; <a name="l00173"></a>00173 <span class="keyword">public</span>: <a name="l00174"></a><a class="code" href="classcsConstPtrKey.html#3b04b99602ed60fb96a905ff5721308c">00174</a> <a class="code" href="classcsConstPtrKey.html#3b04b99602ed60fb96a905ff5721308c">csConstPtrKey</a> () : ptr(0) {} <a name="l00175"></a><a class="code" href="classcsConstPtrKey.html#6b00a8657b00c48f262edb2dc8297ae0">00175</a> <a class="code" href="classcsConstPtrKey.html#3b04b99602ed60fb96a905ff5721308c">csConstPtrKey</a> (<span class="keyword">const</span> T* ptr) : ptr(ptr) {} <a name="l00176"></a><a class="code" href="classcsConstPtrKey.html#83a3edf23d22b53286848b9bf0e08eba">00176</a> <a class="code" href="classcsConstPtrKey.html#3b04b99602ed60fb96a905ff5721308c">csConstPtrKey</a> (<a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a> <span class="keyword">const</span>& other) : ptr (other.ptr) {} <a name="l00177"></a>00177 <a name="l00178"></a><a class="code" href="classcsConstPtrKey.html#b005266564adc19d819e92aebd056786">00178</a> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsConstPtrKey.html#b005266564adc19d819e92aebd056786">GetHash</a> ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (<a class="code" href="group__util.html#g728e973c799f206f0151c8a3bd1e5699" title="Unsigned integer at least as wide as a pointer.">uintptr_t</a>)ptr; } <a name="l00179"></a><a class="code" href="classcsConstPtrKey.html#bff7d86849ea9639ec9e4c5345b5a26f">00179</a> <span class="keyword">inline</span> <span class="keyword">friend</span> <span class="keywordtype">bool</span> <a class="code" href="classcsConstPtrKey.html#bff7d86849ea9639ec9e4c5345b5a26f">operator < </a>(<span class="keyword">const</span> <a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a>& r1, <span class="keyword">const</span> <a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a>& r2) <a name="l00180"></a>00180 { <span class="keywordflow">return</span> r1.<a class="code" href="classcsConstPtrKey.html#4b16893660c5b65e0c1cd26f6afae245">ptr</a> < r2.<a class="code" href="classcsConstPtrKey.html#4b16893660c5b65e0c1cd26f6afae245">ptr</a>; } <a name="l00181"></a><a class="code" href="classcsConstPtrKey.html#0fd852a9328712bb4438875012487960">00181</a> <a class="code" href="classcsConstPtrKey.html#0fd852a9328712bb4438875012487960">operator const T* </a>()<span class="keyword"> const</span> <a name="l00182"></a>00182 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ptr; } <a name="l00183"></a><a class="code" href="classcsConstPtrKey.html#a27c9a91e9b0eb7234912184e96c363e">00183</a> <span class="keyword">const</span> T* <a class="code" href="classcsConstPtrKey.html#a27c9a91e9b0eb7234912184e96c363e">operator -> </a>()<span class="keyword"> const</span> <a name="l00184"></a>00184 <span class="keyword"> </span>{ <span class="keywordflow">return</span> ptr; } <a name="l00185"></a><a class="code" href="classcsConstPtrKey.html#2516eccd4c78e6d46fc4b29dab926adc">00185</a> <a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a>& <a class="code" href="classcsConstPtrKey.html#2516eccd4c78e6d46fc4b29dab926adc">operator = </a>(<a class="code" href="classcsConstPtrKey.html" title="A helper template to use const pointers as keys for hashes.">csConstPtrKey</a> <span class="keyword">const</span>& other) <a name="l00186"></a>00186 { ptr = other.<a class="code" href="classcsConstPtrKey.html#4b16893660c5b65e0c1cd26f6afae245">ptr</a>; <span class="keywordflow">return</span> *<span class="keyword">this</span>; } <a name="l00187"></a>00187 }; <a name="l00188"></a>00188 <a name="l00198"></a>00198 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00199"></a><a class="code" href="classcsHashComputerString.html">00199</a> <span class="keyword">class </span><a class="code" href="classcsHashComputerString.html" title="Template that can be used as a base class for hash computers for string types (must...">csHashComputerString</a> <a name="l00200"></a>00200 { <a name="l00201"></a>00201 <span class="keyword">public</span>: <a name="l00202"></a><a class="code" href="classcsHashComputerString.html#842a46ab901f6e6ecdfc849d7a1b51a7">00202</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputerString.html#842a46ab901f6e6ecdfc849d7a1b51a7">ComputeHash</a> (<span class="keyword">const</span> T& key) <a name="l00203"></a>00203 { <a name="l00204"></a>00204 <span class="keywordflow">return</span> <a class="code" href="group__util__containers.html#gb805c6e597fbb1d73233fecf4c050a6e" title="Compute a hash key for a null-terminated string.">csHashCompute</a> ((<span class="keyword">const</span> <span class="keywordtype">char</span>*)key); <a name="l00205"></a>00205 } <a name="l00206"></a>00206 }; <a name="l00207"></a>00207 <a name="l00211"></a>00211 <span class="keyword">template</span><> <a name="l00212"></a><a class="code" href="classcsHashComputer_3_01const_01char_01_5_01_4.html">00212</a> <span class="keyword">class </span><a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><const char*> : <span class="keyword">public</span> <a class="code" href="classcsHashComputerString.html" title="Template that can be used as a base class for hash computers for string types (must...">csHashComputerString<const char*></a> {}; <a name="l00213"></a>00213 <a name="l00223"></a>00223 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00224"></a><a class="code" href="classcsHashComputerStruct.html">00224</a> <span class="keyword">class </span><a class="code" href="classcsHashComputerStruct.html" title="Template that can be used as a base class for hash computers for POD structs.">csHashComputerStruct</a> <a name="l00225"></a>00225 { <a name="l00226"></a>00226 <span class="keyword">public</span>: <a name="l00227"></a><a class="code" href="classcsHashComputerStruct.html#8c433240991a9c1fe9290a16eac844b4">00227</a> <span class="keyword">static</span> <a class="code" href="group__util.html#g91ad9478d81a7aaf2593e8d9c3d06a14" title="Shortcut for default unsigned int.">uint</a> <a class="code" href="classcsHashComputerStruct.html#8c433240991a9c1fe9290a16eac844b4">ComputeHash</a> (<span class="keyword">const</span> T& key) <a name="l00228"></a>00228 { <a name="l00229"></a>00229 <span class="keywordflow">return</span> <a class="code" href="group__util__containers.html#gb805c6e597fbb1d73233fecf4c050a6e" title="Compute a hash key for a null-terminated string.">csHashCompute</a> ((<span class="keywordtype">char</span>*)&key, <span class="keyword">sizeof</span> (T)); <a name="l00230"></a>00230 } <a name="l00231"></a>00231 }; <a name="l00232"></a>00232 <a name="l00233"></a>00233 <a name="l00243"></a>00243 <span class="keyword">template</span> <<span class="keyword">class </span>T, <span class="keyword">class </span>K = <span class="keywordtype">unsigned</span> <a class="code" href="namespaceCS_1_1Threading_1_1Implementation.html#1cd8696cadd16a7d377658879ff61f7a">int</a>, <a name="l00244"></a>00244 <span class="keyword">class </span>ArrayMemoryAlloc = <a class="code" href="classCS_1_1Memory_1_1AllocatorMalloc.html" title="A default memory allocator that allocates with cs_malloc().">CS::Memory::AllocatorMalloc</a>> <a name="l00245"></a><a class="code" href="classcsHash.html">00245</a> <span class="keyword">class </span><a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash</a> <a name="l00246"></a>00246 { <a name="l00247"></a>00247 <span class="keyword">public</span>: <a name="l00248"></a><a class="code" href="classcsHash.html#68fcc3be97e81a486a9477ffbab1bdb5">00248</a> <span class="keyword">typedef</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K, ArrayMemoryAlloc></a> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">ThisType</a>; <a name="l00249"></a><a class="code" href="classcsHash.html#e3754abcf3a8b46b780944dd91b74496">00249</a> <span class="keyword">typedef</span> T <a class="code" href="classcsEventCord.html" title="Event cord.">ValueType</a>; <a name="l00250"></a><a class="code" href="classcsHash.html#c417f7958c3587067a3582fc7a12628c">00250</a> <span class="keyword">typedef</span> K <a class="code" href="classcsHash.html#c417f7958c3587067a3582fc7a12628c">KeyType</a>; <a name="l00251"></a><a class="code" href="classcsHash.html#521e02c32f53de01f88546c384bcacca">00251</a> <span class="keyword">typedef</span> ArrayMemoryAlloc <a class="code" href="classCS_1_1Memory_1_1AllocatorMalloc.html" title="A default memory allocator that allocates with cs_malloc().">AllocatorType</a>; <a name="l00252"></a>00252 <a name="l00253"></a>00253 <span class="keyword">protected</span>: <a name="l00254"></a><a class="code" href="structcsHash_1_1Element.html">00254</a> <span class="keyword">struct </span><a class="code" href="structcsHash_1_1Element.html">Element</a> <a name="l00255"></a>00255 { <a name="l00256"></a><a class="code" href="structcsHash_1_1Element.html#1f89f99ccf2a468f1cdc37c5d79ddb33">00256</a> <span class="keyword">const</span> K <a class="code" href="structcsHash_1_1Element.html#1f89f99ccf2a468f1cdc37c5d79ddb33">key</a>; <a name="l00257"></a><a class="code" href="structcsHash_1_1Element.html#67b6d4b4e8ca9bf07bd85b30297ea766">00257</a> T <a class="code" href="structcsHash_1_1Element.html#67b6d4b4e8ca9bf07bd85b30297ea766">value</a>; <a name="l00258"></a>00258 <a name="l00259"></a><a class="code" href="structcsHash_1_1Element.html#65ff10d56c2e9df5ccc52252cfc72334">00259</a> <a class="code" href="structcsHash_1_1Element.html#65ff10d56c2e9df5ccc52252cfc72334">Element</a> (<span class="keyword">const</span> K& key0, <span class="keyword">const</span> T &value0) : <a class="code" href="structcsHash_1_1Element.html#1f89f99ccf2a468f1cdc37c5d79ddb33">key</a> (key0), <a class="code" href="structcsHash_1_1Element.html#67b6d4b4e8ca9bf07bd85b30297ea766">value</a> (value0) {} <a name="l00260"></a><a class="code" href="structcsHash_1_1Element.html#25b6a89f538fcb9be80efc92a8999d47">00260</a> <a class="code" href="structcsHash_1_1Element.html#65ff10d56c2e9df5ccc52252cfc72334">Element</a> (<span class="keyword">const</span> <a class="code" href="structcsHash_1_1Element.html">Element</a> &other) : <a class="code" href="structcsHash_1_1Element.html#1f89f99ccf2a468f1cdc37c5d79ddb33">key</a> (other.<a class="code" href="structcsHash_1_1Element.html#1f89f99ccf2a468f1cdc37c5d79ddb33">key</a>), <a class="code" href="structcsHash_1_1Element.html#67b6d4b4e8ca9bf07bd85b30297ea766">value</a> (other.<a class="code" href="structcsHash_1_1Element.html#67b6d4b4e8ca9bf07bd85b30297ea766">value</a>) {} <a name="l00261"></a>00261 }; <a name="l00262"></a>00262 <span class="keyword">typedef</span> <a class="code" href="classcsArray.html" title="A templated array class.">csArray<Element, csArrayElementHandler<Element></a>, <a name="l00263"></a><a class="code" href="classcsHash.html#b64d29764ad9127aa67b159119442276">00263</a> ArrayMemoryAlloc> <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>; <a name="l00264"></a>00264 <a class="code" href="classcsArray.html" title="A templated array class.">csArray<ElementArray, csArrayElementHandler<ElementArray></a>, <a name="l00265"></a><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">00265</a> ArrayMemoryAlloc> <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>; <a name="l00266"></a>00266 <a name="l00267"></a><a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">00267</a> <span class="keywordtype">size_t</span> <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>; <a name="l00268"></a>00268 <a name="l00269"></a>00269 <span class="keyword">private</span>: <a name="l00270"></a>00270 <span class="keywordtype">size_t</span> InitModulo; <a name="l00271"></a>00271 <span class="keywordtype">size_t</span> GrowRate; <a name="l00272"></a>00272 <span class="keywordtype">size_t</span> MaxSize; <a name="l00273"></a>00273 <span class="keywordtype">size_t</span> Size; <a name="l00274"></a>00274 <a name="l00275"></a>00275 <span class="keywordtype">void</span> Grow () <a name="l00276"></a>00276 { <a name="l00277"></a>00277 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">size_t</span> Primes[] = <a name="l00278"></a>00278 { <a name="l00279"></a>00279 53, 97, 193, 389, 769, <a name="l00280"></a>00280 1543, 3079, 6151, 12289, 24593, <a name="l00281"></a>00281 49157, 98317, 196613, 393241, 786433, <a name="l00282"></a>00282 1572869, 3145739, 6291469, 12582917, 25165843, <a name="l00283"></a>00283 50331653, 100663319, 201326611, 402653189, 805306457, <a name="l00284"></a>00284 1610612741, 0 <a name="l00285"></a>00285 }; <a name="l00286"></a>00286 <a name="l00287"></a>00287 <span class="keyword">const</span> <span class="keywordtype">size_t</span> *p; <a name="l00288"></a>00288 <span class="keywordtype">size_t</span> elen = <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize (); <a name="l00289"></a>00289 <span class="keywordflow">for</span> (p = Primes; *p && *p <= elen; p++) ; <a name="l00290"></a>00290 <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a> = *p; <a name="l00291"></a>00291 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a> (<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>); <a name="l00292"></a>00292 <a name="l00293"></a>00293 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.SetSize (<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>, <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a> (0, MIN(<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a> / GrowRate, 4))); <a name="l00294"></a>00294 <a name="l00295"></a>00295 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < elen; i++) <a name="l00296"></a>00296 { <a name="l00297"></a>00297 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& src = <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[i]; <a name="l00298"></a>00298 <span class="keywordtype">size_t</span> slen = src.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00299"></a>00299 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> j = slen; j > 0; j--) <a name="l00300"></a>00300 { <a name="l00301"></a>00301 <span class="keyword">const</span> Element& srcElem = src[j - 1]; <a name="l00302"></a>00302 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& dst = <a name="l00303"></a>00303 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.Get (<a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer<K>::ComputeHash</a> (srcElem.key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>); <a name="l00304"></a>00304 <span class="keywordflow">if</span> (&src != &dst) <a name="l00305"></a>00305 { <a name="l00306"></a>00306 dst.<a class="code" href="classcsArray.html#6c1acc9a8bdc9d19272f5236089c6b5b" title="Push a copy of an element onto the tail end of the array.">Push</a> (srcElem); <a name="l00307"></a>00307 src.<a class="code" href="classcsArray.html#10a2afd5172c671fb32c70b4f6e538e8" title="Delete an element from the array.">DeleteIndex</a> (j - 1); <a name="l00308"></a>00308 } <a name="l00309"></a>00309 } <a name="l00310"></a>00310 } <a name="l00311"></a>00311 } <a name="l00312"></a>00312 <a name="l00313"></a>00313 <span class="keyword">public</span>: <a name="l00328"></a><a class="code" href="classcsHash.html#8b46b882e83b872a91afd9b5f0a525da">00328</a> <a class="code" href="classcsHash.html#8b46b882e83b872a91afd9b5f0a525da" title="Construct a hash table with an array of the given size, which for optimisation reasons...">csHash</a> (<span class="keywordtype">size_t</span> size = 23, <span class="keywordtype">size_t</span> grow_rate = 5, <span class="keywordtype">size_t</span> max_size = 20000) <a name="l00329"></a>00329 : <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a> (size), InitModulo (size), <a name="l00330"></a>00330 GrowRate (MIN (grow_rate, size)), MaxSize (max_size), Size (0) <a name="l00331"></a>00331 { <a name="l00332"></a>00332 } <a name="l00333"></a>00333 <a name="l00335"></a><a class="code" href="classcsHash.html#3abf064780ab7b0b830d871561fc53d5">00335</a> <a class="code" href="classcsHash.html#8b46b882e83b872a91afd9b5f0a525da" title="Construct a hash table with an array of the given size, which for optimisation reasons...">csHash</a> (<span class="keyword">const</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T></a> &o) : <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a> (o.<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>), <a name="l00336"></a>00336 <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a> (o.<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>), InitModulo (o.InitModulo), <a name="l00337"></a>00337 GrowRate (o.GrowRate), MaxSize (o.MaxSize), Size (o.Size) {} <a name="l00338"></a>00338 <a name="l00346"></a><a class="code" href="classcsHash.html#25d78ac60667a3f6950ef9212db6a12c">00346</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#25d78ac60667a3f6950ef9212db6a12c" title="Add an element to the hash table.">Put</a> (<span class="keyword">const</span> K& key, <span class="keyword">const</span> T &value) <a name="l00347"></a>00347 { <a name="l00348"></a>00348 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.SetSize (<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>); <a name="l00349"></a>00349 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00350"></a>00350 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00351"></a>00351 values.<a class="code" href="classcsArray.html#6c1acc9a8bdc9d19272f5236089c6b5b" title="Push a copy of an element onto the tail end of the array.">Push</a> (Element (key, value)); <a name="l00352"></a>00352 Size++; <a name="l00353"></a>00353 <span class="keywordflow">if</span> (values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () > <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize () / GrowRate <a name="l00354"></a>00354 && <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize () < MaxSize) Grow (); <a name="l00355"></a>00355 } <a name="l00356"></a>00356 <a name="l00358"></a><a class="code" href="classcsHash.html#7a852c5b0ab7a745795411974890baca">00358</a> <a class="code" href="classcsArray.html" title="A templated array class.">csArray<T></a> <a class="code" href="classcsHash.html#7a852c5b0ab7a745795411974890baca" title="Get all the elements with the given key, or empty if there are none.">GetAll</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00359"></a>00359 <span class="keyword"> </span>{ <a name="l00360"></a>00360 <span class="keywordflow">return</span> GetAll<typename csArray<T>::ElementHandlerType, <a name="l00361"></a>00361 <span class="keyword">typename</span> <a class="code" href="classcsArray.html" title="A templated array class.">csArray<T>::AllocatorType</a>> (key); <a name="l00362"></a>00362 } <a name="l00363"></a>00363 <a name="l00365"></a>00365 <span class="keyword">template</span><<span class="keyword">typename</span> H, <span class="keyword">typename</span> M> <a name="l00366"></a><a class="code" href="classcsHash.html#30b4703285b3ccd21420c2cb6f361229">00366</a> <a class="code" href="classcsArray.html" title="A templated array class.">csArray<T, H, M></a> <a class="code" href="classcsHash.html#7a852c5b0ab7a745795411974890baca" title="Get all the elements with the given key, or empty if there are none.">GetAll</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00367"></a>00367 <span class="keyword"> </span>{ <a name="l00368"></a>00368 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> <a class="code" href="classcsArray.html" title="A templated array class.">csArray<T></a> (); <a name="l00369"></a>00369 <span class="keyword">const</span> <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00370"></a>00370 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00371"></a>00371 <a class="code" href="classcsArray.html" title="A templated array class.">csArray<T></a> ret (values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () / 2); <a name="l00372"></a>00372 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00373"></a>00373 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00374"></a>00374 { <a name="l00375"></a>00375 <span class="keyword">const</span> Element& v = values[i]; <a name="l00376"></a>00376 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00377"></a>00377 ret.<a class="code" href="classcsArray.html#6c1acc9a8bdc9d19272f5236089c6b5b" title="Push a copy of an element onto the tail end of the array.">Push</a> (v.value); <a name="l00378"></a>00378 } <a name="l00379"></a>00379 <span class="keywordflow">return</span> ret; <a name="l00380"></a>00380 } <a name="l00381"></a>00381 <a name="l00383"></a><a class="code" href="classcsHash.html#26669d4e89f8a5615cbb974442cf92ab">00383</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#26669d4e89f8a5615cbb974442cf92ab" title="Add an element to the hash table, overwriting if the key already exists.">PutUnique</a> (<span class="keyword">const</span> K& key, <span class="keyword">const</span> T &value) <a name="l00384"></a>00384 { <a name="l00385"></a>00385 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.SetSize (<a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>); <a name="l00386"></a>00386 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00387"></a>00387 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00388"></a>00388 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00389"></a>00389 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00390"></a>00390 { <a name="l00391"></a>00391 Element& v = values[i]; <a name="l00392"></a>00392 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00393"></a>00393 { <a name="l00394"></a>00394 v.value = value; <a name="l00395"></a>00395 <span class="keywordflow">return</span>; <a name="l00396"></a>00396 } <a name="l00397"></a>00397 } <a name="l00398"></a>00398 <a name="l00399"></a>00399 values.<a class="code" href="classcsArray.html#6c1acc9a8bdc9d19272f5236089c6b5b" title="Push a copy of an element onto the tail end of the array.">Push</a> (Element (key, value)); <a name="l00400"></a>00400 Size++; <a name="l00401"></a>00401 <span class="keywordflow">if</span> (values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () > <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize () / GrowRate <a name="l00402"></a>00402 && <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize () < MaxSize) Grow (); <a name="l00403"></a>00403 } <a name="l00404"></a>00404 <a name="l00406"></a><a class="code" href="classcsHash.html#3d8d0fd5f7f89a201dd107f60fec56ed">00406</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash.html#3d8d0fd5f7f89a201dd107f60fec56ed" title="Returns whether at least one element matches the given key.">Contains</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00407"></a>00407 <span class="keyword"> </span>{ <a name="l00408"></a>00408 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00409"></a>00409 <span class="keyword">const</span> <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00410"></a>00410 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00411"></a>00411 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00412"></a>00412 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00413"></a>00413 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (values[i].key, key) == 0) <a name="l00414"></a>00414 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00415"></a>00415 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00416"></a>00416 } <a name="l00417"></a>00417 <a name="l00423"></a><a class="code" href="classcsHash.html#6ecfc915e059391cc2558c592264b671">00423</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash.html#6ecfc915e059391cc2558c592264b671" title="Returns whether at least one element matches the given key.">In</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00424"></a>00424 <span class="keyword"> </span>{ <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#3d8d0fd5f7f89a201dd107f60fec56ed" title="Returns whether at least one element matches the given key.">Contains</a>(key); } <a name="l00425"></a>00425 <a name="l00430"></a><a class="code" href="classcsHash.html#be068c7c222f4e78640e990a1810b6c5">00430</a> <span class="keyword">const</span> T* <a class="code" href="classcsHash.html#be068c7c222f4e78640e990a1810b6c5" title="Get a pointer to the first element matching the given key, or 0 if there is none...">GetElementPointer</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00431"></a>00431 <span class="keyword"> </span>{ <a name="l00432"></a>00432 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> 0; <a name="l00433"></a>00433 <span class="keyword">const</span> <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00434"></a>00434 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00435"></a>00435 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00436"></a>00436 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00437"></a>00437 { <a name="l00438"></a>00438 <span class="keyword">const</span> Element& v = values[i]; <a name="l00439"></a>00439 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00440"></a>00440 <span class="keywordflow">return</span> &v.value; <a name="l00441"></a>00441 } <a name="l00442"></a>00442 <a name="l00443"></a>00443 <span class="keywordflow">return</span> 0; <a name="l00444"></a>00444 } <a name="l00445"></a>00445 <a name="l00450"></a><a class="code" href="classcsHash.html#486ae42af4fe30feabc7e365aaed99b3">00450</a> T* <a class="code" href="classcsHash.html#be068c7c222f4e78640e990a1810b6c5" title="Get a pointer to the first element matching the given key, or 0 if there is none...">GetElementPointer</a> (<span class="keyword">const</span> K& key) <a name="l00451"></a>00451 { <a name="l00452"></a>00452 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> 0; <a name="l00453"></a>00453 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00454"></a>00454 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00455"></a>00455 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00456"></a>00456 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00457"></a>00457 { <a name="l00458"></a>00458 Element& v = values[i]; <a name="l00459"></a>00459 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00460"></a>00460 <span class="keywordflow">return</span> &v.value; <a name="l00461"></a>00461 } <a name="l00462"></a>00462 <a name="l00463"></a>00463 <span class="keywordflow">return</span> 0; <a name="l00464"></a>00464 } <a name="l00465"></a>00465 <a name="l00469"></a><a class="code" href="classcsHash.html#0bd143a491197e0ba2cd3a2e7bd58ec3">00469</a> T* <a class="code" href="classcsHash.html#0bd143a491197e0ba2cd3a2e7bd58ec3" title="h[&quot;key&quot;] shorthand notation for h.GetElementPoint (&quot;key&quot;)">operator[] </a>(<span class="keyword">const</span> K& key) <a name="l00470"></a>00470 { <a name="l00471"></a>00471 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#be068c7c222f4e78640e990a1810b6c5" title="Get a pointer to the first element matching the given key, or 0 if there is none...">GetElementPointer</a> (key); <a name="l00472"></a>00472 } <a name="l00473"></a>00473 <a name="l00478"></a><a class="code" href="classcsHash.html#2241e61d25ae5030e3e3174bfccc079f">00478</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash.html#2241e61d25ae5030e3e3174bfccc079f" title="Get the first element matching the given key, or fallback if there is none.">Get</a> (<span class="keyword">const</span> K& key, <span class="keyword">const</span> T& fallback)<span class="keyword"> const</span> <a name="l00479"></a>00479 <span class="keyword"> </span>{ <a name="l00480"></a>00480 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> fallback; <a name="l00481"></a>00481 <span class="keyword">const</span> <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00482"></a>00482 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00483"></a>00483 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00484"></a>00484 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00485"></a>00485 { <a name="l00486"></a>00486 <span class="keyword">const</span> Element& v = values[i]; <a name="l00487"></a>00487 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00488"></a>00488 <span class="keywordflow">return</span> v.value; <a name="l00489"></a>00489 } <a name="l00490"></a>00490 <a name="l00491"></a>00491 <span class="keywordflow">return</span> fallback; <a name="l00492"></a>00492 } <a name="l00493"></a>00493 <a name="l00498"></a><a class="code" href="classcsHash.html#c48907570f77a75ab5c216cfec8a5938">00498</a> T& <a class="code" href="classcsHash.html#2241e61d25ae5030e3e3174bfccc079f" title="Get the first element matching the given key, or fallback if there is none.">Get</a> (<span class="keyword">const</span> K& key, T& fallback) <a name="l00499"></a>00499 { <a name="l00500"></a>00500 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> fallback; <a name="l00501"></a>00501 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00502"></a>00502 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00503"></a>00503 <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00504"></a>00504 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < len; ++i) <a name="l00505"></a>00505 { <a name="l00506"></a>00506 Element& v = values[i]; <a name="l00507"></a>00507 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (v.key, key) == 0) <a name="l00508"></a>00508 <span class="keywordflow">return</span> v.value; <a name="l00509"></a>00509 } <a name="l00510"></a>00510 <a name="l00511"></a>00511 <span class="keywordflow">return</span> fallback; <a name="l00512"></a>00512 } <a name="l00513"></a>00513 <a name="l00515"></a><a class="code" href="classcsHash.html#13f7704179600401bcf337a9130c5480">00515</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#13f7704179600401bcf337a9130c5480" title="Delete all the elements.">DeleteAll</a> () <a name="l00516"></a>00516 { <a name="l00517"></a>00517 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.DeleteAll(); <a name="l00518"></a>00518 <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a> = InitModulo; <a name="l00519"></a>00519 Size = 0; <a name="l00520"></a>00520 } <a name="l00521"></a>00521 <a name="l00523"></a><a class="code" href="classcsHash.html#f5fe9d4c1fa175c3d0fc718566e6c801">00523</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#f5fe9d4c1fa175c3d0fc718566e6c801" title="Delete all the elements. (Idiomatic alias for DeleteAll().).">Empty</a>() { <a class="code" href="classcsHash.html#13f7704179600401bcf337a9130c5480" title="Delete all the elements.">DeleteAll</a>(); } <a name="l00524"></a>00524 <a name="l00526"></a><a class="code" href="classcsHash.html#8c60faf9a893528d3479d8ede5920134">00526</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash.html#13f7704179600401bcf337a9130c5480" title="Delete all the elements.">DeleteAll</a> (<span class="keyword">const</span> K& key) <a name="l00527"></a>00527 { <a name="l00528"></a>00528 <span class="keywordtype">bool</span> ret = <span class="keyword">false</span>; <a name="l00529"></a>00529 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> ret; <a name="l00530"></a>00530 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00531"></a>00531 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00532"></a>00532 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); i > 0; i--) <a name="l00533"></a>00533 { <a name="l00534"></a>00534 <span class="keyword">const</span> <span class="keywordtype">size_t</span> idx = i - 1; <a name="l00535"></a>00535 <span class="keywordflow">if</span> (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (values[idx].key, key) == 0) <a name="l00536"></a>00536 { <a name="l00537"></a>00537 values.<a class="code" href="classcsArray.html#a82497a8ba6e336fa16a1d86f245d07e" title="Delete an element from the array in constant-time, regardless of the array&#39;s...">DeleteIndexFast</a> (idx); <a name="l00538"></a>00538 ret = <span class="keyword">true</span>; <a name="l00539"></a>00539 Size--; <a name="l00540"></a>00540 } <a name="l00541"></a>00541 } <a name="l00542"></a>00542 <span class="keywordflow">return</span> ret; <a name="l00543"></a>00543 } <a name="l00544"></a>00544 <a name="l00546"></a><a class="code" href="classcsHash.html#0a7f8b2b8f46fcd915037d31b1e8fedb">00546</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash.html#0a7f8b2b8f46fcd915037d31b1e8fedb" title="Delete all the elements matching the given key and value.">Delete</a> (<span class="keyword">const</span> K& key, <span class="keyword">const</span> T &value) <a name="l00547"></a>00547 { <a name="l00548"></a>00548 <span class="keywordtype">bool</span> ret = <span class="keyword">false</span>; <a name="l00549"></a>00549 <span class="keywordflow">if</span> (<a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize() == 0) <span class="keywordflow">return</span> ret; <a name="l00550"></a>00550 <a class="code" href="classcsArray.html" title="A templated array class.">ElementArray</a>& values = <a name="l00551"></a>00551 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[<a class="code" href="classcsHashComputer.html#28098b758683db0027dd7fafb900096b" title="Compute a hash value for key.">csHashComputer<K>::ComputeHash</a> (key) % <a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>]; <a name="l00552"></a>00552 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = values.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); i > 0; i--) <a name="l00553"></a>00553 { <a name="l00554"></a>00554 <span class="keyword">const</span> <span class="keywordtype">size_t</span> idx = i - 1; <a name="l00555"></a>00555 <span class="keywordflow">if</span> ((<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (values[idx].key, key) == 0) && <a name="l00556"></a>00556 (<a class="code" href="classcsComparator.html#91f6c9cfaa52ebbc6245dc0ba5f944d7" title="Compare two objects of the same type or different types (T1 and T2).">csComparator<T, T>::Compare</a> (values[idx].value, value) == 0 )) <a name="l00557"></a>00557 { <a name="l00558"></a>00558 values.<a class="code" href="classcsArray.html#a82497a8ba6e336fa16a1d86f245d07e" title="Delete an element from the array in constant-time, regardless of the array&#39;s...">DeleteIndexFast</a> (idx); <a name="l00559"></a>00559 ret = <span class="keyword">true</span>; <a name="l00560"></a>00560 Size--; <a name="l00561"></a>00561 } <a name="l00562"></a>00562 } <a name="l00563"></a>00563 <span class="keywordflow">return</span> ret; <a name="l00564"></a>00564 } <a name="l00565"></a>00565 <a name="l00567"></a><a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e">00567</a> <span class="keywordtype">size_t</span> <a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a> ()<span class="keyword"> const</span> <a name="l00568"></a>00568 <span class="keyword"> </span>{ <a name="l00569"></a>00569 <span class="keywordflow">return</span> Size; <a name="l00570"></a>00570 } <a name="l00571"></a>00571 <a name="l00577"></a><a class="code" href="classcsHash.html#e67b2dfd18740126a3866d9d4fbb391c">00577</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash.html#e67b2dfd18740126a3866d9d4fbb391c" title="Return true if the hash is empty.">IsEmpty</a>()<span class="keyword"> const</span> <a name="l00578"></a>00578 <span class="keyword"> </span>{ <a name="l00579"></a>00579 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a>() == 0; <a name="l00580"></a>00580 } <a name="l00581"></a>00581 <a name="l00583"></a><a class="code" href="classcsHash_1_1Iterator.html">00583</a> <span class="keyword">class </span><a class="code" href="classcsHash_1_1Iterator.html" title="An iterator class for the hash.">Iterator</a> <a name="l00584"></a>00584 { <a name="l00585"></a>00585 <span class="keyword">private</span>: <a name="l00586"></a>00586 <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a>* hash; <a name="l00587"></a>00587 <span class="keyword">const</span> K key; <a name="l00588"></a>00588 <span class="keywordtype">size_t</span> bucket, size, element; <a name="l00589"></a>00589 <a name="l00590"></a>00590 <span class="keywordtype">void</span> Seek () <a name="l00591"></a>00591 { <a name="l00592"></a>00592 <span class="keywordflow">while</span> ((element < size) && <a name="l00593"></a>00593 (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key, <a name="l00594"></a>00594 key) != 0)) <a name="l00595"></a>00595 element++; <a name="l00596"></a>00596 } <a name="l00597"></a>00597 <a name="l00598"></a>00598 <span class="keyword">protected</span>: <a name="l00599"></a><a class="code" href="classcsHash_1_1Iterator.html#bec50fe1022ca70cf2c814329879fef1">00599</a> <a class="code" href="classcsHash_1_1Iterator.html#bec50fe1022ca70cf2c814329879fef1">Iterator</a> (<a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a>* hash0, <span class="keyword">const</span> K& key0) : <a name="l00600"></a>00600 hash(hash0), <a name="l00601"></a>00601 key(key0), <a name="l00602"></a>00602 bucket(<a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><K>::ComputeHash (key) % hash-><a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>), <a name="l00603"></a>00603 size((hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a>() > 0) ? hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket].<a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a> () : 0) <a name="l00604"></a>00604 { <a class="code" href="classcsHash_1_1Iterator.html#0b0f206c8cc31837cf2fd3817fdbcd16" title="Move the iterator back to the first element.">Reset</a> (); } <a name="l00605"></a>00605 <a name="l00606"></a><a class="code" href="classcsHash_1_1Iterator.html#bac4f17a9a41bec8a2ccd12f2e624f66">00606</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash</a><T, K>; <a name="l00607"></a>00607 <span class="keyword">public</span>: <a name="l00609"></a><a class="code" href="classcsHash_1_1Iterator.html#c289e2cc07c8516e20ab94200310bd8b">00609</a> <a class="code" href="classcsHash_1_1Iterator.html#bec50fe1022ca70cf2c814329879fef1">Iterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash_1_1Iterator.html" title="An iterator class for the hash.">Iterator</a> &o) : <a name="l00610"></a>00610 hash (o.hash), <a name="l00611"></a>00611 key(o.key), <a name="l00612"></a>00612 bucket(o.bucket), <a name="l00613"></a>00613 size(o.size), <a name="l00614"></a>00614 element(o.element) {} <a name="l00615"></a>00615 <a name="l00617"></a><a class="code" href="classcsHash_1_1Iterator.html#b8bc59d0a94c01cbfa6d1e187374a829">00617</a> <a class="code" href="classcsHash_1_1Iterator.html" title="An iterator class for the hash.">Iterator</a>& <a class="code" href="classcsHash_1_1Iterator.html#b8bc59d0a94c01cbfa6d1e187374a829" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classcsHash_1_1Iterator.html" title="An iterator class for the hash.">Iterator</a>& o) <a name="l00618"></a>00618 { <a name="l00619"></a>00619 hash = o.<a class="code" href="classcsHash_1_1Iterator.html#5711bad8f64251c19a869b58edc516f7">hash</a>; <a name="l00620"></a>00620 key = o.<a class="code" href="classcsHash_1_1Iterator.html#710750dd96745e4bb0a213ed6522c1e4">key</a>; <a name="l00621"></a>00621 bucket = o.<a class="code" href="classcsHash_1_1Iterator.html#f06b29189f92b068c39584b978ff64b3">bucket</a>; <a name="l00622"></a>00622 size = o.<a class="code" href="classcsHash_1_1Iterator.html#785765c881278fd4a61c97950a28c35c">size</a>; <a name="l00623"></a>00623 element = o.<a class="code" href="classcsHash_1_1Iterator.html#8a1a3efab762c97d8d798e0930ad352b">element</a>; <a name="l00624"></a>00624 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00625"></a>00625 } <a name="l00626"></a>00626 <a name="l00628"></a><a class="code" href="classcsHash_1_1Iterator.html#47e0d5859bcad8b5e04f5e53ba8b5f45">00628</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash_1_1Iterator.html#47e0d5859bcad8b5e04f5e53ba8b5f45" title="Returns a boolean indicating whether or not the hash has more elements.">HasNext</a> ()<span class="keyword"> const</span> <a name="l00629"></a>00629 <span class="keyword"> </span>{ <a name="l00630"></a>00630 <span class="keywordflow">return</span> element < size; <a name="l00631"></a>00631 } <a name="l00632"></a>00632 <a name="l00634"></a><a class="code" href="classcsHash_1_1Iterator.html#e7f2fff8860fac5d7357ae7ac8c34cd5">00634</a> T& <a class="code" href="classcsHash_1_1Iterator.html#e7f2fff8860fac5d7357ae7ac8c34cd5" title="Get the next element&#39;s value.">Next</a> () <a name="l00635"></a>00635 { <a name="l00636"></a>00636 T &ret = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].value; <a name="l00637"></a>00637 element++; <a name="l00638"></a>00638 Seek (); <a name="l00639"></a>00639 <span class="keywordflow">return</span> ret; <a name="l00640"></a>00640 } <a name="l00641"></a>00641 <a name="l00643"></a><a class="code" href="classcsHash_1_1Iterator.html#0b0f206c8cc31837cf2fd3817fdbcd16">00643</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1Iterator.html#0b0f206c8cc31837cf2fd3817fdbcd16" title="Move the iterator back to the first element.">Reset</a> () { element = 0; Seek (); } <a name="l00644"></a>00644 }; <a name="l00645"></a><a class="code" href="classcsHash.html#9830fc407400559db7e7783cc10a9394">00645</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html#9830fc407400559db7e7783cc10a9394">Iterator</a>; <a name="l00646"></a>00646 <a name="l00648"></a><a class="code" href="classcsHash_1_1GlobalIterator.html">00648</a> <span class="keyword">class </span><a class="code" href="classcsHash_1_1GlobalIterator.html" title="An iterator class for the hash.">GlobalIterator</a> <a name="l00649"></a>00649 { <a name="l00650"></a>00650 <span class="keyword">private</span>: <a name="l00651"></a>00651 <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a> *hash; <a name="l00652"></a>00652 <span class="keywordtype">size_t</span> bucket, size, element; <a name="l00653"></a>00653 <a name="l00654"></a>00654 <span class="keywordtype">void</span> Zero () { bucket = element = 0; } <a name="l00655"></a>00655 <span class="keywordtype">void</span> Init () <a name="l00656"></a>00656 { <a name="l00657"></a>00657 size = <a name="l00658"></a>00658 (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a>() > 0) ? hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket].<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () : 0; <a name="l00659"></a>00659 } <a name="l00660"></a>00660 <a name="l00661"></a>00661 <span class="keywordtype">void</span> FindItem () <a name="l00662"></a>00662 { <a name="l00663"></a>00663 <span class="keywordflow">if</span> (element >= size) <a name="l00664"></a>00664 { <a name="l00665"></a>00665 <span class="keywordflow">while</span> (++bucket < hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize ()) <a name="l00666"></a>00666 { <a name="l00667"></a>00667 Init (); <a name="l00668"></a>00668 <span class="keywordflow">if</span> (size != 0) <a name="l00669"></a>00669 { <a name="l00670"></a>00670 element = 0; <a name="l00671"></a>00671 <span class="keywordflow">break</span>; <a name="l00672"></a>00672 } <a name="l00673"></a>00673 } <a name="l00674"></a>00674 } <a name="l00675"></a>00675 } <a name="l00676"></a>00676 <a name="l00677"></a>00677 <span class="keyword">protected</span>: <a name="l00678"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#81cac1527d7a7920273e9c308175e1d7">00678</a> <a class="code" href="classcsHash_1_1GlobalIterator.html#81cac1527d7a7920273e9c308175e1d7">GlobalIterator</a> (<a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a> *hash0) : hash (hash0) <a name="l00679"></a>00679 { <a name="l00680"></a>00680 Zero (); <a name="l00681"></a>00681 Init (); <a name="l00682"></a>00682 FindItem (); <a name="l00683"></a>00683 } <a name="l00684"></a>00684 <a name="l00685"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#bac4f17a9a41bec8a2ccd12f2e624f66">00685</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash</a><T, K>; <a name="l00686"></a>00686 <span class="keyword">public</span>: <a name="l00688"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#f93d99d3c16080f6d30bf484ba52cc70">00688</a> <a class="code" href="classcsHash_1_1GlobalIterator.html#81cac1527d7a7920273e9c308175e1d7">GlobalIterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash_1_1GlobalIterator.html" title="An iterator class for the hash.">GlobalIterator</a> &o) : <a name="l00689"></a>00689 hash (o.hash), <a name="l00690"></a>00690 bucket (o.bucket), <a name="l00691"></a>00691 size (o.size), <a name="l00692"></a>00692 element (o.element) {} <a name="l00693"></a>00693 <a name="l00695"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#89ae88d4276faa0e175f89bb43a61600">00695</a> <a class="code" href="classcsHash_1_1GlobalIterator.html" title="An iterator class for the hash.">GlobalIterator</a>& <a class="code" href="classcsHash_1_1GlobalIterator.html#89ae88d4276faa0e175f89bb43a61600" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classcsHash_1_1GlobalIterator.html" title="An iterator class for the hash.">GlobalIterator</a>& o) <a name="l00696"></a>00696 { <a name="l00697"></a>00697 hash = o.<a class="code" href="classcsHash_1_1GlobalIterator.html#50f27c757c681f73d8bbde89e5e2ecd7">hash</a>; <a name="l00698"></a>00698 bucket = o.<a class="code" href="classcsHash_1_1GlobalIterator.html#060b8450aa4bf3fd78a207a5e541228a">bucket</a>; <a name="l00699"></a>00699 size = o.<a class="code" href="classcsHash_1_1GlobalIterator.html#3111e020780366b684ab32cbdd7ea311">size</a>; <a name="l00700"></a>00700 element = o.<a class="code" href="classcsHash_1_1GlobalIterator.html#3c39898165b4998a6582e12586fa4234">element</a>; <a name="l00701"></a>00701 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00702"></a>00702 } <a name="l00703"></a>00703 <a name="l00705"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#e45862acea507ff84122338174c49eec">00705</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash_1_1GlobalIterator.html#e45862acea507ff84122338174c49eec" title="Returns a boolean indicating whether or not the hash has more elements.">HasNext</a> ()<span class="keyword"> const</span> <a name="l00706"></a>00706 <span class="keyword"> </span>{ <a name="l00707"></a>00707 <span class="keywordflow">if</span> (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () == 0) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00708"></a>00708 <span class="keywordflow">return</span> element < size || bucket < hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00709"></a>00709 } <a name="l00710"></a>00710 <a name="l00712"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#230496a7f6abfdfca1909c099d93c293">00712</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1GlobalIterator.html#230496a7f6abfdfca1909c099d93c293" title="Advance the iterator of one step.">Advance</a> () <a name="l00713"></a>00713 { <a name="l00714"></a>00714 element++; <a name="l00715"></a>00715 FindItem (); <a name="l00716"></a>00716 } <a name="l00717"></a>00717 <a name="l00719"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c">00719</a> T& <a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> () <a name="l00720"></a>00720 { <a name="l00721"></a>00721 <span class="keywordflow">return</span> hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].value; <a name="l00722"></a>00722 } <a name="l00723"></a>00723 <a name="l00725"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#ef988640dcf3b817690d2dd38ea09af3">00725</a> T& <a class="code" href="classcsHash_1_1GlobalIterator.html#ef988640dcf3b817690d2dd38ea09af3" title="Get the next element&#39;s value.">Next</a> () <a name="l00726"></a>00726 { <a name="l00727"></a>00727 T &ret = <a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (); <a name="l00728"></a>00728 <a class="code" href="classcsHash_1_1GlobalIterator.html#230496a7f6abfdfca1909c099d93c293" title="Advance the iterator of one step.">Advance</a> (); <a name="l00729"></a>00729 <span class="keywordflow">return</span> ret; <a name="l00730"></a>00730 } <a name="l00731"></a>00731 <a name="l00733"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#bba7250accf72378ca6fd895af7b2398">00733</a> T& <a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (K &key) <a name="l00734"></a>00734 { <a name="l00735"></a>00735 key = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key; <a name="l00736"></a>00736 <span class="keywordflow">return</span> <a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (); <a name="l00737"></a>00737 } <a name="l00738"></a>00738 <a name="l00740"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#32144f2a0323ebed9a73f1da6171fd0f">00740</a> T& <a class="code" href="classcsHash_1_1GlobalIterator.html#ef988640dcf3b817690d2dd38ea09af3" title="Get the next element&#39;s value.">Next</a> (K &key) <a name="l00741"></a>00741 { <a name="l00742"></a>00742 key = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key; <a name="l00743"></a>00743 <span class="keywordflow">return</span> <a class="code" href="classcsHash_1_1GlobalIterator.html#ef988640dcf3b817690d2dd38ea09af3" title="Get the next element&#39;s value.">Next</a> (); <a name="l00744"></a>00744 } <a name="l00745"></a>00745 <a name="l00747"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#26f18d1f391d560abaeeac805b52151a">00747</a> <span class="keyword">const</span> <a class="code" href="classcsTuple2.html" title="A two length tuple (fixed size collection of elements) Tuples are typically used...">csTuple2<T, K></a> <a class="code" href="classcsHash_1_1GlobalIterator.html#26f18d1f391d560abaeeac805b52151a" title="Return a tuple of the value and key.">NextTuple</a> () <a name="l00748"></a>00748 { <a name="l00749"></a>00749 <a class="code" href="classcsTuple2.html" title="A two length tuple (fixed size collection of elements) Tuples are typically used...">csTuple2<T, K></a> t (<a class="code" href="classcsHash_1_1GlobalIterator.html#bd47bc70a761f693ba261399d514e31c" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (), <a name="l00750"></a>00750 hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key); <a name="l00751"></a>00751 <a class="code" href="classcsHash_1_1GlobalIterator.html#230496a7f6abfdfca1909c099d93c293" title="Advance the iterator of one step.">Advance</a> (); <a name="l00752"></a>00752 <span class="keywordflow">return</span> t; <a name="l00753"></a>00753 } <a name="l00754"></a>00754 <a name="l00756"></a><a class="code" href="classcsHash_1_1GlobalIterator.html#7335bde361cdbbbd96e9404976f08d83">00756</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1GlobalIterator.html#7335bde361cdbbbd96e9404976f08d83" title="Move the iterator back to the first element.">Reset</a> () { Zero (); Init (); FindItem (); } <a name="l00757"></a>00757 }; <a name="l00758"></a><a class="code" href="classcsHash.html#594373255032048e48ada9ba4e8b6e0f">00758</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html#594373255032048e48ada9ba4e8b6e0f">GlobalIterator</a>; <a name="l00759"></a>00759 <a name="l00761"></a><a class="code" href="classcsHash_1_1ConstIterator.html">00761</a> <span class="keyword">class </span><a class="code" href="classcsHash_1_1ConstIterator.html" title="An const iterator class for the hash.">ConstIterator</a> <a name="l00762"></a>00762 { <a name="l00763"></a>00763 <span class="keyword">private</span>: <a name="l00764"></a>00764 <span class="keyword">const</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a>* hash; <a name="l00765"></a>00765 <span class="keyword">const</span> K key; <a name="l00766"></a>00766 <span class="keywordtype">size_t</span> bucket, size, element; <a name="l00767"></a>00767 <a name="l00768"></a>00768 <span class="keywordtype">void</span> Seek () <a name="l00769"></a>00769 { <a name="l00770"></a>00770 <span class="keywordflow">while</span> ((element < size) && <a name="l00771"></a>00771 (<a class="code" href="classcsComparator.html" title="A template providing various comparison and ordering functions.">csComparator<K, K>::Compare</a> (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key, <a name="l00772"></a>00772 key) != 0)) <a name="l00773"></a>00773 element++; <a name="l00774"></a>00774 } <a name="l00775"></a>00775 <a name="l00776"></a>00776 <span class="keyword">protected</span>: <a name="l00777"></a><a class="code" href="classcsHash_1_1ConstIterator.html#efce995a2cb758f0f6c1afd873c14551">00777</a> <a class="code" href="classcsHash_1_1ConstIterator.html#efce995a2cb758f0f6c1afd873c14551">ConstIterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a>* hash0, <span class="keyword">const</span> K& key0) : <a name="l00778"></a>00778 hash(hash0), <a name="l00779"></a>00779 key(key0), <a name="l00780"></a>00780 bucket(<a class="code" href="classcsHashComputer.html" title="Template for hash value computing.">csHashComputer</a><K>::ComputeHash (key) % hash-><a class="code" href="classcsHash.html#905c6b082d89cf34a3ecb050b0236cfe">Modulo</a>), <a name="l00781"></a>00781 size((hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a>() > 0) ? hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket].<a class="code" href="classcsHash.html#c0e6f8aea25fa59de886e3d85bd4ea9e" title="Get the number of elements in the hash.">GetSize</a> () : 0) <a name="l00782"></a>00782 { <a class="code" href="classcsHash_1_1ConstIterator.html#ddb83543e460d533db84b08d5b8ba007" title="Move the iterator back to the first element.">Reset</a> (); } <a name="l00783"></a>00783 <a name="l00784"></a><a class="code" href="classcsHash_1_1ConstIterator.html#bac4f17a9a41bec8a2ccd12f2e624f66">00784</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash</a><T, K>; <a name="l00785"></a>00785 <span class="keyword">public</span>: <a name="l00787"></a><a class="code" href="classcsHash_1_1ConstIterator.html#859a534bcb0f3b6777d8a5edd596f393">00787</a> <a class="code" href="classcsHash_1_1ConstIterator.html#efce995a2cb758f0f6c1afd873c14551">ConstIterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash_1_1ConstIterator.html" title="An const iterator class for the hash.">ConstIterator</a> &o) : <a name="l00788"></a>00788 hash (o.hash), <a name="l00789"></a>00789 key(o.key), <a name="l00790"></a>00790 bucket(o.bucket), <a name="l00791"></a>00791 size(o.size), <a name="l00792"></a>00792 element(o.element) {} <a name="l00793"></a>00793 <a name="l00795"></a><a class="code" href="classcsHash_1_1ConstIterator.html#0717e8eb5d95f8c8c8df739a20c2936b">00795</a> <a class="code" href="classcsHash_1_1ConstIterator.html" title="An const iterator class for the hash.">ConstIterator</a>& <a class="code" href="classcsHash_1_1ConstIterator.html#0717e8eb5d95f8c8c8df739a20c2936b" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classcsHash_1_1ConstIterator.html" title="An const iterator class for the hash.">ConstIterator</a>& o) <a name="l00796"></a>00796 { <a name="l00797"></a>00797 hash = o.<a class="code" href="classcsHash_1_1ConstIterator.html#822d70c3f133278c69bda0e24300d84f">hash</a>; <a name="l00798"></a>00798 key = o.<a class="code" href="classcsHash_1_1ConstIterator.html#c278b6c681962d5f02e63bee5d86cd5f">key</a>; <a name="l00799"></a>00799 bucket = o.<a class="code" href="classcsHash_1_1ConstIterator.html#f2ae192006d06edef3f98a7e5abcc4c0">bucket</a>; <a name="l00800"></a>00800 size = o.<a class="code" href="classcsHash_1_1ConstIterator.html#92d6e22196ceecee96a0b82b7715cd1b">size</a>; <a name="l00801"></a>00801 element = o.<a class="code" href="classcsHash_1_1ConstIterator.html#e0e7d94f1e118f94f11d9b113e8c96ba">element</a>; <a name="l00802"></a>00802 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00803"></a>00803 } <a name="l00804"></a>00804 <a name="l00806"></a><a class="code" href="classcsHash_1_1ConstIterator.html#ace64b256ad94c42a3cddeede9ac4f7f">00806</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash_1_1ConstIterator.html#ace64b256ad94c42a3cddeede9ac4f7f" title="Returns a boolean indicating whether or not the hash has more elements.">HasNext</a> ()<span class="keyword"> const</span> <a name="l00807"></a>00807 <span class="keyword"> </span>{ <a name="l00808"></a>00808 <span class="keywordflow">return</span> element < size; <a name="l00809"></a>00809 } <a name="l00810"></a>00810 <a name="l00812"></a><a class="code" href="classcsHash_1_1ConstIterator.html#655b9a235acdf433602c6a3c826aff5e">00812</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash_1_1ConstIterator.html#655b9a235acdf433602c6a3c826aff5e" title="Get the next element&#39;s value.">Next</a> () <a name="l00813"></a>00813 { <a name="l00814"></a>00814 <span class="keyword">const</span> T &ret = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].value; <a name="l00815"></a>00815 element++; <a name="l00816"></a>00816 Seek (); <a name="l00817"></a>00817 <span class="keywordflow">return</span> ret; <a name="l00818"></a>00818 } <a name="l00819"></a>00819 <a name="l00821"></a><a class="code" href="classcsHash_1_1ConstIterator.html#ddb83543e460d533db84b08d5b8ba007">00821</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1ConstIterator.html#ddb83543e460d533db84b08d5b8ba007" title="Move the iterator back to the first element.">Reset</a> () { element = 0; Seek (); } <a name="l00822"></a>00822 }; <a name="l00823"></a><a class="code" href="classcsHash.html#5485970bb9da6b5d782fa28638b5658f">00823</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html#5485970bb9da6b5d782fa28638b5658f">ConstIterator</a>; <a name="l00824"></a>00824 <a name="l00826"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html">00826</a> <span class="keyword">class </span><a class="code" href="classcsHash_1_1ConstGlobalIterator.html" title="An const iterator class for the hash.">ConstGlobalIterator</a> <a name="l00827"></a>00827 { <a name="l00828"></a>00828 <span class="keyword">private</span>: <a name="l00829"></a>00829 <span class="keyword">const</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a> *hash; <a name="l00830"></a>00830 <span class="keywordtype">size_t</span> bucket, size, element; <a name="l00831"></a>00831 <a name="l00832"></a>00832 <span class="keywordtype">void</span> Zero () { bucket = element = 0; } <a name="l00833"></a>00833 <span class="keywordtype">void</span> Init () <a name="l00834"></a>00834 { <a name="l00835"></a>00835 size = <a name="l00836"></a>00836 (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a>() > 0) ? hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket].<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () : 0; <a name="l00837"></a>00837 } <a name="l00838"></a>00838 <a name="l00839"></a>00839 <span class="keywordtype">void</span> FindItem () <a name="l00840"></a>00840 { <a name="l00841"></a>00841 <span class="keywordflow">if</span> (element >= size) <a name="l00842"></a>00842 { <a name="l00843"></a>00843 <span class="keywordflow">while</span> (++bucket < hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.GetSize ()) <a name="l00844"></a>00844 { <a name="l00845"></a>00845 Init (); <a name="l00846"></a>00846 <span class="keywordflow">if</span> (size != 0) <a name="l00847"></a>00847 { <a name="l00848"></a>00848 element = 0; <a name="l00849"></a>00849 <span class="keywordflow">break</span>; <a name="l00850"></a>00850 } <a name="l00851"></a>00851 } <a name="l00852"></a>00852 } <a name="l00853"></a>00853 } <a name="l00854"></a>00854 <a name="l00855"></a>00855 <span class="keyword">protected</span>: <a name="l00856"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#7ab04eaa35b89b00279f51c11705ffcf">00856</a> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#7ab04eaa35b89b00279f51c11705ffcf">ConstGlobalIterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash<T, K></a> *hash0) : hash (hash0) <a name="l00857"></a>00857 { <a name="l00858"></a>00858 Zero (); <a name="l00859"></a>00859 Init (); <a name="l00860"></a>00860 FindItem (); <a name="l00861"></a>00861 } <a name="l00862"></a>00862 <a name="l00863"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#bac4f17a9a41bec8a2ccd12f2e624f66">00863</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html" title="A generic hash table class, which grows dynamically and whose buckets are unsorted...">csHash</a><T, K>; <a name="l00864"></a>00864 <span class="keyword">public</span>: <a name="l00866"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#30d1acc653933f1f8304774d0f4ea545">00866</a> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#7ab04eaa35b89b00279f51c11705ffcf">ConstGlobalIterator</a> (<span class="keyword">const</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html" title="An const iterator class for the hash.">ConstGlobalIterator</a> &o) : <a name="l00867"></a>00867 hash (o.hash), <a name="l00868"></a>00868 bucket (o.bucket), <a name="l00869"></a>00869 size (o.size), <a name="l00870"></a>00870 element (o.element) {} <a name="l00871"></a>00871 <a name="l00873"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#8712f94ade2834072035fdb413ad3a55">00873</a> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html" title="An const iterator class for the hash.">ConstGlobalIterator</a>& <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#8712f94ade2834072035fdb413ad3a55" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html" title="An const iterator class for the hash.">ConstGlobalIterator</a>& o) <a name="l00874"></a>00874 { <a name="l00875"></a>00875 hash = o.<a class="code" href="classcsHash_1_1ConstGlobalIterator.html#988827e26449a72ba22c359da91c924c">hash</a>; <a name="l00876"></a>00876 bucket = o.<a class="code" href="classcsHash_1_1ConstGlobalIterator.html#874509977d1af0707d650fecc4aa2cfb">bucket</a>; <a name="l00877"></a>00877 size = o.<a class="code" href="classcsHash_1_1ConstGlobalIterator.html#960b73a230096b5a2cf4647df18d2513">size</a>; <a name="l00878"></a>00878 element = o.<a class="code" href="classcsHash_1_1ConstGlobalIterator.html#b19b9faed5cdcc4f8e933d2758c856b0">element</a>; <a name="l00879"></a>00879 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00880"></a>00880 } <a name="l00881"></a>00881 <a name="l00883"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#8fde9c33defeccec5a967951f3ba4e43">00883</a> <span class="keywordtype">bool</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#8fde9c33defeccec5a967951f3ba4e43" title="Returns a boolean indicating whether or not the hash has more elements.">HasNext</a> ()<span class="keyword"> const</span> <a name="l00884"></a>00884 <span class="keyword"> </span>{ <a name="l00885"></a>00885 <span class="keywordflow">if</span> (hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> () == 0) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00886"></a>00886 <span class="keywordflow">return</span> element < size || bucket < hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>.<a class="code" href="classcsArray.html#d9707ffab9a7c3f30f76189f6a1ac7c2" title="Return the number of elements in the array.">GetSize</a> (); <a name="l00887"></a>00887 } <a name="l00888"></a>00888 <a name="l00890"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#3f2ecc2196fbff8a959461a8ce9edc67">00890</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#3f2ecc2196fbff8a959461a8ce9edc67" title="Advance the iterator of one step.">Advance</a> () <a name="l00891"></a>00891 { <a name="l00892"></a>00892 element++; <a name="l00893"></a>00893 FindItem (); <a name="l00894"></a>00894 } <a name="l00895"></a>00895 <a name="l00897"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f">00897</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> () <a name="l00898"></a>00898 { <a name="l00899"></a>00899 <span class="keywordflow">return</span> hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].value; <a name="l00900"></a>00900 } <a name="l00901"></a>00901 <a name="l00903"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#9b0aa0b39c1903ead266d9d69c069f3a">00903</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#9b0aa0b39c1903ead266d9d69c069f3a" title="Get the next element&#39;s value.">Next</a> () <a name="l00904"></a>00904 { <a name="l00905"></a>00905 <span class="keyword">const</span> T &ret = <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (); <a name="l00906"></a>00906 <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#3f2ecc2196fbff8a959461a8ce9edc67" title="Advance the iterator of one step.">Advance</a> (); <a name="l00907"></a>00907 <span class="keywordflow">return</span> ret; <a name="l00908"></a>00908 } <a name="l00909"></a>00909 <a name="l00911"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#28e291bfd8c6fd3629794a26703a7c64">00911</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (K &key) <a name="l00912"></a>00912 { <a name="l00913"></a>00913 key = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key; <a name="l00914"></a>00914 <span class="keywordflow">return</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (); <a name="l00915"></a>00915 } <a name="l00916"></a>00916 <a name="l00918"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#ac1736e2487117b7a5e019a9c4eeb0c2">00918</a> <span class="keyword">const</span> T& <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#9b0aa0b39c1903ead266d9d69c069f3a" title="Get the next element&#39;s value.">Next</a> (K &key) <a name="l00919"></a>00919 { <a name="l00920"></a>00920 key = hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key; <a name="l00921"></a>00921 <span class="keywordflow">return</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#9b0aa0b39c1903ead266d9d69c069f3a" title="Get the next element&#39;s value.">Next</a> (); <a name="l00922"></a>00922 } <a name="l00923"></a>00923 <a name="l00925"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#97442a5a04b41335bf097e139f7707df">00925</a> <span class="keyword">const</span> <a class="code" href="classcsTuple2.html" title="A two length tuple (fixed size collection of elements) Tuples are typically used...">csTuple2<T, K></a> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#97442a5a04b41335bf097e139f7707df" title="Return a tuple of the value and key.">NextTuple</a> () <a name="l00926"></a>00926 { <a name="l00927"></a>00927 <a class="code" href="classcsTuple2.html" title="A two length tuple (fixed size collection of elements) Tuples are typically used...">csTuple2<T, K></a> t (<a class="code" href="classcsHash_1_1ConstGlobalIterator.html#1f48c0e4bd0a9144946fe9bc9345351f" title="Get the next element&#39;s value, don&#39;t move the iterator.">NextNoAdvance</a> (), <a name="l00928"></a>00928 hash-><a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[bucket][element].key); <a name="l00929"></a>00929 <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#3f2ecc2196fbff8a959461a8ce9edc67" title="Advance the iterator of one step.">Advance</a> (); <a name="l00930"></a>00930 <span class="keywordflow">return</span> t; <a name="l00931"></a>00931 } <a name="l00932"></a>00932 <a name="l00934"></a><a class="code" href="classcsHash_1_1ConstGlobalIterator.html#06e532864f70fa0325633bcb036f3c84">00934</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash_1_1ConstGlobalIterator.html#06e532864f70fa0325633bcb036f3c84" title="Move the iterator back to the first element.">Reset</a> () { Zero (); Init (); FindItem (); } <a name="l00935"></a>00935 }; <a name="l00936"></a><a class="code" href="classcsHash.html#20c95ebfa904fc04881383afebb4635f">00936</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classcsHash.html#20c95ebfa904fc04881383afebb4635f">ConstGlobalIterator</a>; <a name="l00937"></a>00937 <a name="l00940"></a><a class="code" href="classcsHash.html#bd90b6c8da7870ee7f5cd80299b92115">00940</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#bd90b6c8da7870ee7f5cd80299b92115" title="Delete the element pointed by the iterator.">DeleteElement</a> (<a class="code" href="classcsHash.html#594373255032048e48ada9ba4e8b6e0f">GlobalIterator</a>& iterator) <a name="l00941"></a>00941 { <a name="l00942"></a>00942 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[iterator.bucket].DeleteIndex(iterator.element); <a name="l00943"></a>00943 Size--; <a name="l00944"></a>00944 iterator.size--; <a name="l00945"></a>00945 iterator.FindItem (); <a name="l00946"></a>00946 } <a name="l00947"></a>00947 <a name="l00950"></a><a class="code" href="classcsHash.html#2de35a34f8ad5666654c33047b2c60bc">00950</a> <span class="keywordtype">void</span> <a class="code" href="classcsHash.html#bd90b6c8da7870ee7f5cd80299b92115" title="Delete the element pointed by the iterator.">DeleteElement</a> (<a class="code" href="classcsHash.html#20c95ebfa904fc04881383afebb4635f">ConstGlobalIterator</a>& iterator) <a name="l00951"></a>00951 { <a name="l00952"></a>00952 <a class="code" href="classcsHash.html#5d4ab61e8a7d28c82a71b0739cf5a273">Elements</a>[iterator.bucket].DeleteIndex(iterator.element); <a name="l00953"></a>00953 Size--; <a name="l00954"></a>00954 iterator.size--; <a name="l00955"></a>00955 iterator.FindItem (); <a name="l00956"></a>00956 } <a name="l00957"></a>00957 <a name="l00964"></a><a class="code" href="classcsHash.html#0a5d83ba5963da614ba6d19819d4eb07">00964</a> <a class="code" href="classcsHash.html#9830fc407400559db7e7783cc10a9394">Iterator</a> <a class="code" href="classcsHash.html#87ee4aae183859a13101daf80b4032de" title="Return an iterator for the hash, to iterate over all elements.">GetIterator</a> (<span class="keyword">const</span> K& key) <a name="l00965"></a>00965 { <a name="l00966"></a>00966 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#9830fc407400559db7e7783cc10a9394">Iterator</a> (<span class="keyword">this</span>, key); <a name="l00967"></a>00967 } <a name="l00968"></a>00968 <a name="l00974"></a><a class="code" href="classcsHash.html#87ee4aae183859a13101daf80b4032de">00974</a> <a class="code" href="classcsHash.html#594373255032048e48ada9ba4e8b6e0f">GlobalIterator</a> <a class="code" href="classcsHash.html#87ee4aae183859a13101daf80b4032de" title="Return an iterator for the hash, to iterate over all elements.">GetIterator</a> () <a name="l00975"></a>00975 { <a name="l00976"></a>00976 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#594373255032048e48ada9ba4e8b6e0f">GlobalIterator</a> (<span class="keyword">this</span>); <a name="l00977"></a>00977 } <a name="l00978"></a>00978 <a name="l00985"></a><a class="code" href="classcsHash.html#4ad6807c13abf6668420e4587a2bb0a9">00985</a> <a class="code" href="classcsHash.html#5485970bb9da6b5d782fa28638b5658f">ConstIterator</a> <a class="code" href="classcsHash.html#87ee4aae183859a13101daf80b4032de" title="Return an iterator for the hash, to iterate over all elements.">GetIterator</a> (<span class="keyword">const</span> K& key)<span class="keyword"> const</span> <a name="l00986"></a>00986 <span class="keyword"> </span>{ <a name="l00987"></a>00987 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#5485970bb9da6b5d782fa28638b5658f">ConstIterator</a> (<span class="keyword">this</span>, key); <a name="l00988"></a>00988 } <a name="l00989"></a>00989 <a name="l00995"></a><a class="code" href="classcsHash.html#63496fcf5fb4a0898fe2c4a7222ae364">00995</a> <a class="code" href="classcsHash.html#20c95ebfa904fc04881383afebb4635f">ConstGlobalIterator</a> <a class="code" href="classcsHash.html#87ee4aae183859a13101daf80b4032de" title="Return an iterator for the hash, to iterate over all elements.">GetIterator</a> ()<span class="keyword"> const</span> <a name="l00996"></a>00996 <span class="keyword"> </span>{ <a name="l00997"></a>00997 <span class="keywordflow">return</span> <a class="code" href="classcsHash.html#20c95ebfa904fc04881383afebb4635f">ConstGlobalIterator</a> (<span class="keyword">this</span>); <a name="l00998"></a>00998 } <a name="l00999"></a>00999 }; <a name="l01000"></a>01000 <a name="l01003"></a>01003 <span class="preprocessor">#endif</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>