|
|
@@ -55,4 +55,28 @@ public interface HashFunction<K> {
|
|
|
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ static <K> HashFunction<K> identity() {
|
|
|
+ return IdentityHashFunction.INSTANCE;
|
|
|
+ }
|
|
|
+
|
|
|
+ final class IdentityHashFunction<K> implements HashFunction<K> {
|
|
|
+
|
|
|
+ private static final HashFunction INSTANCE = new IdentityHashFunction();
|
|
|
+
|
|
|
+ private IdentityHashFunction() {
|
|
|
+ // do nothing
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode(K object) {
|
|
|
+ return System.identityHashCode(object);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(K a, K b) {
|
|
|
+ return a == b;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|