Andreas Wundsam | 19dfc1e | 2014-04-24 19:00:27 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import com.google.common.base.Preconditions; |
| 4 | |
| 5 | public 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 | } |