Skip to content
Snippets Groups Projects
Commit a71c6d1c authored by zsxwing's avatar zsxwing Committed by Reynold Xin
Browse files

SPARK-1628: Add missing hashCode methods in Partitioner subclasses

JIRA: https://issues.apache.org/jira/browse/SPARK-1628

Added `hashCode` in HashPartitioner, RangePartitioner, PythonPartitioner and PageRankUtils.CustomPartitioner.

Author: zsxwing <zsxwing@gmail.com>

Closes #549 from zsxwing/SPARK-1628 and squashes the following commits:

2620936 [zsxwing] SPARK-1628: Add missing hashCode methods in Partitioner subclasses
parent ee96e940
No related branches found
No related tags found
No related merge requests found
...@@ -83,6 +83,8 @@ class HashPartitioner(partitions: Int) extends Partitioner { ...@@ -83,6 +83,8 @@ class HashPartitioner(partitions: Int) extends Partitioner {
case _ => case _ =>
false false
} }
override def hashCode: Int = numPartitions
} }
/** /**
...@@ -119,7 +121,7 @@ class RangePartitioner[K : Ordering : ClassTag, V]( ...@@ -119,7 +121,7 @@ class RangePartitioner[K : Ordering : ClassTag, V](
} }
} }
def numPartitions = partitions def numPartitions = rangeBounds.length + 1
private val binarySearch: ((Array[K], K) => Int) = CollectionsUtils.makeBinarySearch[K] private val binarySearch: ((Array[K], K) => Int) = CollectionsUtils.makeBinarySearch[K]
...@@ -155,4 +157,17 @@ class RangePartitioner[K : Ordering : ClassTag, V]( ...@@ -155,4 +157,17 @@ class RangePartitioner[K : Ordering : ClassTag, V](
case _ => case _ =>
false false
} }
override def hashCode(): Int = {
val prime = 31
var result = 1
var i = 0
while (i < rangeBounds.length) {
result = prime * result + rangeBounds(i).hashCode
i += 1
}
result = prime * result + ascending.hashCode
result
}
} }
...@@ -50,4 +50,6 @@ private[spark] class PythonPartitioner( ...@@ -50,4 +50,6 @@ private[spark] class PythonPartitioner(
case _ => case _ =>
false false
} }
override def hashCode: Int = 31 * numPartitions + pyPartitionFunctionId.hashCode
} }
...@@ -124,4 +124,6 @@ class CustomPartitioner(partitions: Int) extends Partitioner { ...@@ -124,4 +124,6 @@ class CustomPartitioner(partitions: Int) extends Partitioner {
c.numPartitions == numPartitions c.numPartitions == numPartitions
case _ => false case _ => false
} }
override def hashCode: Int = numPartitions
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment