Fix/improve hashCode for Functions
Some types of Function had hashCode methods which didn't match the behavior of equals, while others could simply be rewritten in a simpler way by using Objects.hash.
This commit is contained in:
parent
0c316226e6
commit
a74f047655
@ -136,7 +136,7 @@ public abstract class FunctionDynamic implements Function {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return functions.hashCode() + 883 * super.hashCode();
|
||||
return Arrays.hashCode(functions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,8 @@ import it.cavallium.warppi.util.Errors;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class FunctionOperator implements Function {
|
||||
|
||||
/**
|
||||
@ -175,7 +177,7 @@ public abstract class FunctionOperator implements Function {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode();
|
||||
return Objects.hash(parameter1, parameter2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class FunctionSingle implements Function {
|
||||
|
||||
private boolean simplified;
|
||||
@ -117,7 +119,7 @@ public abstract class FunctionSingle implements Function {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return parameter.hashCode() + 883 * super.hashCode();
|
||||
return Objects.hash(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,6 +8,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Variable implements Function {
|
||||
|
||||
protected char var;
|
||||
@ -84,7 +86,7 @@ public class Variable implements Function {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
return Objects.hash(var, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user