use sorted flag in hashcode/equals

This commit is contained in:
2017-12-08 18:35:49 +01:00
parent 29d4e49298
commit b56f1e6688
2 changed files with 33 additions and 1 deletions

View File

@@ -645,10 +645,14 @@ public final class IntList implements Serializable, Cloneable {
@Override
public int hashCode() {
if (size == 0) {
return 0;
}
/*
* only consider values in the range of 0 to size
*/
int result = 1;
for (int i = 0; i < size; i++) {
result = 31 * result + data[i];
@@ -672,7 +676,13 @@ public final class IntList implements Serializable, Cloneable {
if (size != other.size) {
return false;
}
if (sorted != other.sorted) {
return false;
}
/*
* only consider values in the range of 0 to size
*/
for (int i = 0; i < size; i++) {
if (data[i] != other.data[i]) {
return false;