AshanGimhana's picture
Upload folder using huggingface_hub
9375c9a verified
raw
history blame
13.7 kB
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - hash.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2011 Davis E. King ([email protected])
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_HAsH_Hh_
<font color='#0000FF'>#define</font> DLIB_HAsH_Hh_
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='hash_abstract.h.html'>hash_abstract.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>map<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='murmur_hash3.h.html'>murmur_hash3.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>namespace</font> dlib
<b>{</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>item[<font color='#979000'>0</font>], <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>item[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>item[<font color='#979000'>0</font>], <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>item[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> alloc<font color='#5555FF'>&gt;</font>
uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>T,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>DLIB_ASSERT_HAS_STANDARD_LAYOUT</font><font face='Lucida Console'>(</font>T<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>item[<font color='#979000'>0</font>], <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>T<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> U, <font color='#0000FF'>typename</font> alloc<font color='#5555FF'>&gt;</font>
uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::pair<font color='#5555FF'>&lt;</font>T,U<font color='#5555FF'>&gt;</font>,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>DLIB_ASSERT_HAS_STANDARD_LAYOUT</font><font face='Lucida Console'>(</font>T<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>DLIB_ASSERT_HAS_STANDARD_LAYOUT</font><font face='Lucida Console'>(</font>U<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>item[<font color='#979000'>0</font>], <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>item[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>item.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> U, <font color='#0000FF'>typename</font> comp, <font color='#0000FF'>typename</font> alloc<font color='#5555FF'>&gt;</font>
uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::map<font color='#5555FF'>&lt;</font>T,U,comp,alloc<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>hash</font><font face='Lucida Console'>(</font>std::vector<font color='#5555FF'>&lt;</font>std::pair<font color='#5555FF'>&lt;</font>T,U<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, item.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
uint32 val,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3_2</font><font face='Lucida Console'>(</font>val,seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
uint64 val,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>uint32<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>murmur_hash3_128bit_3</font><font face='Lucida Console'>(</font>val,seed,<font color='#979000'>0</font><font face='Lucida Console'>)</font>.first<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::pair<font color='#5555FF'>&lt;</font>uint64,uint64<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>uint32<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>murmur_hash3_128bit_3</font><font face='Lucida Console'>(</font>item.first,item.second,seed<font face='Lucida Console'>)</font>.first<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>inline</font> uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::pair<font color='#5555FF'>&lt;</font>uint32,uint32<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>murmur_hash3_3</font><font face='Lucida Console'>(</font>item.first,item.second,seed<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> U<font color='#5555FF'>&gt;</font>
uint32 <b><a name='hash'></a>hash</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::pair<font color='#5555FF'>&lt;</font>T,U<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> item,
uint32 seed <font color='#5555FF'>=</font> <font color='#979000'>0</font>
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>hash</font><font face='Lucida Console'>(</font>item.first, seed<font face='Lucida Console'>)</font> ^ <font color='#BB00BB'>hash</font><font face='Lucida Console'>(</font>item.second, seed<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_HAsH_Hh_
</font>
</pre></body></html>