Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 5e1854624d3bc613bdd0dd13d1ef9ac7 > files > 2534

gap-system-4.4.12-5mdv2010.0.i586.rpm

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (orb) - Chapter 4: Hashing techniques</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
</head>
<body>


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap3.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap5.html">Next Chapter</a>&nbsp;  </div>

<p><a id="X8705763D8698C0B7" name="X8705763D8698C0B7"></a></p>
<div class="ChapSects"><a href="chap4.html#X8705763D8698C0B7">4 <span class="Heading">Hashing techniques</span></a>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X814DE39B7C1B1554">4.1 <span class="Heading">The idea of hashing</span></a>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X7AE36B967EB1382B">4.2 <span class="Heading">Hash functions</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7ACED4FB7C971A5A">4.2-1 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X803D35D97B6E7CC5">4.2-2 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7B04C17D7DC6E277">4.2-3 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7F41F51C83E88759">4.2-4 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X847801B87A03AA77">4.2-5 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X819264A980D873EE">4.2-6 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7BAD070A79E54131">4.2-7 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7C7C0CDB7DCE95B4">4.2-8 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X80C0C39080BFAA8F">4.2-9 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X87C1B2F7871B7EA4">4.2-10 ChooseHashFunction</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X80E195168734F8E3">4.2-11 ChooseHashFunction</a></span>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X8424E70E78FAA203">4.3 <span class="Heading">Using hash tables</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7FD5A22A86DACF26">4.3-1 NewHT</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7D9D6CF37FA68C39">4.3-2 AddHT</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X853825AB7DE1F99C">4.3-3 ValueHT</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X7D6AA1618657386C">4.3-4 InitHT</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X86E9DEC68728425C">4.3-5 GrowHT</a></span>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X8069137484662072">4.4 <span class="Heading"> The data structures for hash tables </span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X81BD00DE877E2C0D">4.4-1 <span class="Heading"> Memory requirements </span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X8238A6C0834A48F4">4.4-2 <span class="Heading"> Handling of collisions </span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X836F7C2C7932FEAE">4.4-3 <span class="Heading"> Efficiency </span></a>
</span>
</div>
</div>

<h3>4 <span class="Heading">Hashing techniques</span></h3>

<p><a id="X814DE39B7C1B1554" name="X814DE39B7C1B1554"></a></p>

<h4>4.1 <span class="Heading">The idea of hashing</span></h4>

<p>If one wants to store a certain set of similar objects and wants to quickly access a given one (or come back with the result that it is unknown), the first idea would be to store them in a list, possibly sorted for faster access. This however still would need log(n) comparisons to find a given element or to decide that it is not yet stored.</p>

<p>Therefore one uses a much bigger array and uses a function on the space of possible objects with integer values to decide, where in the array to store a certain object. If this so called hash function distributes the actually stored objects well enough over the array, the access time is constant in average. Of course, a hash function will usually not be injective, so one needs a strategy what to do in case of so-called "collision", that is, if more than one object with the same hash value has to be stored.</p>

<p>The basic functions to work with hash tables are <code class="func">NewHT</code> (<a href="chap4.html#X7FD5A22A86DACF26"><b>4.3-1</b></a>), <code class="func">AddHT</code> (<a href="chap4.html#X7D9D6CF37FA68C39"><b>4.3-2</b></a>), and <code class="func">ValueHT</code> (<a href="chap4.html#X853825AB7DE1F99C"><b>4.3-3</b></a>). They are described in Section <a href="chap4.html#X8424E70E78FAA203"><b>4.3</b></a>. In the next section, we first describe the infrastructure for hash functions.</p>

<p><a id="X7AE36B967EB1382B" name="X7AE36B967EB1382B"></a></p>

<h4>4.2 <span class="Heading">Hash functions</span></h4>

<p>In the <strong class="pkg">orb</strong> package hash functions are chosen automatically by giving a sample object together with the length of the hash table. This is done with the following operation:</p>

<p><a id="X7ACED4FB7C971A5A" name="X7ACED4FB7C971A5A"></a></p>

<h5>4.2-1 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>The first argument <var class="Arg">ob</var> must be a sample object, that is, an object like those we want to store in the hash table later on. The argument <var class="Arg">len</var> is an integer that gives the length of the hash table. Note that this might be called later on automatically, when a hash table is increased in size. The operation returns a record with two components. The component <code class="code">func</code> is a <strong class="pkg">GAP</strong> function taking two arguments, see below. The component <code class="code">data</code> is some <strong class="pkg">GAP</strong> object. Later on, the hash function will be called with two arguments, the first is the object for which it should call the hash value and the second argument must be the data stored in the <code class="code">data</code> component.</p>

<p>The hash function has to return values between 1 and the hash length <var class="Arg">len</var> inclusively.</p>

<p>This setup is chosen such that the hash functions can be global objects that are not created during the execution of <code class="func">ChooseHashFunction</code> but still can change their behaviour depending on the data.</p>

<p>In the following we just document, for which types of objects there are hash functions that can be found using <code class="func">ChooseHashFunction</code>.</p>

<p><a id="X803D35D97B6E7CC5" name="X803D35D97B6E7CC5"></a></p>

<h5>4.2-2 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for compressed vectors over the field <code class="code">GF(2)</code> of two elements. Note that there is no hash function for non-compressed vectors over <code class="code">GF(2)</code> because those objects cannot efficiently be recognised from their type.</p>

<p>Note that you can only use the resulting hash functions for vectors of the same length.</p>

<p><a id="X7B04C17D7DC6E277" name="X7B04C17D7DC6E277"></a></p>

<h5>4.2-3 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for compressed vectors over a finite field with up to 256 elements. Note that there is no hash function for non-compressed such vectors because those objects cannot efficiently be recognised from their type.</p>

<p>Note that you can only use the resulting hash functions for vectors of the same length.</p>

<p><a id="X7F41F51C83E88759" name="X7F41F51C83E88759"></a></p>

<h5>4.2-4 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for compressed matrices over the field <code class="code">GF(2)</code> of two elements. Note that there is no hash function for non-compressed matrices over <code class="code">GF(2)</code> because those objects cannot efficiently be recognised from their type.</p>

<p>Note that you can only use the resulting hash functions for matrices of the same size.</p>

<p><a id="X847801B87A03AA77" name="X847801B87A03AA77"></a></p>

<h5>4.2-5 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for compressed matrices over a finite field with up to 256 elements. Note that there is no hash function for non-compressed such vectors because those objects cannot efficiently be recognised from their type.</p>

<p>Note that you can only use the resulting hash functions for matrices of the same size.</p>

<p><a id="X819264A980D873EE" name="X819264A980D873EE"></a></p>

<h5>4.2-6 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for integers.</p>

<p><a id="X7BAD070A79E54131" name="X7BAD070A79E54131"></a></p>

<h5>4.2-7 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for permutations.</p>

<p><a id="X7C7C0CDB7DCE95B4" name="X7C7C0CDB7DCE95B4"></a></p>

<h5>4.2-8 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for lists of integers.</p>

<p><a id="X80C0C39080BFAA8F" name="X80C0C39080BFAA8F"></a></p>

<h5>4.2-9 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for kernel Pc words.</p>

<p><a id="X87C1B2F7871B7EA4" name="X87C1B2F7871B7EA4"></a></p>

<h5>4.2-10 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for lists of integers.</p>

<p><a id="X80E195168734F8E3" name="X80E195168734F8E3"></a></p>

<h5>4.2-11 ChooseHashFunction</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ChooseHashFunction</code>( <var class="Arg">ob, len</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p><b>Returns: </b>a record</p>

<p>This method is for lists of matrices.</p>

<p><a id="X8424E70E78FAA203" name="X8424E70E78FAA203"></a></p>

<h4>4.3 <span class="Heading">Using hash tables</span></h4>

<p>The following functions are needed to use hash tables. For details about the data structures see Section <a href="chap4.html#X8069137484662072"><b>4.4</b></a>.</p>

<p><a id="X7FD5A22A86DACF26" name="X7FD5A22A86DACF26"></a></p>

<h5>4.3-1 NewHT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; NewHT</code>( <var class="Arg">sample, len</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a new hash table object</p>

<p>A new hash table for objects like <var class="Arg">sample</var> of length <var class="Arg">len</var> is created. Note that it is a good idea to choose a prime number as the hash length due to the algorithm for collision handling which works particularly well in that case. The hash function is chosen automatically. The resulting object can be used with the functions <code class="func">AddHT</code> (<a href="chap4.html#X7D9D6CF37FA68C39"><b>4.3-2</b></a>) and <code class="func">ValueHT</code> (<a href="chap4.html#X853825AB7DE1F99C"><b>4.3-3</b></a>). It will start with length <var class="Arg">len</var> but will grow as necessary.</p>

<p><a id="X7D9D6CF37FA68C39" name="X7D9D6CF37FA68C39"></a></p>

<h5>4.3-2 AddHT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; AddHT</code>( <var class="Arg">ht, ob, val</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>an integer or fail</p>

<p>Stores the object <var class="Arg">ob</var> into the hash table <var class="Arg">ht</var> and stores the value <var class="Arg">val</var> together with <var class="Arg">ob</var>. The result is <code class="keyw">fail</code> if an error occurred, which can only be that the hash table is already full. This can only happen, if the hash table cannot grow automatically.</p>

<p>If no error occurs, the result is an integer indicating the place in the hash table where the object is stored. Note that once the hash table grows automatically this number is no longer the same!</p>

<p>If the value <var class="Arg">val</var> is <code class="keyw">true</code> for all objects in the hash, no extra memory is used for the values. All other values are stored in the hash. The value <code class="keyw">fail</code> cannot be stored as it indicates that the object is not found in the hash.</p>

<p>See Section <a href="chap4.html#X8069137484662072"><b>4.4</b></a> for details on the data structures and especially about memory requirements.</p>

<p><a id="X853825AB7DE1F99C" name="X853825AB7DE1F99C"></a></p>

<h5>4.3-3 ValueHT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ValueHT</code>( <var class="Arg">ht, ob</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>the stored value, <code class="keyw">true</code>, or <code class="keyw">fail</code></p>

<p>Looks up the object <var class="Arg">ob</var> in the hash table <var class="Arg">ht</var>. If the object is not found, <code class="keyw">fail</code> is returned. Otherwise, the value stored with the object is returned. Note that if this value was <code class="keyw">true</code> no extra memory is used for this.</p>

<p>The following function is only documented for the sake of completeness and for emergency situations, where <code class="func">NewHT</code> (<a href="chap4.html#X7FD5A22A86DACF26"><b>4.3-1</b></a>) tries to be too intelligent.</p>

<p><a id="X7D6AA1618657386C" name="X7D6AA1618657386C"></a></p>

<h5>4.3-4 InitHT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; InitHT</code>( <var class="Arg">len, hfun, eqfun</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a new hash table object</p>

<p>This is usually only an internal function. It is called from <code class="func">NewHT</code> (<a href="chap4.html#X7FD5A22A86DACF26"><b>4.3-1</b></a>). The argument <var class="Arg">len</var> is the length of the hash table, <var class="Arg">hfun</var> is the hash function record as returned by <code class="func">ChooseHashFunction</code> (<a href="chap4.html#X7ACED4FB7C971A5A"><b>4.2-1</b></a>) and <var class="Arg">eqfun</var> is a comparison function taking two arguments and returning <code class="keyw">true</code> or <code class="keyw">false</code>.</p>

<p>Note that automatic growing is switched on for the new hash table which means that if the hash table grows, a new hash function is chosen using <code class="func">ChooseHashFunction</code> (<a href="chap4.html#X7ACED4FB7C971A5A"><b>4.2-1</b></a>). If you do not want this, change the component <code class="code">cangrow</code> to <code class="keyw">false</code> after creating the hash table.</p>

<p><a id="X86E9DEC68728425C" name="X86E9DEC68728425C"></a></p>

<h5>4.3-5 GrowHT</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; GrowHT</code>( <var class="Arg">ht, ob</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>nothing</p>

<p>This is a more or less internal function. It is called when the space in a hash table becomes scarce. The first argument <var class="Arg">ht</var> must be a hash table object, the second a sample point. The function increases the hash size by a factor of 2. This makes it necessary to choose a new hash function. Usually this is done with the usual <code class="code">ChooseHashFunction</code> method. However, one can assign the two components <code class="code">hfbig</code> and <code class="code">hfdbig</code> to a function and a record respectively. In that case, upon growing the hash, a new hash function is created by taking the function <code class="code">hfbig</code> together with <code class="code">hfdbig</code> as second data argument and reducing the resulting integer modulo the hash length. In this way one can specify a hash function suitable for all hash sizes by simply producing big enough hash values.</p>

<p><a id="X8069137484662072" name="X8069137484662072"></a></p>

<h4>4.4 <span class="Heading"> The data structures for hash tables </span></h4>

<p>A hash table object is just a record with the following components:</p>


<dl>
<dt><strong class="Mark"><code class="code">els</code></strong></dt>
<dd><p>A <strong class="pkg">GAP</strong> list storing the elements. Its length can be as long as the component <code class="code">len</code> indicates but will only grow as necessary when elements are stored in the hash.</p>

</dd>
<dt><strong class="Mark"><code class="code">vals</code></strong></dt>
<dd><p>A <strong class="pkg">GAP</strong> list storing the corresponding values. If a value is <code class="keyw">true</code> nothing is stored here to save memory.</p>

</dd>
<dt><strong class="Mark"><code class="code">len</code></strong></dt>
<dd><p>Length of the hash table.</p>

</dd>
<dt><strong class="Mark"><code class="code">nr</code></strong></dt>
<dd><p>Number of elements stored in the hash table.</p>

</dd>
<dt><strong class="Mark"><code class="code">hf</code></strong></dt>
<dd><p>The hash function (value of the <code class="code">func</code> component in the record returned by <code class="func">ChooseHashFunction</code> (<a href="chap4.html#X7ACED4FB7C971A5A"><b>4.2-1</b></a>)).</p>

</dd>
<dt><strong class="Mark"><code class="code">hfd</code></strong></dt>
<dd><p>The data for the second argument of the hash function (value of the <code class="code">data</code> component in the record returned by <code class="func">ChooseHashFunction</code> (<a href="chap4.html#X7ACED4FB7C971A5A"><b>4.2-1</b></a>)).</p>

</dd>
<dt><strong class="Mark"><code class="code">eqf</code></strong></dt>
<dd><p>A comparison function taking two arguments and returning <code class="keyw">true</code> for equality or <code class="keyw">false</code> otherwise.</p>

</dd>
<dt><strong class="Mark"><code class="code">collisions</code></strong></dt>
<dd><p>Number of collisions (see below).</p>

</dd>
<dt><strong class="Mark"><code class="code">accesses</code></strong></dt>
<dd><p>Number of lookup or store accesses to the hash.</p>

</dd>
<dt><strong class="Mark"><code class="code">cangrow</code></strong></dt>
<dd><p>A boolean value indicating whether the hash can grow automatically or not.</p>

</dd>
<dt><strong class="Mark"><code class="code">ishash</code></strong></dt>
<dd><p>Is <code class="keyw">true</code> to indicate that this is a hash table record.</p>

</dd>
</dl>
<p><a id="X81BD00DE877E2C0D" name="X81BD00DE877E2C0D"></a></p>

<h5>4.4-1 <span class="Heading"> Memory requirements </span></h5>

<p>Due to the data structure defined above the hash table will need one machine word (4 bytes on 32bit machines and 8 bytes on 64bit machines) per possible entry in the hash if all values corresponding to objects in the hash are <code class="keyw">true</code> and two machine words otherwise. This means that the memory requirement for the hash itself is proportional to the hash table length and not to the number of objects actually stored in the hash!</p>

<p>In addition one of course needs the memory to store the objects themselves.</p>

<p><a id="X8238A6C0834A48F4" name="X8238A6C0834A48F4"></a></p>

<h5>4.4-2 <span class="Heading"> Handling of collisions </span></h5>

<p>If two or more objects have the same hash value, the following is done: If the hash value is coprime to the hash length, the hash value is taken as "the increment", otherwise 1 is taken. The code to find the proper place for an object just repeatedly adds the increment to the current position modulo the hash length. Due to the choice of the increment this will eventually try all places in the hash table. Every such increment step is counted as a collision in the <code class="code">collisions</code> component in the hash table. This algorithm explains why it is sensible to choose a prime number as the length of a hash table.</p>

<p><a id="X836F7C2C7932FEAE" name="X836F7C2C7932FEAE"></a></p>

<h5>4.4-3 <span class="Heading"> Efficiency </span></h5>

<p>Hashing is efficient as long as there are not too many collisions. It is not a problem if the number of collisions (counted in the <code class="code">collisions</code> component) is smaller than the number of accesses (counted in the <code class="code">accesses</code> component).</p>

<p>A high number of collisions can be caused by a bad hash function, because the hash table is too small (do not fill a hash table to more than about 80%), or because the objects to store are just not well enough distributed. Hash tables will grow automatically if too many collisions are detected.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap3.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap5.html">Next Chapter</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>