Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34490

Re: Java Source of Meiyan Hash Scrambler?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Java Source of Meiyan Hash Scrambler?
Date 2016-06-06 07:48 -0400
Organization A noiseless patient Spider
Message-ID <nj3nuq$5i8$1@dont-email.me> (permalink)
References <8d97fe56-983e-412d-bf46-73f46c3e1bae@googlegroups.com>

Show all headers | View raw


On 6/5/2016 8:22 PM, bursejan@gmail.com wrote:
> 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.

     s/usually/always/ (according to the JavaDoc).

> 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.

     Hmmm?  Float.hashCode() uses all thirty-two bits of the float,
and Double.hashCode() uses all sixty-four bits of the double.  All
the bits -- including the exponent bits -- contribute to the hashes.

> 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

     Eight different float values, eight different hashCode() values.

> 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

     Eight different double values, eight different hashCode() values.
Also, seven of the eight are different from their corresponding
Float.hashCode((float) d) values.  I do not understand why you think
they "cannot be distinguished."

>[...]
> Any ideas?

     About what?  What do you think is wrong with Float.hashCode() and
Double.hashCode() as they stand?

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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