diff --git a/h2o-algos/src/main/java/hex/knn/KNNKey.java b/h2o-algos/src/main/java/hex/knn/KNNKey.java index a2692ea97366..4b15dd0ebb96 100644 --- a/h2o-algos/src/main/java/hex/knn/KNNKey.java +++ b/h2o-algos/src/main/java/hex/knn/KNNKey.java @@ -32,12 +32,6 @@ public int hashCode() { } @Override - /** - * The compare method does not ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all cases: - * in case the this.value and o.value are the same but the keys are not same -> order of asking matters. - * In this special case x.compareTo(y) == y.compareTo(x). - * We need this functionality for ordering in TopNTreeMap, where order of asking is important to decide top N neighbours. - */ public int compareTo(KNNKey o) { if (o == null) return 1; int sameValue = this.value.compareTo(o.value); diff --git a/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java b/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java index 4096058252a7..74770c115b92 100644 --- a/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java +++ b/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java @@ -64,8 +64,8 @@ public void testKNNKeyCompareTo(){ // same key same value -> both object are the same Assert.assertEquals(k2.compareTo(k3), 0); - // different key same value -> the first is less - Assert.assertEquals(k2.compareTo(k1), -1); + // different key same value -> depends on key comparator + Assert.assertEquals(k2.compareTo(k1), 1); // same key different value -> the item with less value is less Assert.assertEquals(k3.compareTo(k4), -1);