Skip to content

Commit

Permalink
Update Hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Dec 30, 2024
1 parent f6dbd03 commit 9aa7fee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion kala-base/src/main/java/kala/function/Hasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import kala.annotations.ReplaceWith;

import java.io.Serializable;
import java.util.Objects;
import java.util.function.BiPredicate;

Expand Down
8 changes: 7 additions & 1 deletion kala-base/src/main/java/kala/function/Hashers.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package kala.function;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

Expand All @@ -24,6 +25,7 @@ final class Hashers {
static final Hasher<?> IDENTITY = new Identity<>();

private static final class Default<T> implements Hasher<T>, Serializable {
@Serial
private static final long serialVersionUID = 0L;

@Override
Expand All @@ -36,12 +38,14 @@ public String toString() {
return "Hashers.Default";
}

@Serial
private Object readResolve() {
return DEFAULT;
}
}

private static final class Optimized<T> implements Hasher<T>, Serializable {
@Serial
private static final long serialVersionUID = 0L;

@Override
Expand All @@ -51,7 +55,6 @@ public int hash(T obj) {
}

int originalHash = obj.hashCode();

return originalHash ^ (originalHash >>> 16);
}

Expand All @@ -60,12 +63,14 @@ public String toString() {
return "Hashers.Optimized";
}

@Serial
private Object readResolve() {
return OPTIMIZED;
}
}

private static final class Identity<T> implements Hasher<T>, Serializable {
@Serial
private static final long serialVersionUID = 0L;

@Override
Expand All @@ -83,6 +88,7 @@ public String toString() {
return "Hashers.Optimized";
}

@Serial
private Object readResolve() {
return IDENTITY;
}
Expand Down

0 comments on commit 9aa7fee

Please sign in to comment.