KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > unimi > dsi > fastutil > HashCommon


1 package it.unimi.dsi.fastutil;
2
3 /*
4  * fastutil: Fast & compact type-specific collections for Java
5  *
6  * Copyright (C) 2002, 2003, 2004, 2005, 2006 Sebastiano Vigna
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */

23
24 /** Common code for all hash-based classes.
25  *
26  * All hashing in <code>fastutil</code> is performed starting from a 32-bit integer
27  * associated to a key or value. For all integer types smaller than <code>long</code>, we
28  * just cast. In all other cases, we do some conversion using static code in this
29  * class. Note that we follow the conventions established by the various classes
30  * associated to primitive types ({@link Boolean}, {@link Double}, etc.).
31  */

32
33 public class HashCommon {
34
35     /** This reference is used to fill keys and values of removed entries (if
36         they are objects). <code>null</code> cannot be used as it would confuse the
37         search algorithm in the presence of an actual <code>null</code> key. */

38     public static final Object JavaDoc REMOVED = new Object JavaDoc();
39
40     private HashCommon() {};
41
42     /** Returns the hash code that would be returned by {@link Float#hashCode()}.
43      *
44      * @return the same code as {@link Float#hashCode() new Float(f).hashCode()}.
45      */

46
47     final public static int float2int( final float f ) {
48         return Float.floatToRawIntBits( f );
49     }
50
51     /** Returns the hash code that would be returned by {@link Double#hashCode()}.
52      *
53      * @return the same code as {@link Double#hashCode() new Double(f).hashCode()}.
54      */

55
56     final public static int double2int( final double d ) {
57         final long l = Double.doubleToRawLongBits( d );
58         return (int)( l ^ ( l >>> 32 ) );
59     }
60
61     /** Returns the hash code that would be returned by {@link Long#hashCode()}.
62      *
63      * @return the same code as {@link Long#hashCode() new Long(f).hashCode()}.
64      */

65     final public static int long2int( final long l ) {
66         return (int)( l ^ ( l >>> 32 ) );
67     }
68 }
69
Popular Tags