mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
529 lines
41 KiB
HTML
529 lines
41 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.2"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: Hash algorithms</title>
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">Algorithms_in_C<span id="projectnumber"> 1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.2 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('d7/d3b/group__hash.html','../../'); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#files">Files</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">Hash algorithms</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="files" name="files"></a>
|
|
Files</h2></td></tr>
|
|
<tr class="memitem:d3/d39/hash__adler32_8c"><td class="memItemLeft" align="right" valign="top">file  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/d39/hash__adler32_8c.html">hash_adler32.c</a></td></tr>
|
|
<tr class="memdesc:d3/d39/hash__adler32_8c"><td class="mdescLeft"> </td><td class="mdescRight">32-bit <a href="https://en.wikipedia.org/wiki/Adler-32" target="_blank">Adler hash</a> algorithm <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d9/dc9/hash__crc32_8c"><td class="memItemLeft" align="right" valign="top">file  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/dc9/hash__crc32_8c.html">hash_crc32.c</a></td></tr>
|
|
<tr class="memdesc:d9/dc9/hash__crc32_8c"><td class="mdescLeft"> </td><td class="mdescRight">32-bit <a href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm" target="_blank">CRC hash</a> algorithm <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d4/de3/hash__djb2_8c"><td class="memItemLeft" align="right" valign="top">file  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/de3/hash__djb2_8c.html">hash_djb2.c</a></td></tr>
|
|
<tr class="memdesc:d4/de3/hash__djb2_8c"><td class="mdescLeft"> </td><td class="mdescRight"><a href="http://www.cse.yorku.ca/~oz/hash.html" target="_blank">DJB2 hash algorithm</a> <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d7/d0c/hash__sdbm_8c"><td class="memItemLeft" align="right" valign="top">file  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d0c/hash__sdbm_8c.html">hash_sdbm.c</a></td></tr>
|
|
<tr class="memdesc:d7/d0c/hash__sdbm_8c"><td class="mdescLeft"> </td><td class="mdescRight"><a href="http://www.cse.yorku.ca/~oz/hash.html" target="_blank">SDBM hash algorithm</a> <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:d0/d57/hash__xor8_8c"><td class="memItemLeft" align="right" valign="top">file  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d57/hash__xor8_8c.html">hash_xor8.c</a></td></tr>
|
|
<tr class="memdesc:d0/d57/hash__xor8_8c"><td class="mdescLeft"> </td><td class="mdescRight">8-bit <a href="https://en.wikipedia.org/wiki/XOR_cipher" target="_blank">XOR hash</a> algorithm for ASCII characters <br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:ga506f0227a3b5f9434a503e09a3cb672b"><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a> (const char *s)</td></tr>
|
|
<tr class="memdesc:ga506f0227a3b5f9434a503e09a3cb672b"><td class="mdescLeft"> </td><td class="mdescRight">32-bit Adler algorithm implementation <a href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">More...</a><br /></td></tr>
|
|
<tr class="separator:ga506f0227a3b5f9434a503e09a3cb672b"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga994ea8b243b6c0fbef734551ec5765dd"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga994ea8b243b6c0fbef734551ec5765dd">test_adler32</a> ()</td></tr>
|
|
<tr class="memdesc:ga994ea8b243b6c0fbef734551ec5765dd"><td class="mdescLeft"> </td><td class="mdescRight">Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b" title="32-bit Adler algorithm implementation">adler32</a>. <a href="../../d7/d3b/group__hash.html#ga994ea8b243b6c0fbef734551ec5765dd">More...</a><br /></td></tr>
|
|
<tr class="separator:ga994ea8b243b6c0fbef734551ec5765dd"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga483e7ee6db1dc09a0f3e683e028ec567"><td class="memItemLeft" align="right" valign="top">uint32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a> (const char *s)</td></tr>
|
|
<tr class="memdesc:ga483e7ee6db1dc09a0f3e683e028ec567"><td class="mdescLeft"> </td><td class="mdescRight">32-bit CRC algorithm implementation <a href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">More...</a><br /></td></tr>
|
|
<tr class="separator:ga483e7ee6db1dc09a0f3e683e028ec567"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gad451622bbdca271edfa8e0d98ca422f2"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#gad451622bbdca271edfa8e0d98ca422f2">test_crc32</a> ()</td></tr>
|
|
<tr class="memdesc:gad451622bbdca271edfa8e0d98ca422f2"><td class="mdescLeft"> </td><td class="mdescRight">Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567" title="32-bit CRC algorithm implementation">crc32</a>. <a href="../../d7/d3b/group__hash.html#gad451622bbdca271edfa8e0d98ca422f2">More...</a><br /></td></tr>
|
|
<tr class="separator:gad451622bbdca271edfa8e0d98ca422f2"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga1ac362fa25f7c35d104205985f8e754b"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a> (const char *s)</td></tr>
|
|
<tr class="memdesc:ga1ac362fa25f7c35d104205985f8e754b"><td class="mdescLeft"> </td><td class="mdescRight">DJB2 algorithm implementation. <a href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">More...</a><br /></td></tr>
|
|
<tr class="separator:ga1ac362fa25f7c35d104205985f8e754b"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga9f76001544014905468dc812336110d5"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga9f76001544014905468dc812336110d5">test_djb2</a> (void)</td></tr>
|
|
<tr class="memdesc:ga9f76001544014905468dc812336110d5"><td class="mdescLeft"> </td><td class="mdescRight">Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b" title="DJB2 algorithm implementation.">djb2</a>. <a href="../../d7/d3b/group__hash.html#ga9f76001544014905468dc812336110d5">More...</a><br /></td></tr>
|
|
<tr class="separator:ga9f76001544014905468dc812336110d5"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga8ab8eeb35f8ccfcad89091b5fdd4f605"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a> (const char *s)</td></tr>
|
|
<tr class="memdesc:ga8ab8eeb35f8ccfcad89091b5fdd4f605"><td class="mdescLeft"> </td><td class="mdescRight">SDBM algorithm implementation. <a href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">More...</a><br /></td></tr>
|
|
<tr class="separator:ga8ab8eeb35f8ccfcad89091b5fdd4f605"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gab87679863646255178427a56dc33e453"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#gab87679863646255178427a56dc33e453">test_sdbm</a> ()</td></tr>
|
|
<tr class="memdesc:gab87679863646255178427a56dc33e453"><td class="mdescLeft"> </td><td class="mdescRight">Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605" title="SDBM algorithm implementation.">sdbm</a>. <a href="../../d7/d3b/group__hash.html#gab87679863646255178427a56dc33e453">More...</a><br /></td></tr>
|
|
<tr class="separator:gab87679863646255178427a56dc33e453"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gae4836b42b998b336298f3b19dcc9cdeb"><td class="memItemLeft" align="right" valign="top">uint8_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a> (const char *s)</td></tr>
|
|
<tr class="memdesc:gae4836b42b998b336298f3b19dcc9cdeb"><td class="mdescLeft"> </td><td class="mdescRight">8-bit XOR algorithm implementation <a href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">More...</a><br /></td></tr>
|
|
<tr class="separator:gae4836b42b998b336298f3b19dcc9cdeb"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga39d4c16427acbf8bbe744f6d8ed61dc0"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d3b/group__hash.html#ga39d4c16427acbf8bbe744f6d8ed61dc0">test_xor8</a> ()</td></tr>
|
|
<tr class="memdesc:ga39d4c16427acbf8bbe744f6d8ed61dc0"><td class="mdescLeft"> </td><td class="mdescRight">Test function for <a class="el" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb" title="8-bit XOR algorithm implementation">xor8</a>. <a href="../../d7/d3b/group__hash.html#ga39d4c16427acbf8bbe744f6d8ed61dc0">More...</a><br /></td></tr>
|
|
<tr class="separator:ga39d4c16427acbf8bbe744f6d8ed61dc0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<h2 class="groupheader">Function Documentation</h2>
|
|
<a id="ga506f0227a3b5f9434a503e09a3cb672b" name="ga506f0227a3b5f9434a503e09a3cb672b"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga506f0227a3b5f9434a503e09a3cb672b">◆ </a></span>adler32()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint32_t adler32 </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>32-bit Adler algorithm implementation </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>NULL terminated ASCII string to hash </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>32-bit hash result </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span>{</div>
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> uint32_t a = 1;</div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> uint32_t b = 0;</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> <span class="keyword">const</span> uint32_t MODADLER = 65521;</div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> </div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> <span class="keywordtype">size_t</span> i = 0;</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> <span class="keywordflow">while</span> (s[i] != <span class="charliteral">'\0'</span>)</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> {</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> a = (a + s[i]) % MODADLER;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> b = (b + a) % MODADLER;</div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> i++;</div>
|
|
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> }</div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="keywordflow">return</span> (b << 16) | a;</div>
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ga483e7ee6db1dc09a0f3e683e028ec567" name="ga483e7ee6db1dc09a0f3e683e028ec567"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga483e7ee6db1dc09a0f3e683e028ec567">◆ </a></span>crc32()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint32_t crc32 </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>32-bit CRC algorithm implementation </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>NULL terminated ASCII string to hash </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>32-bit hash result </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span>{</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> uint32_t crc = 0xffffffff;</div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> <span class="keywordtype">size_t</span> i = 0;</div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> <span class="keywordflow">while</span> (s[i] != <span class="charliteral">'\0'</span>)</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> {</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> uint8_t <span class="keywordtype">byte</span> = s[i];</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> crc = crc ^ byte;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> <span class="keywordflow">for</span> (uint8_t j = 8; j > 0; --j)</div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> {</div>
|
|
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> crc = (crc >> 1) ^ (0xEDB88320 & (-(crc & 1)));</div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> }</div>
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> </div>
|
|
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> i++;</div>
|
|
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> }</div>
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <span class="keywordflow">return</span> crc ^ 0xffffffff;</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ga1ac362fa25f7c35d104205985f8e754b" name="ga1ac362fa25f7c35d104205985f8e754b"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga1ac362fa25f7c35d104205985f8e754b">◆ </a></span>djb2()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint64_t djb2 </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>DJB2 algorithm implementation. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>NULL terminated string to hash </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>64-bit hash result </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span>{</div>
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> uint64_t hash = 5381; <span class="comment">/* init value */</span></div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> <span class="keywordtype">size_t</span> i = 0;</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> <span class="keywordflow">while</span> (s[i] != <span class="charliteral">'\0'</span>)</div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> {</div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> hash = ((hash << 5) + hash) + s[i];</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> i++;</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> }</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> <span class="keywordflow">return</span> hash;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ga8ab8eeb35f8ccfcad89091b5fdd4f605" name="ga8ab8eeb35f8ccfcad89091b5fdd4f605"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga8ab8eeb35f8ccfcad89091b5fdd4f605">◆ </a></span>sdbm()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint64_t sdbm </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>SDBM algorithm implementation. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>NULL terminated string to hash </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>64-bit hash result </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span>{</div>
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> uint64_t hash = 0;</div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> <span class="keywordtype">size_t</span> i = 0;</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> <span class="keywordflow">while</span> (s[i] != <span class="charliteral">'\0'</span>)</div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> {</div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> hash = s[i] + (hash << 6) + (hash << 16) - hash;</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> i++;</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> }</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> <span class="keywordflow">return</span> hash;</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ga994ea8b243b6c0fbef734551ec5765dd" name="ga994ea8b243b6c0fbef734551ec5765dd"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga994ea8b243b6c0fbef734551ec5765dd">◆ </a></span>test_adler32()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_adler32 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b" title="32-bit Adler algorithm implementation">adler32</a>. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span>{</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a>(<span class="stringliteral">"Hello World"</span>) == 403375133);</div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a>(<span class="stringliteral">"Hello World!"</span>) == 474547262);</div>
|
|
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a>(<span class="stringliteral">"Hello world"</span>) == 413860925);</div>
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a>(<span class="stringliteral">"Hello world!"</span>) == 487130206);</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> printf(<span class="stringliteral">"Tests passed\n"</span>);</div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span>}</div>
|
|
<div class="ttc" id="agroup__hash_html_ga506f0227a3b5f9434a503e09a3cb672b"><div class="ttname"><a href="../../d7/d3b/group__hash.html#ga506f0227a3b5f9434a503e09a3cb672b">adler32</a></div><div class="ttdeci">uint32_t adler32(const char *s)</div><div class="ttdoc">32-bit Adler algorithm implementation</div><div class="ttdef"><b>Definition:</b> hash_adler32.c:18</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d3b/group__hash_ga994ea8b243b6c0fbef734551ec5765dd_cgraph.svg" width="216" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="gad451622bbdca271edfa8e0d98ca422f2" name="gad451622bbdca271edfa8e0d98ca422f2"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gad451622bbdca271edfa8e0d98ca422f2">◆ </a></span>test_crc32()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_crc32 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567" title="32-bit CRC algorithm implementation">crc32</a>. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span>{</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a>(<span class="stringliteral">"Hello World"</span>) == 1243066710);</div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a>(<span class="stringliteral">"Hello World!"</span>) == 472456355);</div>
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a>(<span class="stringliteral">"Hello world"</span>) == 2346098258);</div>
|
|
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a>(<span class="stringliteral">"Hello world!"</span>) == 461707669);</div>
|
|
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> printf(<span class="stringliteral">"Tests passed\n"</span>);</div>
|
|
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span>}</div>
|
|
<div class="ttc" id="agroup__hash_html_ga483e7ee6db1dc09a0f3e683e028ec567"><div class="ttname"><a href="../../d7/d3b/group__hash.html#ga483e7ee6db1dc09a0f3e683e028ec567">crc32</a></div><div class="ttdeci">uint32_t crc32(const char *s)</div><div class="ttdoc">32-bit CRC algorithm implementation</div><div class="ttdef"><b>Definition:</b> hash_crc32.c:20</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d3b/group__hash_gad451622bbdca271edfa8e0d98ca422f2_cgraph.svg" width="196" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ga9f76001544014905468dc812336110d5" name="ga9f76001544014905468dc812336110d5"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga9f76001544014905468dc812336110d5">◆ </a></span>test_djb2()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_djb2 </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b" title="DJB2 algorithm implementation.">djb2</a>. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>none </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span>{</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a>(<span class="stringliteral">"Hello World"</span>) == 13827776004929097857);</div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a>(<span class="stringliteral">"Hello World!"</span>) == 13594750393630990530);</div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a>(<span class="stringliteral">"Hello world"</span>) == 13827776004967047329);</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a>(<span class="stringliteral">"Hello world!"</span>) == 13594750394883323106);</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> printf(<span class="stringliteral">"Tests passed\n"</span>);</div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span>}</div>
|
|
<div class="ttc" id="agroup__hash_html_ga1ac362fa25f7c35d104205985f8e754b"><div class="ttname"><a href="../../d7/d3b/group__hash.html#ga1ac362fa25f7c35d104205985f8e754b">djb2</a></div><div class="ttdeci">uint64_t djb2(const char *s)</div><div class="ttdoc">DJB2 algorithm implementation.</div><div class="ttdef"><b>Definition:</b> hash_djb2.c:18</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d3b/group__hash_ga9f76001544014905468dc812336110d5_cgraph.svg" width="180" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="gab87679863646255178427a56dc33e453" name="gab87679863646255178427a56dc33e453"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gab87679863646255178427a56dc33e453">◆ </a></span>test_sdbm()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_sdbm </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test function for <a class="el" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605" title="SDBM algorithm implementation.">sdbm</a>. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span>{</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a>(<span class="stringliteral">"Hello World"</span>) == 12881824461405877380U);</div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a>(<span class="stringliteral">"Hello World!"</span>) == 7903571203300273309);</div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a>(<span class="stringliteral">"Hello world"</span>) == 15154913742888948900U);</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a>(<span class="stringliteral">"Hello world!"</span>) == 15254999417003201661U);</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> printf(<span class="stringliteral">"Tests passed\n"</span>);</div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span>}</div>
|
|
<div class="ttc" id="agroup__hash_html_ga8ab8eeb35f8ccfcad89091b5fdd4f605"><div class="ttname"><a href="../../d7/d3b/group__hash.html#ga8ab8eeb35f8ccfcad89091b5fdd4f605">sdbm</a></div><div class="ttdeci">uint64_t sdbm(const char *s)</div><div class="ttdoc">SDBM algorithm implementation.</div><div class="ttdef"><b>Definition:</b> hash_sdbm.c:18</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d3b/group__hash_gab87679863646255178427a56dc33e453_cgraph.svg" width="196" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ga39d4c16427acbf8bbe744f6d8ed61dc0" name="ga39d4c16427acbf8bbe744f6d8ed61dc0"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ga39d4c16427acbf8bbe744f6d8ed61dc0">◆ </a></span>test_xor8()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_xor8 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test function for <a class="el" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb" title="8-bit XOR algorithm implementation">xor8</a>. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span>{</div>
|
|
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a>(<span class="stringliteral">"Hello World"</span>) == 228);</div>
|
|
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a>(<span class="stringliteral">"Hello World!"</span>) == 195);</div>
|
|
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a>(<span class="stringliteral">"Hello world"</span>) == 196);</div>
|
|
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> assert(<a class="code hl_function" href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a>(<span class="stringliteral">"Hello world!"</span>) == 163);</div>
|
|
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> printf(<span class="stringliteral">"Tests passed\n"</span>);</div>
|
|
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span>}</div>
|
|
<div class="ttc" id="agroup__hash_html_gae4836b42b998b336298f3b19dcc9cdeb"><div class="ttname"><a href="../../d7/d3b/group__hash.html#gae4836b42b998b336298f3b19dcc9cdeb">xor8</a></div><div class="ttdeci">uint8_t xor8(const char *s)</div><div class="ttdoc">8-bit XOR algorithm implementation</div><div class="ttdef"><b>Definition:</b> hash_xor8.c:19</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d3b/group__hash_ga39d4c16427acbf8bbe744f6d8ed61dc0_cgraph.svg" width="182" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="gae4836b42b998b336298f3b19dcc9cdeb" name="gae4836b42b998b336298f3b19dcc9cdeb"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#gae4836b42b998b336298f3b19dcc9cdeb">◆ </a></span>xor8()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint8_t xor8 </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>s</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>8-bit XOR algorithm implementation </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">s</td><td>NULL terminated ASCII string to hash </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>8-bit hash result </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span>{</div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> uint8_t hash = 0;</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> <span class="keywordtype">size_t</span> i = 0;</div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> <span class="keywordflow">while</span> (s[i] != <span class="charliteral">'\0'</span>)</div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> {</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> hash = (hash + s[i]) & 0xff;</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> i++;</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> }</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> <span class="keywordflow">return</span> (((hash ^ 0xff) + 1) & 0xff);</div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|