1 10 package org.mmbase.util; 11 12 13 14 54 final public class HashCodeUtil { 55 56 private static final int PRIME = 1000003; 57 58 public static final int hashCode(int source, boolean x) { 59 return PRIME * source + (x ? 1 : 0); 60 } 61 62 public static final int hashCode(int source, int x) { 63 return PRIME * source + x; 64 } 65 66 public static final int hashCode(int source, long x) { 67 return PRIME * source + (int) (PRIME * (x >>> 32) + (x & 0xFFFFFFFF)); 68 } 69 70 public static final int hashCode(int source, float x) { 71 return hashCode(source, x == 0.0F ? 0 : Float.floatToIntBits(x)); 72 } 73 74 public static final int hashCode(int source, double x) { 75 return hashCode(source, x == 0.0 ? 0L : Double.doubleToLongBits(x)); 76 } 77 78 public static final int hashCode(int source, Object x) { 79 return hashCode(source, x == null ? 0 : x.hashCode()); 80 } 81 82 public static final int hashCode(int source, boolean[] x) { 83 for (int i = 0; i < x.length; ++i) { 84 source = hashCode(source, x[i]); 85 } 86 return source; 87 } 88 89 public static final int hashCode(int source, int[] x) { 90 for (int i = 0; i < x.length; ++i) { 91 source = hashCode(source, x[i]); 92 } 93 return source; 94 } 95 96 public static final int hashCode(int source, long[] x) { 97 for (int i = 0; i < x.length; ++i) { 98 source = hashCode(source, x[i]); 99 } 100 return source; 101 } 102 103 public static final int hashCode(int source, float[] x) { 104 for (int i = 0; i < x.length; ++i) { 105 source = hashCode(source, x[i]); 106 } 107 return source; 108 } 109 110 public static final int hashCode(int source, double[] x) { 111 for (int i = 0; i < x.length; ++i) { 112 source = hashCode(source, x[i]); 113 } 114 return source; 115 } 116 117 public static final int hashCode(int source, Object [] x) { 118 for (int i = 0; i < x.length; ++i) { 119 source = hashCode(source, x[i]); 120 } 121 return source; 122 } 123 124 125 public static final int hashCodeGentle(int source, Object [] x) { 126 source = PRIME * source + x.length; 127 for (int i = 0; i < x.length; i++) { 128 source = PRIME * source + x[i].hashCode(); 129 } 130 return source; 131 } 132 133 public static final int hashCodeGentle2(int source, Object [] x) { 134 int last = x.length - 1; 135 int i = 0, j = last; 136 source = PRIME * source + last; 137 for (; i < j; i = 17 * (i + 1) >> 4, j = last - i) { 138 source = PRIME * source + x[i].hashCode(); 139 source = PRIME * source + x[j].hashCode(); 140 } 141 if (i == j) { 142 source = PRIME * source + x[i].hashCode(); 143 } 144 return source; 145 } 146 } | Popular Tags |