File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_79) on Thu Sep 17 01:48:28 IST 2015 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hash (Solr 5.3.1 API)</title>
<meta name="date" content="2015-09-17">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Hash (Solr 5.3.1 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Hash.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/solr/common/util/FastOutputStream.html" title="class in org.apache.solr.common.util"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../org/apache/solr/common/util/Hash.LongPair.html" title="class in org.apache.solr.common.util"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/solr/common/util/Hash.html" target="_top">Frames</a></li>
<li><a href="Hash.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary: </li>
<li><a href="#nested_class_summary">Nested</a> | </li>
<li>Field | </li>
<li><a href="#constructor_summary">Constr</a> | </li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li>Field | </li>
<li><a href="#constructor_detail">Constr</a> | </li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.solr.common.util</div>
<h2 title="Class Hash" class="title">Class Hash</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>org.apache.solr.common.util.Hash</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="strong">Hash</span>
extends <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></pre>
<div class="block"><p>Fast, well distributed, cross-platform hash functions.
</p>
<p>Development background: I was surprised to discovered that there isn't a good cross-platform hash function defined for strings. MD5, SHA, FVN, etc, all define hash functions over bytes, meaning that it's under-specified for strings.
</p>
<p>So I set out to create a standard 32 bit string hash that would be well defined for implementation in all languages, have very high performance, and have very good hash properties such as distribution. After evaluating all the options, I settled on using Bob Jenkins' lookup3 as a base. It's a well studied and very fast hash function, and the hashword variant can work with 32 bits at a time (perfect for hashing unicode code points). It's also even faster on the latest JVMs which can translate pairs of shifts into native rotate instructions.
</p>
<p>The only problem with using lookup3 hashword is that it includes a length in the initial value. This would suck some performance out since directly hashing a UTF8 or UTF16 string (Java) would require a pre-scan to get the actual number of unicode code points. The solution was to simply remove the length factor, which is equivalent to biasing initVal by -(numCodePoints*4). This slightly modified lookup3 I define as lookup3ycs.
</p>
<p>So the definition of the cross-platform string hash lookup3ycs is as follows:
</p>
<p>The hash value of a character sequence (a string) is defined to be the hash of its unicode code points, according to lookup3 hashword, with the initval biased by -(length*4).
</p>
<p>So by definition
</p>
<pre>
lookup3ycs(k,offset,length,initval) == lookup3(k,offset,length,initval-(length*4))
AND
lookup3ycs(k,offset,length,initval+(length*4)) == lookup3(k,offset,length,initval)
</pre>
<p>An obvious advantage of this relationship is that you can use lookup3 if you don't have an implementation of lookup3ycs.
</p></div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== NESTED CLASS SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="nested_class_summary">
<!-- -->
</a>
<h3>Nested Class Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation">
<caption><span>Nested Classes</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Class and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static class </code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.LongPair.html" title="class in org.apache.solr.common.util">Hash.LongPair</a></strong></code>
<div class="block">128 bits of state</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#Hash()">Hash</a></strong>()</code> </td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#fmix32(int)">fmix32</a></strong>(int h)</code> </td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static long</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#fmix64(long)">fmix64</a></strong>(long k)</code> </td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static long</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#getLongLittleEndian(byte[],%20int)">getLongLittleEndian</a></strong>(byte[] buf,
int offset)</code>
<div class="block">Gets a long from a byte buffer in little endian byte order.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3(int[],%20int,%20int,%20int)">lookup3</a></strong>(int[] k,
int offset,
int length,
int initval)</code>
<div class="block">A Java implementation of hashword from lookup3.c by Bob Jenkins
(<a href="http://burtleburtle.net/bob/c/lookup3.c">original source</a>).</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3ycs(java.lang.CharSequence,%20int,%20int,%20int)">lookup3ycs</a></strong>(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> s,
int start,
int end,
int initval)</code>
<div class="block">The hash value of a character sequence is defined to be the hash of
its unicode code points, according to <a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3ycs(int[],%20int,%20int,%20int)"><code>lookup3ycs(int[] k, int offset, int length, int initval)</code></a></div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3ycs(int[],%20int,%20int,%20int)">lookup3ycs</a></strong>(int[] k,
int offset,
int length,
int initval)</code>
<div class="block">Identical to lookup3, except initval is biased by -(length<<2).</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static long</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3ycs64(java.lang.CharSequence,%20int,%20int,%20long)">lookup3ycs64</a></strong>(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> s,
int start,
int end,
long initval)</code>
<div class="block">This is the 64 bit version of lookup3ycs, corresponding to Bob Jenkin's
lookup3 hashlittle2 with initval biased by -(numCodePoints<<2).</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#murmurhash3_x64_128(byte[],%20int,%20int,%20int,%20org.apache.solr.common.util.Hash.LongPair)">murmurhash3_x64_128</a></strong>(byte[] key,
int offset,
int len,
int seed,
<a href="../../../../../org/apache/solr/common/util/Hash.LongPair.html" title="class in org.apache.solr.common.util">Hash.LongPair</a> out)</code>
<div class="block">Returns the MurmurHash3_x64_128 hash, placing the result in "out".</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#murmurhash3_x86_32(byte[],%20int,%20int,%20int)">murmurhash3_x86_32</a></strong>(byte[] data,
int offset,
int len,
int seed)</code>
<div class="block">Returns the MurmurHash3_x86_32 hash.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../../org/apache/solr/common/util/Hash.html#murmurhash3_x86_32(java.lang.CharSequence,%20int,%20int,%20int)">murmurhash3_x86_32</a></strong>(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> data,
int offset,
int len,
int seed)</code>
<div class="block">Returns the MurmurHash3_x86_32 hash of the UTF-8 bytes of the String without actually encoding
the string to a temporary buffer.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class java.lang.<a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</a>, <a href="http://download.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long,%20int)" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="Hash()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Hash</h4>
<pre>public Hash()</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="lookup3(int[], int, int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>lookup3</h4>
<pre>public static int lookup3(int[] k,
int offset,
int length,
int initval)</pre>
<div class="block">A Java implementation of hashword from lookup3.c by Bob Jenkins
(<a href="http://burtleburtle.net/bob/c/lookup3.c">original source</a>).</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>k</code> - the key to hash</dd><dd><code>offset</code> - offset of the start of the key</dd><dd><code>length</code> - length of the key</dd><dd><code>initval</code> - initial value to fold into the hash</dd>
<dt><span class="strong">Returns:</span></dt><dd>the 32 bit hash code</dd></dl>
</li>
</ul>
<a name="lookup3ycs(int[], int, int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>lookup3ycs</h4>
<pre>public static int lookup3ycs(int[] k,
int offset,
int length,
int initval)</pre>
<div class="block">Identical to lookup3, except initval is biased by -(length<<2).
This is equivalent to leaving out the length factor in the initial state.
<code>lookup3ycs(k,offset,length,initval) == lookup3(k,offset,length,initval-(length<<2))</code>
and
<code>lookup3ycs(k,offset,length,initval+(length<<2)) == lookup3(k,offset,length,initval)</code></div>
</li>
</ul>
<a name="lookup3ycs(java.lang.CharSequence, int, int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>lookup3ycs</h4>
<pre>public static int lookup3ycs(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> s,
int start,
int end,
int initval)</pre>
<div class="block"><p>The hash value of a character sequence is defined to be the hash of
its unicode code points, according to <a href="../../../../../org/apache/solr/common/util/Hash.html#lookup3ycs(int[],%20int,%20int,%20int)"><code>lookup3ycs(int[] k, int offset, int length, int initval)</code></a>
</p>
<p>If you know the number of code points in the <code>CharSequence</code>, you can
generate the same hash as the original lookup3
via <code>lookup3ycs(s, start, end, initval+(numCodePoints<<2))</code></div>
</li>
</ul>
<a name="lookup3ycs64(java.lang.CharSequence, int, int, long)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>lookup3ycs64</h4>
<pre>public static long lookup3ycs64(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> s,
int start,
int end,
long initval)</pre>
<div class="block"><p>This is the 64 bit version of lookup3ycs, corresponding to Bob Jenkin's
lookup3 hashlittle2 with initval biased by -(numCodePoints<<2). It is equivalent
to lookup3ycs in that if the high bits of initval==0, then the low bits of the
result will be the same as lookup3ycs.
</p></div>
</li>
</ul>
<a name="murmurhash3_x86_32(byte[], int, int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>murmurhash3_x86_32</h4>
<pre>public static int murmurhash3_x86_32(byte[] data,
int offset,
int len,
int seed)</pre>
<div class="block">Returns the MurmurHash3_x86_32 hash.
Original source/tests at https://github.com/yonik/java_util/</div>
</li>
</ul>
<a name="murmurhash3_x86_32(java.lang.CharSequence, int, int, int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>murmurhash3_x86_32</h4>
<pre>public static int murmurhash3_x86_32(<a href="http://download.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true" title="class or interface in java.lang">CharSequence</a> data,
int offset,
int len,
int seed)</pre>
<div class="block">Returns the MurmurHash3_x86_32 hash of the UTF-8 bytes of the String without actually encoding
the string to a temporary buffer. This is more than 2x faster than hashing the result
of String.getBytes().</div>
</li>
</ul>
<a name="fmix32(int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>fmix32</h4>
<pre>public static final int fmix32(int h)</pre>
</li>
</ul>
<a name="fmix64(long)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>fmix64</h4>
<pre>public static final long fmix64(long k)</pre>
</li>
</ul>
<a name="getLongLittleEndian(byte[], int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getLongLittleEndian</h4>
<pre>public static final long getLongLittleEndian(byte[] buf,
int offset)</pre>
<div class="block">Gets a long from a byte buffer in little endian byte order.</div>
</li>
</ul>
<a name="murmurhash3_x64_128(byte[], int, int, int, org.apache.solr.common.util.Hash.LongPair)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>murmurhash3_x64_128</h4>
<pre>public static void murmurhash3_x64_128(byte[] key,
int offset,
int len,
int seed,
<a href="../../../../../org/apache/solr/common/util/Hash.LongPair.html" title="class in org.apache.solr.common.util">Hash.LongPair</a> out)</pre>
<div class="block">Returns the MurmurHash3_x64_128 hash, placing the result in "out".</div>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Hash.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/solr/common/util/FastOutputStream.html" title="class in org.apache.solr.common.util"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../../org/apache/solr/common/util/Hash.LongPair.html" title="class in org.apache.solr.common.util"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/solr/common/util/Hash.html" target="_top">Frames</a></li>
<li><a href="Hash.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary: </li>
<li><a href="#nested_class_summary">Nested</a> | </li>
<li>Field | </li>
<li><a href="#constructor_summary">Constr</a> | </li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li>Field | </li>
<li><a href="#constructor_detail">Constr</a> | </li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>
<i>Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.</i>
<script src='../../../../../prettify.js' type='text/javascript'></script>
<script type='text/javascript'>
(function(){
var oldonload = window.onload;
if (typeof oldonload != 'function') {
window.onload = prettyPrint;
} else {
window.onload = function() {
oldonload();
prettyPrint();
}
}
})();
</script>
</small></p>
</body>
</html>