\hypertarget{murmur3__32_8c_source}{}\doxysection{murmur3\+\_\+32.\+c}
\label{murmur3__32_8c_source}\index{libkern/murmur3\_32.c@{libkern/murmur3\_32.c}}
\mbox{\hyperlink{murmur3__32_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00002}00002 \textcolor{comment}{ * Copyright (c) 2014 Dag-\/Erling Smørgrav}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00003}00003 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00004}00004 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00005}00005 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00006}00006 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00007}00007 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00008}00008 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00009}00009 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00010}00010 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00012}00012 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00013}00013 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00014}00014 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00015}00015 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00016}00016 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00017}00017 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00018}00018 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00019}00019 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00020}00020 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00021}00021 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00022}00022 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00023}00023 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00024}00024 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00025}00025 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00026}00026 \textcolor{comment}{ * \$FreeBSD\$}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00027}00027 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00028}00028 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00029}00029 \textcolor{preprocessor}{\#include <sys/hash.h>}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00030}00030 \textcolor{preprocessor}{\#include <sys/endian.h>}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00031}00031 \textcolor{preprocessor}{\#include <sys/stdint.h>}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00033}00033 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00034}\mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{00034}} \textcolor{preprocessor}{\#define rol32(i32, n) ((i32) << (n) | (i32) >> (32 -\/ (n)))}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00035}00035 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00036}00036 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00037}00037 \textcolor{comment}{ * Simple implementation of the Murmur3-\/32 hash function.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00038}00038 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00039}00039 \textcolor{comment}{ * This implementation is slow but safe.  It can be made significantly}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00040}00040 \textcolor{comment}{ * faster if the caller guarantees that the input is correctly aligned for}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00041}00041 \textcolor{comment}{ * 32-\/bit reads, and slightly faster yet if the caller guarantees that the}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00042}00042 \textcolor{comment}{ * length of the input is always a multiple of 4 bytes.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00043}00043 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00044}00044 uint32\_t}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00045}\mbox{\hyperlink{murmur3__32_8c_a38e921d3a34aac66391a80be4a5e1597}{00045}} \mbox{\hyperlink{murmur3__32_8c_a38e921d3a34aac66391a80be4a5e1597}{murmur3\_32\_hash}}(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{size\_t} len, uint32\_t seed)}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00046}00046 \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00047}00047         \textcolor{keyword}{const} uint8\_t *bytes;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00048}00048         uint32\_t hash, k;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00049}00049         \textcolor{keywordtype}{size\_t} res;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00050}00050 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00051}00051         \textcolor{comment}{/* initialization */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00052}00052         bytes = data;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00053}00053         res = len;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00054}00054         hash = seed;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00055}00055 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00056}00056         \textcolor{comment}{/* main loop */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00057}00057         \textcolor{keywordflow}{while} (res >= 4) \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00058}00058                 \textcolor{comment}{/* replace with le32toh() if input is aligned */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00059}00059                 k = le32dec(bytes);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00060}00060                 bytes += 4;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00061}00061                 res -\/= 4;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00062}00062                 k *= 0xcc9e2d51;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00063}00063                 k = \mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{rol32}}(k, 15);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00064}00064                 k *= 0x1b873593;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00065}00065                 hash \string^= k;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00066}00066                 hash = \mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{rol32}}(hash, 13);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00067}00067                 hash *= 5;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00068}00068                 hash += 0xe6546b64;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00069}00069         \}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00070}00070 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00071}00071         \textcolor{comment}{/* remainder */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00072}00072         \textcolor{comment}{/* remove if input length is a multiple of 4 */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00073}00073         \textcolor{keywordflow}{if} (res > 0) \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00074}00074                 k = 0;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00075}00075                 \textcolor{keywordflow}{switch} (res) \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00076}00076                 \textcolor{keywordflow}{case} 3:}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00077}00077                         k |= bytes[2] << 16;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00078}00078                 \textcolor{keywordflow}{case} 2:}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00079}00079                         k |= bytes[1] << 8;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00080}00080                 \textcolor{keywordflow}{case} 1:}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00081}00081                         k |= bytes[0];}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00082}00082                         k *= 0xcc9e2d51;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00083}00083                         k = \mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{rol32}}(k, 15);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00084}00084                         k *= 0x1b873593;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00085}00085                         hash \string^= k;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00086}00086                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00087}00087                 \}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00088}00088         \}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00089}00089 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00090}00090         \textcolor{comment}{/* finalize */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00091}00091         hash \string^= (uint32\_t)len;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00092}00092         hash \string^= hash >> 16;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00093}00093         hash *= 0x85ebca6b;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00094}00094         hash \string^= hash >> 13;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00095}00095         hash *= 0xc2b2ae35;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00096}00096         hash \string^= hash >> 16;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00097}00097         \textcolor{keywordflow}{return} (hash);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00098}00098 \}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00099}00099 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00100}00100 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00101}00101 \textcolor{comment}{ * Simplified version of the above optimized for aligned sequences of}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00102}00102 \textcolor{comment}{ * 32-\/bit words.  The count argument is the number of words, not the}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00103}00103 \textcolor{comment}{ * length in bytes.}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00104}00104 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00105}00105 uint32\_t}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00106}\mbox{\hyperlink{murmur3__32_8c_a7ddc9c6c049998ae55414156768d7307}{00106}} \mbox{\hyperlink{murmur3__32_8c_a7ddc9c6c049998ae55414156768d7307}{murmur3\_32\_hash32}}(\textcolor{keyword}{const} uint32\_t *data, \textcolor{keywordtype}{size\_t} count, uint32\_t seed)}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00107}00107 \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00108}00108         uint32\_t hash, k;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00109}00109         \textcolor{keywordtype}{size\_t} res;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00110}00110 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00111}00111         \textcolor{comment}{/* iterate */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00112}00112         \textcolor{keywordflow}{for} (res = count, hash = seed; res > 0; res-\/-\/, data++) \{}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00113}00113                 k = le32toh(*data);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00114}00114                 k *= 0xcc9e2d51;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00115}00115                 k = \mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{rol32}}(k, 15);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00116}00116                 k *= 0x1b873593;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00117}00117                 hash \string^= k;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00118}00118                 hash = \mbox{\hyperlink{murmur3__32_8c_a71eb850769ec5c1d357ea07bd196b296}{rol32}}(hash, 13);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00119}00119                 hash *= 5;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00120}00120                 hash += 0xe6546b64;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00121}00121         \}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00122}00122 }
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00123}00123         \textcolor{comment}{/* finalize */}}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00124}00124         hash \string^= (uint32\_t)count;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00125}00125         hash \string^= hash >> 16;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00126}00126         hash *= 0x85ebca6b;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00127}00127         hash \string^= hash >> 13;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00128}00128         hash *= 0xc2b2ae35;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00129}00129         hash \string^= hash >> 16;}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00130}00130         \textcolor{keywordflow}{return} (hash);}
\DoxyCodeLine{\Hypertarget{murmur3__32_8c_source_l00131}00131 \}}

\end{DoxyCode}
