Skip to content

Commit

Permalink
update method
Browse files Browse the repository at this point in the history
  • Loading branch information
onebox-li committed Nov 16, 2023
1 parent 71302cb commit 14ca13e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,12 @@ class WorkerInfo(
}

override def hashCode(): Int = {
var h = hash
if (h == 0 || isZeroHash) {
val state = Array(host, rpcPort, pushPort, fetchPort, replicatePort)
var i = 0
while (i < state.length) {
h = 31 * h + state(i).hashCode()
i = i + 1
}
if (h == 0) {
isZeroHash = true
} else {
hash = h
}
}
h
var result = host.hashCode()
result = 31 * result + rpcPort.hashCode()
result = 31 * result + pushPort.hashCode()
result = 31 * result + fetchPort.hashCode()
result = 31 * result + replicatePort.hashCode()
result
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,9 @@ class WorkerInfoSuite extends CelebornFunSuite {
val state = Seq(host, rpcPort, pushPort, fetchPort, replicatePort)
val originHash = state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)

// hashCode() with while loop
val hashCode1 = workerInfo.hashCode()
assert(originHash === hashCode1)

// hashCode() with cache
val hashCode2 = workerInfo.hashCode()
assert(hashCode1 === hashCode2)
}
Expand Down

0 comments on commit 14ca13e

Please sign in to comment.