diff options
author | Douglas Gregor <doug.gregor@gmail.com> | 2005-07-31 16:48:16 +0000 |
---|---|---|
committer | Douglas Gregor <doug.gregor@gmail.com> | 2005-07-31 16:48:16 +0000 |
commit | 6c009ef3685caff213316319b827264c5c1489e5 (patch) | |
tree | c1305562bc74292e8daefff2313c18d081ba408a /doc/html/hash | |
parent | ed6bc8f4c0884495823b25c470838d8094b12446 (diff) | |
download | boost-6c009ef3685caff213316319b827264c5c1489e5.tar.gz |
Move 1.33.0 docs over to the branch
[SVN r30340]
Diffstat (limited to 'doc/html/hash')
-rw-r--r-- | doc/html/hash/acknowledgements.html | 53 | ||||
-rw-r--r-- | doc/html/hash/combine.html | 106 | ||||
-rw-r--r-- | doc/html/hash/custom.html | 103 | ||||
-rw-r--r-- | doc/html/hash/links.html | 53 | ||||
-rw-r--r-- | doc/html/hash/portability.html | 106 | ||||
-rw-r--r-- | doc/html/hash/reference_.html | 163 | ||||
-rw-r--r-- | doc/html/hash/tutorial.html | 90 |
7 files changed, 674 insertions, 0 deletions
diff --git a/doc/html/hash/acknowledgements.html b/doc/html/hash/acknowledgements.html new file mode 100644 index 0000000000..c97f560025 --- /dev/null +++ b/doc/html/hash/acknowledgements.html @@ -0,0 +1,53 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Acknowledgements</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="links.html" title=" Links"> +<link rel="next" href="../lambda.html" title="Chapter 6. Boost.Lambda"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="links.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../lambda.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.acknowledgements"></a> Acknowledgements</h3></div></div></div> +<p> +This library is based on the design by Peter Dimov. During the inital development +Joaquín M López Muñoz made many useful suggestions and contributed fixes.</p> +<p> +The review was managed by Thorsten Ottosen, and the library reviewed by: +David Abrahams, Alberto Barbati, Topher Cooper, Caleb Epstein, Dave Harris, +Chris Jefferson, Bronek Kozicki, John Maddock, Tobias Swinger,Jaap Suter +and Rob Stewart.</p> +<p> +The implementation of the hash function for pointers is based on suggestions +made by Alberto Barbati and Dave Harris. Dave Harris also suggested an +important improvement to <code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code> that was taken up.</p> +<p> +The original implementation came from Jeremy B. Maitin-Shepard's hash table +library, although this is a complete rewrite.</p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="links.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../lambda.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/combine.html b/doc/html/hash/combine.html new file mode 100644 index 0000000000..8e0d2b94e9 --- /dev/null +++ b/doc/html/hash/combine.html @@ -0,0 +1,106 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Combining hash values</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="custom.html" title=" Extending boost::hash for a custom data type"> +<link rel="next" href="portability.html" title=" Portability"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="custom.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="portability.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.combine"></a> Combining hash values</h3></div></div></div> +<p> +Say you have a point class, representing a two dimensional location:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">class</span><span class="identifier"> point</span><span class="special"> +{</span><span class="keyword"> + int</span><span class="identifier"> x</span><span class="special">;</span><span class="keyword"> + int</span><span class="identifier"> y</span><span class="special">;</span><span class="keyword"> +public</span><span class="special">:</span><span class="identifier"> + point</span><span class="special">()</span><span class="special"> :</span><span class="identifier"> x</span><span class="special">(</span><span class="number">0</span><span class="special">),</span><span class="identifier"> y</span><span class="special">(</span><span class="number">0</span><span class="special">)</span><span class="special"> {}</span><span class="identifier"> + point</span><span class="special">(</span><span class="keyword">int</span><span class="identifier"> x</span><span class="special">,</span><span class="keyword"> int</span><span class="identifier"> y</span><span class="special">)</span><span class="special"> :</span><span class="identifier"> x</span><span class="special">(</span><span class="identifier">x</span><span class="special">),</span><span class="identifier"> y</span><span class="special">(</span><span class="identifier">y</span><span class="special">)</span><span class="special"> {}</span><span class="keyword"> + + bool</span><span class="keyword"> operator</span><span class="special">==(</span><span class="identifier">point</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> other</span><span class="special">)</span><span class="keyword"> const</span><span class="special"> + {</span><span class="keyword"> + return</span><span class="identifier"> x</span><span class="special"> =</span><span class="identifier"> other</span><span class="special">.</span><span class="identifier">x</span><span class="special"> &&</span><span class="identifier"> y</span><span class="special"> ==</span><span class="identifier"> other</span><span class="special">.</span><span class="identifier">y</span><span class="special">;</span><span class="special"> + }</span><span class="special"> +};</span></code></pre> +<p> +and you wish to use it as the key for an <code class="computeroutput"><span class="identifier">unordered_map</span></code>. You need to +customise the hash for this structure. To do this we need to combine +the hash values for <code class="computeroutput"><span class="identifier">x</span></code> and <code class="computeroutput"><span class="identifier">y</span></code>. The function +<code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code> is supplied for this purpose:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">class</span><span class="identifier"> point</span><span class="special"> +{</span><span class="special"> + ...</span><span class="keyword"> + + friend</span><span class="identifier"> std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash_value</span><span class="special">(</span><span class="identifier">point</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> p</span><span class="special">)</span><span class="special"> + {</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> seed</span><span class="special"> =</span><span class="number"> 0</span><span class="special">;</span> + <code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span><span class="identifier"> p</span><span class="special">.</span><span class="identifier">x</span><span class="special">);</span> + <code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code><span class="special">(</span><span class="identifier">seed</span><span class="special">,</span><span class="identifier"> p</span><span class="special">.</span><span class="identifier">y</span><span class="special">);</span><span class="keyword"> + + return</span><span class="identifier"> seed</span><span class="special">;</span><span class="special"> + }</span><span class="special"> + + ...</span><span class="special"> +};</span></code></pre> +<p> +Calls to hash_combine incrementally build the hash from the different members +of point, it can be repeatedly called for any number of elements. It calls +<code class="computeroutput"><a href="../id1042434.html" title="Function hash_value">hash_value</a></code> on the supplied element, and combines it with the seed.</p> +<p> +Full code for this example is at +<a href="../../../libs/functional/hash/examples/point.cpp" target="_top">/libs/functional/hash/examples/point.cpp</a>.</p> +<div class="informaltable"><table class="table"> +<colgroup><col></colgroup> +<tbody><tr><td class="blurb"> +When using __hash_combine the order of the +calls matters. +<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"> + std::size_t seed = 0; + boost::hash_combine(seed, 1); + boost::hash_combine(seed, 2); +</pre> +results in a different seed to: +<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"> + std::size_t seed = 0; + boost::hash_combine(seed, 2); + boost::hash_combine(seed, 1); +</pre> +If you are calculating a hash value for data where the order of the data +doesn't matter in comparisons (e.g. a set) you will have to ensure that the +data is always supplied in the same order. + +</td></tr></tbody> +</table></div> +<p> +To calculate the hash of an iterator range you can use <code class="computeroutput"><a href="../hash_range.html" title="Function hash_range">boost::hash_range</a></code>:</p> +<pre class="programlisting"><code class="literal"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">></span><span class="identifier"> some_strings</span><span class="special">;</span><span class="identifier"> +std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash</span><span class="special"> =</span> <code class="computeroutput"><a href="../hash_range.html" title="Function hash_range">boost::hash_range</a></code><span class="special">(</span><span class="identifier">some_strings</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span><span class="identifier"> some_strings</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span></code></pre> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="custom.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="portability.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/custom.html b/doc/html/hash/custom.html new file mode 100644 index 0000000000..a7fc568809 --- /dev/null +++ b/doc/html/hash/custom.html @@ -0,0 +1,103 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Extending boost::hash for a custom data type</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="tutorial.html" title=" Tutorial"> +<link rel="next" href="combine.html" title=" Combining hash values"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="tutorial.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="combine.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.custom"></a> Extending boost::hash for a custom data type</h3></div></div></div> +<p><code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> is implemented by calling the function <code class="computeroutput"><a href="../id1042434.html" title="Function hash_value">hash_value</a></code>. +The namespace isn't specified so that it can detect overloads via argument +dependant lookup. So if there is a free function <code class="computeroutput"><span class="identifier">hash_value</span></code> in the same +namespace as a custom type, it will get called.</p> +<p> +If you have a structure <code class="computeroutput"><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span></code>, where each <code class="computeroutput"><span class="identifier">book</span></code> is uniquely +defined by it's member <code class="computeroutput"><span class="identifier">id</span></code>:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">namespace</span><span class="identifier"> library</span><span class="special"> +{</span><span class="keyword"> + struct</span><span class="identifier"> book</span><span class="special"> + {</span><span class="keyword"> + int</span><span class="identifier"> id</span><span class="special">;</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">string</span><span class="identifier"> author</span><span class="special">;</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">string</span><span class="identifier"> title</span><span class="special">;</span><span class="comment"> + + // .... +</span><span class="special"> };</span><span class="keyword"> + + bool</span><span class="keyword"> operator</span><span class="special">==(</span><span class="identifier">book</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> a</span><span class="special">,</span><span class="identifier"> book</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> b</span><span class="special">)</span><span class="special"> + {</span><span class="keyword"> + return</span><span class="identifier"> a</span><span class="special">.</span><span class="identifier">id</span><span class="special"> ==</span><span class="identifier"> b</span><span class="special">.</span><span class="identifier">id</span><span class="special">;</span><span class="special"> + }</span><span class="special"> +}</span></code></pre> +<p> +Then all you would need to do is write the function <code class="computeroutput"><span class="identifier">library</span><span class="special">::</span><span class="identifier">hash_value</span></code>:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">namespace</span><span class="identifier"> library</span><span class="special"> +{</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash_value</span><span class="special">(</span><span class="identifier">book</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> b</span><span class="special">)</span><span class="special"> + {</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="identifier"> hasher</span><span class="special">;</span><span class="keyword"> + return</span><span class="identifier"> hasher</span><span class="special">(</span><span class="identifier">b</span><span class="special">.</span><span class="identifier">id</span><span class="special">);</span><span class="special"> + }</span><span class="special"> +}</span></code></pre> +<p> +And you can now use <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> with book:</p> +<pre class="programlisting"><code class="literal"><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="identifier"> knife</span><span class="special">(</span><span class="number">3458</span><span class="special">,</span><span class="string"> "Zane Grey"</span><span class="special">,</span><span class="string"> "The Hash Knife Outfit"</span><span class="special">);</span><span class="identifier"> +library</span><span class="special">::</span><span class="identifier">book</span><span class="identifier"> dandelion</span><span class="special">(</span><span class="number">1354</span><span class="special">,</span><span class="string"> "Paul J. Shanley"</span><span class="special">,</span><span class="string"> + "Hash & Dandelion Greens"</span><span class="special">);</span><code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">></span><span class="identifier"> book_hasher</span><span class="special">;</span><span class="identifier"> +std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> knife_hash_value</span><span class="special"> =</span><span class="identifier"> book_hasher</span><span class="special">(</span><span class="identifier">knife</span><span class="special">);</span><span class="comment"> + +// If std::unordered_set is available: +</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_set</span><span class="special"><</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">,</span> <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">></span><span class="special"> ></span><span class="identifier"> books</span><span class="special">;</span><span class="identifier"> +books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">knife</span><span class="special">);</span><span class="identifier"> +books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">(</span><span class="number">2443</span><span class="special">,</span><span class="string"> "Lindgren, Torgny"</span><span class="special">,</span><span class="string"> "Hash"</span><span class="special">));</span><span class="identifier"> +books</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">library</span><span class="special">::</span><span class="identifier">book</span><span class="special">(</span><span class="number">1953</span><span class="special">,</span><span class="string"> "Snyder, Bernadette M."</span><span class="special">,</span><span class="string"> + "Heavenly Hash: A Tasty Mix of a Mother's Meditations"</span><span class="special">));</span><span class="identifier"> + +assert</span><span class="special">(</span><span class="identifier">books</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">knife</span><span class="special">)</span><span class="special"> !=</span><span class="identifier"> books</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span><span class="identifier"> +assert</span><span class="special">(</span><span class="identifier">books</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="identifier">dandelion</span><span class="special">)</span><span class="special"> ==</span><span class="identifier"> books</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span></code></pre> +<p> +The full example can be found in: +<a href="../../../libs/functional/hash/examples/books.cpp" target="_top">/libs/functional/hash/examples/books.hpp</a> +and +<a href="../../../libs/functional/hash/examples/books.cpp" target="_top">/libs/functional/hash/examples/books.cpp</a>.</p> +<div class="informaltable"><table class="table"> +<colgroup><col></colgroup> +<tbody><tr><td class="blurb"> +When writing a hash function, first look at how the equality function works. +Objects that are equal must generate the same hash value. +When objects are not equal the should generate different hash values. +In this object equality was based just on the id, if it was based +on the objects name and author the hash function should take them into account +(how to do this is discussed in the next section). +</td></tr></tbody> +</table></div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="tutorial.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="combine.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/links.html b/doc/html/hash/links.html new file mode 100644 index 0000000000..8b23df1f1f --- /dev/null +++ b/doc/html/hash/links.html @@ -0,0 +1,53 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Links</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="../id873294.html" title="Function hash_value"> +<link rel="next" href="acknowledgements.html" title=" Acknowledgements"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../id873294.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.links"></a> Links</h3></div></div></div> +<p><span class="bold"><strong>A Proposal to Add Hash Tables to the Standard Library</strong></span><br><a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1456.html" target="_top">http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1456.html</a><br> + +The hash table proposal explains much of the design. The hash function object +is discussed in Section D.</p> +<p><span class="bold"><strong>The C++ Standard Library Technical Report.</strong></span><br><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf" target="_top">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf</a><br> + +Contains the hash function specification in section 6.3.2.</p> +<p><span class="bold"><strong>Library Extension Technical Report Issues List.</strong></span><br><a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf" target="_top">http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf</a><br> + +The library implements the extension described in Issue 6.18.</p> +<p><span class="bold"><strong>Methods for Identifying Versioned and Plagiarised Documents</strong></span><br> + +Timothy C. Hoad, Justin Zobel<br><a href="http://www.cs.rmit.edu.au/~jz/fulltext/jasist-tch.pdf" target="_top">http://www.cs.rmit.edu.au/~jz/fulltext/jasist-tch.pdf</a><br> + +Contains the hash function that <code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code> is based on.</p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../id873294.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/portability.html b/doc/html/hash/portability.html new file mode 100644 index 0000000000..58b2f83a15 --- /dev/null +++ b/doc/html/hash/portability.html @@ -0,0 +1,106 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Portability</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="combine.html" title=" Combining hash values"> +<link rel="next" href="reference_.html" title=" Reference"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="combine.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="reference_.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.portability"></a> Portability</h3></div></div></div> +<p><code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> is written to be as portable as possible, but unfortunately, several +older compilers don't support argument dependent lookup (ADL) - the mechanism +used for customization. On those compilers custom overloads for hash_value +need to be declared in the boost namespace.</p> +<p> +On a strictly standards compliant compiler, an overload defined in the +boost namespace won't be found when <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> is instantiated, +so for these compilers the overload should only be declared in the same +namespace as the class.</p> +<p> +Let's say we have a simple custom type:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">namespace</span><span class="identifier"> foo</span><span class="special"> +{</span><span class="keyword"> + struct</span><span class="identifier"> custom_type</span><span class="special"> + {</span><span class="keyword"> + int</span><span class="identifier"> value</span><span class="special">;</span><span class="keyword"> + + friend</span><span class="keyword"> inline</span><span class="identifier"> std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash_value</span><span class="special">(</span><span class="identifier">custom_type</span><span class="identifier"> x</span><span class="special">)</span><span class="special"> + {</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="identifier"> hasher</span><span class="special">;</span><span class="keyword"> + return</span><span class="identifier"> hasher</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span><span class="special">);</span><span class="special"> + }</span><span class="special"> + };</span><span class="special"> +}</span></code></pre> +<p> +On a compliant compiler, when <code class="computeroutput"><span class="identifier">hash_value</span></code> is called for this type, +it will look at the namespace inside the type and find <code class="computeroutput"><span class="identifier">hash_value</span></code> +but on a compiler which doesn't support ADL <code class="computeroutput"><span class="identifier">hash_value</span></code> won't be found.</p> +<p> +So on these compilers define a member function:</p> +<pre class="programlisting"><code class="literal"><span class="preprocessor">#ifndef</span><span class="identifier"> BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP</span><span class="keyword"> + friend</span><span class="keyword"> inline</span><span class="identifier"> std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash_value</span><span class="special">(</span><span class="identifier">custom_type</span><span class="identifier"> x</span><span class="special">)</span><span class="special"> + {</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="identifier"> hasher</span><span class="special">;</span><span class="keyword"> + return</span><span class="identifier"> hasher</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">value</span><span class="special">);</span><span class="special"> + }</span><span class="preprocessor"> +#else</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash</span><span class="special">()</span><span class="keyword"> const</span><span class="special"> + {</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="identifier"> hasher</span><span class="special">;</span><span class="keyword"> + return</span><span class="identifier"> hasher</span><span class="special">(</span><span class="identifier">value</span><span class="special">);</span><span class="special"> + }</span><span class="preprocessor"> +#endif</span></code></pre> +<p> +which will be called from the <code class="computeroutput"><span class="identifier">boost</span></code> namespace:</p> +<pre class="programlisting"><code class="literal"><span class="preprocessor">#ifdef</span><span class="identifier"> BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP</span><span class="keyword"> +namespace</span><span class="identifier"> boost</span><span class="special"> +{</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> hash_value</span><span class="special">(</span><span class="identifier">foo</span><span class="special">::</span><span class="identifier">custom_type</span><span class="identifier"> x</span><span class="special">)</span><span class="special"> + {</span><span class="keyword"> + return</span><span class="identifier"> x</span><span class="special">.</span><span class="identifier">hash</span><span class="special">();</span><span class="special"> + }</span><span class="special"> +}</span><span class="preprocessor"> +#endif</span></code></pre> +<p> +Full code for this example is at +<a href="../../../libs/functional/hash/examples/portable.cpp" target="_top">/libs/functional/hash/examples/portable.cpp</a>.</p> +<a name="portability.other_issues"></a><h2> +<a name="id1219332"></a>Other Issues</h2> +<p> +On Visual C++ versions 6.5 and 7.0, <code class="computeroutput"><span class="identifier">hash_value</span></code> isn't overloaded for built in +arrays. <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>, <code class="computeroutput"><a href="../hash_combine.html" title="Function template hash_combine">boost::hash_combine</a></code> and <code class="computeroutput"><a href="../hash_range.html" title="Function hash_range">boost::hash_range</a></code> all use a workaround to +support built in arrays so this shouldn't be a problem in most cases.</p> +<p> +On Visual C++ versions 6.5 and 7.0, function pointers aren't currently supported.</p> +<p><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash_value</span><span class="special">(</span><span class="keyword">long</span><span class="keyword"> double</span><span class="special">)</span></code> on GCC on Solaris appears to treat +<code class="computeroutput"><span class="keyword">long</span><span class="keyword"> double</span></code>s as doubles - so the hash function doesn't take into account the +full range of values.</p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="combine.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="reference_.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/reference_.html b/doc/html/hash/reference_.html new file mode 100644 index 0000000000..1702ec21f3 --- /dev/null +++ b/doc/html/hash/reference_.html @@ -0,0 +1,163 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Reference</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="portability.html" title=" Portability"> +<link rel="next" href="../boost/hash.html" title="Struct template hash"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="portability.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../boost/hash.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.reference_"></a> Reference</h3></div></div></div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h5 class="title"> +<a name="hash.reference"></a>Reference</h5></div></div></div> +<div class="toc"><dl> +<dt><span class="section"><a href="reference_.html#hash.reference.specification"></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1082053">Header <boost/functional/hash.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1082064">Header <boost/functional/hash/hash.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1081880">Header <boost/functional/hash/pair.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id999017">Header <boost/functional/hash/vector.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1067315">Header <boost/functional/hash/list.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1068774">Header <boost/functional/hash/deque.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id836835">Header <boost/functional/hash/set.hpp></a></span></dt> +<dt><span class="section"><a href="reference_.html#id1034618">Header <boost/functional/hash/map.hpp></a></span></dt> +</dl></div> +<div class="section" lang="en"> +<div class="titlepage"></div> +<p>For the full specification, see section 6.3 of the + <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf" target="_top">C++ Standard Library Technical Report</a> + and issue 6.18 of the + <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf" target="_top">Library Extension Technical Report Issues List</a>. + </p> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1082053"></a>Header <<a href="../../../boost/functional/hash.hpp" target="_top">boost/functional/hash.hpp</a>></h6></div></div></div> +<p>Includes all the following headers.</p> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1082064"></a>Header <<a href="../../../boost/functional/hash/hash.hpp" target="_top">boost/functional/hash/hash.hpp</a>></h6></div></div></div> +<p> + Defines <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>, + the implementation for built in types and + <code class="computeroutput">std::string</code> and customisation functions. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <span class="bold"><strong>struct</strong></span> <a href="../boost/hash.html" title="Struct template hash">hash</a>; + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="../hash_combine.html" title="Function template hash_combine">hash_combine</a>(size_t &, T <span class="bold"><strong>const</strong></span> &); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> It> <span class="type">std::size_t</span> <a href="../hash_range.html" title="Function hash_range">hash_range</a>(It, It); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> It> <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="../hash_range.html" title="Function hash_range">hash_range</a>(std::size_t&, It, It); + <span class="type">std::size_t</span> <a href="../id1042434.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>int</strong></span>); + <span class="type">std::size_t</span> <a href="../id1042434.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>unsigned</strong></span> <span class="bold"><strong>int</strong></span>); + <span class="type">std::size_t</span> <a href="../id1042434.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>long</strong></span>); + <span class="type">std::size_t</span> <a href="../id1042434.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>unsigned</strong></span> <span class="bold"><strong>long</strong></span>); + <span class="type">std::size_t</span> <a href="../id802125.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>float</strong></span>); + <span class="type">std::size_t</span> <a href="../id802125.html" title="Function hash_value">hash_value</a>(double); + <span class="type">std::size_t</span> <a href="../id802125.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>long</strong></span> double); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <span class="type">std::size_t</span> <a href="../id1001098.html" title="Function hash_value">hash_value</a>(T* <span class="bold"><strong>const</strong></span>&); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>unsigned</strong></span> N> <span class="type">std::size_t</span> <a href="../id1070986.html" title="Function hash_value">hash_value</a>(T (&val)[N]); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>unsigned</strong></span> N> <span class="type">std::size_t</span> <a href="../id1070986.html" title="Function hash_value">hash_value</a>(<span class="bold"><strong>const</strong></span> T (&val)[N]); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Ch, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id897675.html" title="Function hash_value">hash_value</a>(std::basic_string<Ch, std::char_traits<Ch>, A> <span class="bold"><strong>const</strong></span>&); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1081880"></a>Header <<a href="../../../boost/functional/hash/pair.hpp" target="_top">boost/functional/hash/pair.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::pair</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> A, <span class="bold"><strong>typename</strong></span> B> + <span class="type">std::size_t</span> <a href="../id975607.html" title="Function hash_value">hash_value</a>(std::pair<A, B> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id999017"></a>Header <<a href="../../../boost/functional/hash/vector.hpp" target="_top">boost/functional/hash/vector.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::vector</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id1000285.html" title="Function hash_value">hash_value</a>(std::vector<T, A> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1067315"></a>Header <<a href="../../../boost/functional/hash/list.hpp" target="_top">boost/functional/hash/list.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::list</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id1067334.html" title="Function hash_value">hash_value</a>(std::list<T, A> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1068774"></a>Header <<a href="../../../boost/functional/hash/deque.hpp" target="_top">boost/functional/hash/deque.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::deque</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id1068792.html" title="Function hash_value">hash_value</a>(std::deque<T, A> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id836835"></a>Header <<a href="../../../boost/functional/hash/set.hpp" target="_top">boost/functional/hash/set.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::set</code> and <code class="computeroutput">std::multiset</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> K, <span class="bold"><strong>typename</strong></span> C, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id898032.html" title="Function hash_value">hash_value</a>(std::set<K, C, A> <span class="bold"><strong>const</strong></span> &); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> K, <span class="bold"><strong>typename</strong></span> C, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id898032.html" title="Function hash_value">hash_value</a>(std::multiset<K, C, A> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h6 class="title"> +<a name="id1034618"></a>Header <<a href="../../../boost/functional/hash/map.hpp" target="_top">boost/functional/hash/map.hpp</a>></h6></div></div></div> +<p> + Hash implementation for <code class="computeroutput">std::map</code> and <code class="computeroutput">std::multimap</code>. + </p> +<pre class="synopsis"><span class="bold"><strong>namespace</strong></span> boost { + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> K, <span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> C, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id873294.html" title="Function hash_value">hash_value</a>(std::map<K, T, C, A> <span class="bold"><strong>const</strong></span> &); + <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> K, <span class="bold"><strong>typename</strong></span> T, <span class="bold"><strong>typename</strong></span> C, <span class="bold"><strong>typename</strong></span> A> + <span class="type">std::size_t</span> <a href="../id873294.html" title="Function hash_value">hash_value</a>(std::multimap<K, T, C, A> <span class="bold"><strong>const</strong></span> &); +}</pre> +</div> +</div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="portability.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../boost/hash.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/doc/html/hash/tutorial.html b/doc/html/hash/tutorial.html new file mode 100644 index 0000000000..3da9975377 --- /dev/null +++ b/doc/html/hash/tutorial.html @@ -0,0 +1,90 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title> Tutorial</title> +<link rel="stylesheet" href="../boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> +<link rel="start" href="../index.html" title="The Boost C++ Libraries"> +<link rel="up" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="prev" href="../hash.html" title="Chapter 5. Boost.Functional/Hash"> +<link rel="next" href="custom.html" title=" Extending boost::hash for a custom data type"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"> +<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td> +<td align="center"><a href="../../../index.htm">Home</a></td> +<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="../../../people/people.htm">People</a></td> +<td align="center"><a href="../../../more/faq.htm">FAQ</a></td> +<td align="center"><a href="../../../more/index.htm">More</a></td> +</table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../hash.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="custom.html"><img src="../images/next.png" alt="Next"></a> +</div> +<div class="section" lang="en"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="hash.tutorial"></a> Tutorial</h3></div></div></div> +<p> +When using a hash index with <a href="../../../libs/multi_index/doc/index.html" target="_top">Boost.MultiIndex</a>, you don't need to do +anything to use <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> as it uses it by default. +To find out how to use a user-defined type, read the +<a href="custom.html" title=" Extending boost::hash for a custom data type">section on extending boost::hash for a custom data type</a>.</p> +<p> +If your standard library supplies its own implementation of the unordered +associative containers and you wish to use +<code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code>, just use an extra template parameter:</p> +<pre class="programlisting"><code class="literal"><span class="identifier">std</span><span class="special">::</span><span class="identifier">unordered_multiset</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">>,</span> <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="special"> ></span><span class="identifier"> + set_of_ints</span><span class="special">;</span><span class="identifier"> + +std</span><span class="special">::</span><span class="identifier">unordered_set</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span><span class="keyword"> int</span><span class="special">>,</span> <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span><span class="keyword"> int</span><span class="special">></span><span class="special"> ></span><span class="identifier"> + set_of_pairs</span><span class="special">;</span><span class="identifier"> + +std</span><span class="special">::</span><span class="identifier">unordered_map</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span><span class="identifier"> std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">int</span><span class="special">></span><span class="special"> ></span><span class="identifier"> map_int_to_string</span><span class="special">;</span></code></pre> +<p> +To use <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code> directly, create an instance and call it as a function:</p> +<pre class="programlisting"><code class="literal"><span class="preprocessor">#include</span><span class="special"> <</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">hash</span><span class="special">/</span><span class="identifier">hash</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span><span class="keyword"> + +int</span><span class="identifier"> main</span><span class="special">()</span><span class="special"> +{</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">></span><span class="identifier"> string_hash</span><span class="special">;</span><span class="identifier"> + + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> h</span><span class="special"> =</span><span class="identifier"> string_hash</span><span class="special">(</span><span class="string">"Hash me"</span><span class="special">);</span><span class="special"> +}</span></code></pre> +<p> +If you wish to make use of the extensions, you will need to include the +appropriate header (see the +<a href="reference_.html#hash.reference.specification" title="">reference documentation</a> for the full list).</p> +<pre class="programlisting"><code class="literal"><span class="preprocessor">#include</span><span class="special"> <</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">hash</span><span class="special">/</span><span class="identifier">pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span><span class="keyword"> + +int</span><span class="identifier"> main</span><span class="special">()</span><span class="special"> +{</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span><span class="keyword"> int</span><span class="special">></span><span class="special"> ></span><span class="identifier"> pair_hash</span><span class="special">;</span><span class="identifier"> + + std</span><span class="special">::</span><span class="identifier">size_t</span><span class="identifier"> h</span><span class="special"> =</span><span class="identifier"> pair_hash</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="number"> 2</span><span class="special">));</span><span class="special"> +}</span></code></pre> +<p> +Or alternatively, include <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">hash</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> for the full library.</p> +<p> +For an example of generic use, here is a function to generate a vector +containing the hashes of the elements of a container:</p> +<pre class="programlisting"><code class="literal"><span class="keyword">template</span><span class="special"> <</span><span class="keyword">class</span><span class="identifier"> Container</span><span class="special">></span><span class="identifier"> +std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">></span><span class="identifier"> get_hashes</span><span class="special">(</span><span class="identifier">Container</span><span class="keyword"> const</span><span class="special">&</span><span class="identifier"> x</span><span class="special">)</span><span class="special"> +{</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">></span><span class="identifier"> hashes</span><span class="special">;</span><span class="identifier"> + std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span><span class="identifier"> x</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span><span class="identifier"> std</span><span class="special">::</span><span class="identifier">insert_iterator</span><span class="special">(</span><span class="identifier">hashes</span><span class="special">),</span> + <code class="computeroutput"><a href="../boost/hash.html" title="Struct template hash">boost::hash</a></code><span class="special"><</span><span class="keyword">typename</span><span class="identifier"> Container</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">>());</span><span class="keyword"> + + return</span><span class="identifier"> hashes</span><span class="special">;</span><span class="special"> +}</span></code></pre> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><small>Copyright © 2005 Daniel James</small></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../hash.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../hash.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="custom.html"><img src="../images/next.png" alt="Next"></a> +</div> +</body> +</html> |