Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34484
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-06-05 17:22 -0700 |
| Message-ID | <8d97fe56-983e-412d-bf46-73f46c3e1bae@googlegroups.com> (permalink) |
| Subject | Java Source of Meiyan Hash Scrambler? |
| From | bursejan@gmail.com |
Dear All,
Does somebody have Java code for the Meiyan hash scrambler.
I would like to test it against float32 and float64. These IEEE
formats have as a hashCode() in Java usually their bit
representation.
In this bit representation the mantissa is shifted to the upper
end, just after the sign and the exponent. With the result that
the hash has no sensitivity on the magnitude definining bits of
a float number.
Here is some test code:
public static void main(String[] args) {
float[] tabf = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
for (int i = 0; i < tabf.length; i++) {
float f = tabf[i];
int h = Float.hashCode(f);
System.out.println("f=" + f + ", hash(f)=" + h +
", hash(f)%4=" + (h & 3));
}
double[] tabd = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
for (int i = 0; i < tabd.length; i++) {
double d = tabd[i];
int h = Double.hashCode(d);
System.out.println("d=" + d + ", hash(d)=" + h +
", hash(d)%4=" + (h & 3));
}
String[] tabs = {".", "[]"};
for (int i = 0; i < tabs.length; i++) {
String s = tabs[i];
int h = s.hashCode();
System.out.println("s=" + s + ", hash(s)=" + h +
", hash(s)%4=" + (h & 3));
}
}
The problem is then seen here, the different floats and
doubles cannot be distinguished:
f=1.0, hash(f)=1065353216, hash(f)%4=0
f=2.0, hash(f)=1073741824, hash(f)%4=0
f=3.0, hash(f)=1077936128, hash(f)%4=0
f=4.0, hash(f)=1082130432, hash(f)%4=0
f=5.0, hash(f)=1084227584, hash(f)%4=0
f=6.0, hash(f)=1086324736, hash(f)%4=0
f=7.0, hash(f)=1088421888, hash(f)%4=0
f=8.0, hash(f)=1090519040, hash(f)%4=0
d=1.0, hash(d)=1072693248, hash(d)%4=0
d=2.0, hash(d)=1073741824, hash(d)%4=0
d=3.0, hash(d)=1074266112, hash(d)%4=0
d=4.0, hash(d)=1074790400, hash(d)%4=0
d=5.0, hash(d)=1075052544, hash(d)%4=0
d=6.0, hash(d)=1075314688, hash(d)%4=0
d=7.0, hash(d)=1075576832, hash(d)%4=0
d=8.0, hash(d)=1075838976, hash(d)%4=0
s=., hash(s)=46, hash(s)%4=2
s=[], hash(s)=2914, hash(s)%4=2
So I tryed the last phase of murmur, and look see it
works wonderful:
static int murmur(int x) {
x ^= x >> 13;
x *= 0x5bd1e995;
return x ^ (x >> 15);
}
The result is now:
f=1.0, hash(f)=17018375, murmur(hash(f))%4=3
f=2.0, hash(f)=321529428, murmur(hash(f))%4=0
f=3.0, hash(f)=473764474, murmur(hash(f))%4=2
f=4.0, hash(f)=626007712, murmur(hash(f))%4=0
f=5.0, hash(f)=702134963, murmur(hash(f))%4=3
f=6.0, hash(f)=778248902, murmur(hash(f))%4=2
f=7.0, hash(f)=854423258, murmur(hash(f))%4=2
f=8.0, hash(f)=930531053, murmur(hash(f))%4=1
d=1.0, hash(d)=1863980106, murmur(hash(d))%4=2
d=2.0, hash(d)=321529428, murmur(hash(d))%4=0
d=3.0, hash(d)=1414319576, murmur(hash(d))%4=0
d=4.0, hash(d)=1787945053, murmur(hash(d))%4=1
d=5.0, hash(d)=1241552607, murmur(hash(d))%4=3
d=6.0, hash(d)=695108322, murmur(hash(d))%4=2
d=7.0, hash(d)=148737060, murmur(hash(d))%4=0
d=8.0, hash(d)=397654631, murmur(hash(d))%4=3
s=., hash(s)=2142701481, murmur(hash(s))%4=1
s=[], hash(s)=728007875, murmur(hash(s))%4=3
But according to some stats on the web Meiyan is better.
But I couldn't figure out some code. It seems to be
variant of FNV1a.
Any ideas?
Bye
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Java Source of Meiyan Hash Scrambler? bursejan@gmail.com - 2016-06-05 17:22 -0700
Re: Java Source of Meiyan Hash Scrambler? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-06 07:48 -0400
Re: Java Source of Meiyan Hash Scrambler? Jan Burse <janburse@fastmail.fm> - 2016-06-06 14:13 +0200
TreeBins Problem and Float/Double (Was: Java Source of Meiyan Hash Scrambler?) Jan Burse <janburse@fastmail.fm> - 2016-06-06 14:45 +0200
Re: Java Source of Meiyan Hash Scrambler? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-06 08:47 -0400
Floating-point hash keys (Was: Java Source of Meiyan Hash Scrambler?) Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-06 12:02 -0400
Re: Floating-point hash keys (Was: Java Source of Meiyan Hash Scrambler?) Roedy Green <inquiry@mindprod.com> - 2016-06-09 05:33 -0700
Re: Floating-point hash keys (Was: Java Source of Meiyan Hash Scrambler?) Jan Burse <janburse@fastmail.fm> - 2016-06-09 16:27 +0200
Re: Java Source of Meiyan Hash Scrambler? Roedy Green <inquiry@mindprod.com> - 2016-06-07 03:24 -0700
Re: Java Source of Meiyan Hash Scrambler? Jan Burse <janburse@fastmail.fm> - 2016-06-07 15:38 +0200
Re: Java Source of Meiyan Hash Scrambler? Jan Burse <janburse@fastmail.fm> - 2016-06-07 15:39 +0200
Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Jan Burse <janburse@fastmail.fm> - 2016-06-07 15:42 +0200
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Roedy Green <inquiry@mindprod.com> - 2016-06-09 05:29 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Mike Amling <mamling@chaff.us> - 2016-06-09 08:00 -0500
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Eric Douglas <e.d.programmer@gmail.com> - 2016-06-09 06:07 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Jerry Stuckle <jstucklex@attglobal.net> - 2016-06-09 11:41 -0400
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Roedy Green <inquiry@mindprod.com> - 2016-06-11 01:17 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Daniel Pitts <usenet@coloraura.com> - 2016-06-11 12:31 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Mike Amling <mamling@chaff.us> - 2016-06-12 15:42 -0500
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Daniel Pitts <usenet@coloraura.com> - 2016-06-12 21:03 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Roedy Green <inquiry@mindprod.com> - 2016-06-13 14:13 -0700
Re: Sideremark II ( Re: Java Source of Meiyan Hash Scrambler?) Roedy Green <inquiry@mindprod.com> - 2016-06-10 14:11 -0700
Re: Java Source of Meiyan Hash Scrambler? Roedy Green <inquiry@mindprod.com> - 2016-06-07 20:38 -0700
Re: Java Source of Meiyan Hash Scrambler? Roedy Green <inquiry@mindprod.com> - 2016-06-09 05:15 -0700
Re: Java Source of Meiyan Hash Scrambler? Jan Burse <janburse@fastmail.fm> - 2016-06-09 16:26 +0200
Re: Java Source of Meiyan Hash Scrambler? Roedy Green <inquiry@mindprod.com> - 2016-06-12 02:28 -0700
Re: Java Source of Meiyan Hash Scrambler? j4n bur53 <janburse@fastmail.fm> - 2016-06-12 12:03 +0200
Re: Java Source of Meiyan Hash Scrambler? Andreas Leitgeb <avl@logic.at> - 2016-06-13 14:07 +0000
Re: Java Source of Meiyan Hash Scrambler? Andreas Leitgeb <avl@logic.at> - 2016-06-13 14:17 +0000
Re: Java Source of Meiyan Hash Scrambler? Andreas Leitgeb <avl@logic.at> - 2016-06-13 14:20 +0000
Re: Java Source of Meiyan Hash Scrambler? j4n bur53 <janburse@fastmail.fm> - 2016-06-13 16:23 +0200
csiph-web