Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.linkedin.norbert.network.partitioned.loadbalancer
package com.linkedin.norbert
package network
package partitioned
package loadbalancer

/**
* Object which provides hash function implementations.
Expand All @@ -32,11 +35,14 @@ object HashFunctions {
val FNV_BASIS = 0x811c9dc5
val FNV_PRIME = (1 << 24) + 0x193

def fnv(key: Array[Byte], hash: Long): Int = {
if (key.length == 0) hash.toInt
else fnv(key.drop(1), (hash ^ (0xFF & key.first)) * FNV_PRIME)
}
var hash: Long = FNV_BASIS
var i: Int = 0
var maxIdx: Int = bytes.length

fnv(bytes, FNV_BASIS)
while (i < maxIdx) {
hash = (hash ^ (0xFF & bytes(i))) * FNV_PRIME
i += 1
}
hash.toInt
}
}