etk/class_etk__Hash.html

220 lines
17 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>etk Library</title>
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="menu.css">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="container">
<h1><a href="index.html">etk library</a></h1>
<h4><a href="http://github.com/heeroyui/etk/">&nbsp;&nbsp;&nbsp;[ sources ]</a></h4>
<h3>API:</h3> <div id="menu">
<ul class="niveau1">
<li class="sousmenu"><a href="namespace_etk.html">etk</a>
<ul class="niveau2">
<li><a href="namespace_etk__color.html">color</a>
</li>
<li><a href="namespace_etk__tool.html">tool</a>
</li>
<li><a href="namespace_etk__archive.html">archive</a>
</li>
<li><a href="namespace_etk__theme.html">theme</a>
</li>
</ul>
</li>
<li><a href="namespace_u32char.html">u32char</a>
</li>
<li><a href="namespace_utf8.html">utf8</a>
</li>
<li><a href="namespace_std.html">std</a>
</li>
<li><a href="namespace_debug.html">debug</a>
</li>
</ul>
</div>
<br/><h3>Associate libraries:</h3><div id="menu">
<ul class="niveau1"><li><a href="../ewol/index.html">ewol</a></li>
</ul><ul class="niveau1"><li><a href="../ejson/index.html">ejson</a></li>
</ul><ul class="niveau1"><li><a href="../egami/index.html">egami</a></li>
</ul><ul class="niveau1"><li><a href="../ege/index.html">ege</a></li>
</ul><ul class="niveau1"><li><a href="../esvg/index.html">esvg</a></li>
</ul><ul class="niveau1"><li><a href="../exml/index.html">exml</a></li>
</ul></div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</div>
</div>
<div class="container" id="content">
<h1>class: etk::Hash</h1><hr/><h2>Description:</h2>
Hash table tamplate is a simple classical hash interface.
A hash table is a equivalent of the dictionary in python, this is a
simple interfaace between a name and a value:
<ul> "name" : 19
"name 2" : 99
</ul>
<br/>
<b>Note:</b><pre>The name is unique and the value is what you want.</pre><br/>
A simple example of use:
<pre>
<span class="code-comment">// Create a integer hash table
</span>Hash&lt;<span class="code-type">int</span>&gt; myValue;
<span class="code-comment">// add some element (note add and set is the same function)
</span>myValue.<span class="code-function-name">add(</span><span class="code-text-quote">"example"</span>, <span class="code-number">98837</span>);
myValue.<span class="code-function-name">add(</span><span class="code-text-quote">"plop"</span>, <span class="code-number">88</span>);
<span class="code-comment">// Display an element:
</span>pr<span class="code-type">int</span><span class="code-function-name">f(</span><span class="code-text-quote">"my value is : %d"</span>, myValue[<span class="code-text-quote">"example"</span>]);
<span class="code-comment">// Change value of an element:
</span>myValue.<span class="code-function-name">set(</span><span class="code-text-quote">"example"</span>, <span class="code-number">99</span>);
<span class="code-comment">// Remove an element:
</span>myValue.<span class="code-function-name">remove(</span><span class="code-text-quote">"plop"</span>);
<span class="code-comment">//Clean all the table:
</span>myValue.<span class="code-function-name">clear(</span>);
</pre><br/><br/>
<h2>Constructor and Destructor:</h2>
<pre>
+ <a class="code-function" href="#8269">Hash</a> (<span class="code-type" >int32_t</span> <span class="code-argument">_count</span>);<br/>+ <a class="code-function" href="#8271">~Hash</a> (<span class="code-type" >void</span> <span class="code-argument"></span>);<br/></pre>
<br/>
<h2>Synopsis:</h2>
<pre>
+ <span class="code-type" >void</span> <a class="code-function" href="#8273">clear</a> (<span class="code-type" >void</span> <span class="code-argument"></span>);<br/>+ <span class="code-type" >int64_t</span> <a class="code-function" href="#8275">getId</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/>+ <span class="code-type" >bool</span> <a class="code-function" href="#8277">exist</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_name</span>) <span class="code-storage-keyword">const</span>;<br/>+ MY_TYPE & <a class="code-function" href="#8279">get</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/>+ MY_TYPE & <a class="code-function" href="#8281">operator [ ]</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>);<br/>+ <span class="code-storage-keyword">const</span> MY_TYPE & <a class="code-function" href="#8283">operator [ ]</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/>+ <span class="code-type" >void</span> <a class="code-function" href="#8285">add</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>,<br/> <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-argument">_value</span>);<br/>+ <span class="code-type" >void</span> <a class="code-function" href="#8288">set</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>,<br/> <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-argument">_value</span>);<br/>+ <span class="code-type" >void</span> <a class="code-function" href="#8291">remove</a> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>);<br/>+ <span class="code-type" >int32_t</span> <a class="code-function" href="#8293">size</a> (<span class="code-type" >void</span> <span class="code-argument"></span>) <span class="code-storage-keyword">const</span>;<br/>+ MY_TYPE & <a class="code-function" href="#8295">operator [ ]</a> (size_t <span class="code-argument">_pos</span>);<br/>+ <span class="code-storage-keyword">const</span> MY_TYPE & <a class="code-function" href="#8297">operator [ ]</a> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/>+ <span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <a class="code-function" href="#8299">getKey</a> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/>+ <span class="code-storage-keyword">const</span> MY_TYPE & <a class="code-function" href="#8301">getValue</a> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/>+ MY_TYPE & <a class="code-function" href="#8303">getValue</a> (size_t <span class="code-argument">_pos</span>);<br/></pre>
<br/>
<h2>Detail:</h2>
<a id="8269"/><a id="8271"/><h3>Hash</h3><pre>
+ <span class="code-function">Hash</span> (<span class="code-type" >int32_t</span> <span class="code-argument">_count</span>);<br/></pre>
Contructor of the Hach table.<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_count</span> </td><td> Number ob basic elent in the vector.</td></tr>
</table>
</ul>
<br/>
<hr/>
<a id="8273"/><h3>~Hash</h3><pre>
+ <span class="code-function">~Hash</span> (<span class="code-type" >void</span> <span class="code-argument"></span>);<br/></pre>
Destructor of the Hash table(clear all element in the table)<br/>
<br/>
<hr/>
<a id="8275"/><h3>clear</h3><pre>
+ <span class="code-type" >void</span> <span class="code-function">clear</span> (<span class="code-type" >void</span> <span class="code-argument"></span>);<br/></pre>
Remove all entry in the Hash table.<br/><b>Note:</b> It does not delete pointer if your value is a pointer type...<br/>
<br/>
<hr/>
<a id="8277"/><h3>getId</h3><pre>
+ <span class="code-type" >int64_t</span> <span class="code-function">getId</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Get a current element ID in the Hash table<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the hash requested</td></tr>
<tr><td><b>Return: </b></td><td></td><td>Id of the element in the table or -1 of it does not existed</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8279"/><h3>exist</h3><pre>
+ <span class="code-type" >bool</span> <span class="code-function">exist</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_name</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Check if an element exist or not<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the hash requested</td></tr>
<tr><td><b>Return: </b></td><td></td><td>true if the element exist</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8281"/><h3>get</h3><pre>
+ MY_TYPE & <span class="code-function">get</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Get a current element in the hash table, with his name.<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the hash requested</td></tr>
<tr><td><b>Return: </b></td><td></td><td>Reference on the Element</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8283"/><a id="8285"/><h3>operator [ ]</h3><pre>
+ MY_TYPE & <span class="code-function">operator [ ]</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>);<br/>+ <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-function">operator [ ]</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Get an copy Element an a special position<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the hash requested</td></tr>
<tr><td><b>Return: </b></td><td></td><td>An reference on the copy of selected element</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8288"/><a id="8291"/><h3>add</h3><pre>
+ <span class="code-type" >void</span> <span class="code-function">add</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>,<br/> <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-argument">_value</span>);<br/>+ <span class="code-type" >void</span> <span class="code-function">set</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>,<br/> <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-argument">_value</span>);<br/></pre>
Add an element OR set an element value<br/><b>Note:</b> add and set is the same function.<br/> <ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the value to set in the hash table.</td></tr>
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_value</span> </td><td> Value to set in the hash table.</td></tr>
</table>
</ul>
<br/>
<hr/>
<a id="8293"/><h3>remove</h3><pre>
+ <span class="code-type" >void</span> <span class="code-function">remove</span> (<span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-argument">_key</span>);<br/></pre>
Remove an element in the hash table.<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_key</span> </td><td> Name of the element to remove.</td></tr>
</table>
</ul>
<br/>
<hr/>
<a id="8295"/><h3>size</h3><pre>
+ <span class="code-type" >int32_t</span> <span class="code-function">size</span> (<span class="code-type" >void</span> <span class="code-argument"></span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Get the number of element in the hash table<br/><ul>
<table class="parameter-list">
<tr><td><b>Return: </b></td><td></td><td>number of elements</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8297"/><a id="8299"/><h3>operator [ ]</h3><pre>
+ MY_TYPE & <span class="code-function">operator [ ]</span> (size_t <span class="code-argument">_pos</span>);<br/>+ <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-function">operator [ ]</span> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
get an element with his id.<br/><b>Note:</b> this is a dangerous use of the hash table. Maybe you will use a simple vector.<br/> <ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_pos</span> </td><td> Position on the element in the hash table.</td></tr>
<tr><td><b>Return: </b></td><td></td><td>requested element at this position.</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8301"/><h3>getKey</h3><pre>
+ <span class="code-storage-keyword">const</span> <a class="code-type" href="http://www.cplusplus.com/reference/string/string/">std::string</a> & <span class="code-function">getKey</span> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/></pre>
Get the name of the element at a specific position.<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_pos</span> </td><td> Position of the element in the hash table.</td></tr>
<tr><td><b>Return: </b></td><td></td><td>name of the element (key).</td></tr></table>
</ul>
<br/>
<hr/>
<a id="8303"/><h3>getValue</h3><pre>
+ <span class="code-storage-keyword">const</span> MY_TYPE & <span class="code-function">getValue</span> (size_t <span class="code-argument">_pos</span>) <span class="code-storage-keyword">const</span>;<br/>+ MY_TYPE & <span class="code-function">getValue</span> (size_t <span class="code-argument">_pos</span>);<br/></pre>
Get a value of the hash table at a specific position.<br/><ul>
<table class="parameter-list">
<td><b>Parameter [input]:</b></td><td><span class="code-argument">_posPosition</span> </td><td> of the element in the hash table.</td></tr>
<tr><td><b>Return: </b></td><td></td><td>Value availlable at this position.</td></tr></table>
</ul>
<br/>
<hr/>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46753803-1', 'heeroyui.github.io');
ga('send', 'pageview');
</script>
</body>
</html>