Skip to content

Commit 166a6ff

Browse files
committed
add hashcode and equals
1 parent 65f4237 commit 166a6ff

File tree

1 file changed

+12
-0
lines changed
  • mllib/src/main/scala/org/apache/spark/ml/clustering

1 file changed

+12
-0
lines changed

mllib/src/main/scala/org/apache/spark/ml/clustering/KMeans.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ class KMeansModel private[ml] (
136136

137137
@Since("1.6.0")
138138
override def write: MLWriter = new KMeansModel.KMeansModelWriter(this)
139+
140+
override def hashCode(): Int =
141+
this.getClass.hashCode() + uid.hashCode() + clusterCenters.map(_.hashCode()).sum
142+
143+
override def equals(other: Any): Boolean = other match {
144+
case that: KMeansModel =>
145+
this.uid == that.uid &&
146+
this.clusterCenters.length == that.clusterCenters.length &&
147+
this.clusterCenters.zip(that.clusterCenters)
148+
.foldLeft(true) { case (indicator, (v1, v2)) => indicator && (v1 == v2) }
149+
case _ => false
150+
}
139151
}
140152

141153
@Since("1.6.0")

0 commit comments

Comments
 (0)