blob: 67800357e5e248dbffa5e9af0fdff2493454e13c [file] [log] [blame]
Andreas Wundsam19dfc1e2014-04-24 19:00:27 -07001package org.projectfloodlight.openflow.types;
2
3import com.google.common.base.Preconditions;
4
5public class HashValueUtils {
6 private HashValueUtils() { }
7
8 public static long combineWithValue(long key, long value, int keyBits) {
9 Preconditions.checkArgument(keyBits >= 0 && keyBits <= 64, "keyBits must be [0,64]");
10
11 int valueBits = 64 - keyBits;
12 long valueMask = valueBits == 64 ? 0xFFFFFFFFFFFFFFFFL : (1L << valueBits) - 1;
13
14 return key ^ (value & valueMask);
15 }
16
17}