Skip to content

Commit

Permalink
Resolved review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavikBaranov committed Jun 15, 2015
1 parent eaf1e68 commit 4d5b954
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class OpenHashSet[@specialized(Long, Int) T: ClassTag](
loadFactor: Double)
extends Serializable {

require(initialCapacity <= (1 << 30), "Can't make capacity bigger than 2^30 elements")
require(initialCapacity <= OpenHashSet.MAX_CAPACITY,
s"Can't make capacity bigger than ${OpenHashSet.MAX_CAPACITY} elements")
require(initialCapacity >= 1, "Invalid initial capacity")
require(loadFactor < 1.0, "Load factor must be less than 1.0")
require(loadFactor > 0.0, "Load factor must be greater than 0.0")
Expand Down Expand Up @@ -223,7 +224,8 @@ class OpenHashSet[@specialized(Long, Int) T: ClassTag](
*/
private def rehash(k: T, allocateFunc: (Int) => Unit, moveFunc: (Int, Int) => Unit) {
val newCapacity = _capacity * 2
require(newCapacity <= (1 << 30), "Can't make capacity bigger than 2^30 elements")
require(newCapacity <= OpenHashSet.MAX_CAPACITY,
s"Can't contain more than ${(loadFactor * OpenHashSet.MAX_CAPACITY).toInt} elements")
allocateFunc(newCapacity)
val newBitset = new BitSet(newCapacity)
val newData = new Array[T](newCapacity)
Expand Down Expand Up @@ -277,9 +279,10 @@ class OpenHashSet[@specialized(Long, Int) T: ClassTag](
private[spark]
object OpenHashSet {

val MAX_CAPACITY = 1 << 30
val INVALID_POS = -1
val NONEXISTENCE_MASK = 0x80000000
val POSITION_MASK = 0x7FFFFFFF
val NONEXISTENCE_MASK = 1 << 31
val POSITION_MASK = (1 << 31) - 1

/**
* A set of specialized hash function implementation to avoid boxing hash code computation
Expand Down

0 comments on commit 4d5b954

Please sign in to comment.