From 14ca13efff947b2a7e65b570a83fc4029188c722 Mon Sep 17 00:00:00 2001 From: onebox-li Date: Thu, 16 Nov 2023 18:05:09 +0800 Subject: [PATCH] update method --- .../celeborn/common/meta/WorkerInfo.scala | 21 ++++++------------- .../common/meta/WorkerInfoSuite.scala | 2 -- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/common/src/main/scala/org/apache/celeborn/common/meta/WorkerInfo.scala b/common/src/main/scala/org/apache/celeborn/common/meta/WorkerInfo.scala index 4a67fbdeca7..96bb780bfc8 100644 --- a/common/src/main/scala/org/apache/celeborn/common/meta/WorkerInfo.scala +++ b/common/src/main/scala/org/apache/celeborn/common/meta/WorkerInfo.scala @@ -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 } } diff --git a/common/src/test/scala/org/apache/celeborn/common/meta/WorkerInfoSuite.scala b/common/src/test/scala/org/apache/celeborn/common/meta/WorkerInfoSuite.scala index 71dcdfb0622..b4286292488 100644 --- a/common/src/test/scala/org/apache/celeborn/common/meta/WorkerInfoSuite.scala +++ b/common/src/test/scala/org/apache/celeborn/common/meta/WorkerInfoSuite.scala @@ -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) }