Andreas Wundsam | 19dfc1e | 2014-04-24 19:00:27 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import javax.annotation.concurrent.Immutable; |
| 4 | |
| 5 | /** a hash value that supports bit-wise combinations, mainly to calculate hash values for |
| 6 | * reconciliation operations. |
| 7 | * |
| 8 | * @author Andreas Wundsam <andreas.wundsam@bigswitch.com> |
| 9 | * |
| 10 | * @param <H> - this type, for return type safety. |
| 11 | */ |
| 12 | @Immutable |
| 13 | public interface HashValue<H extends HashValue<H>> { |
| 14 | /** return the "numBits" highest-order bits of the hash. |
| 15 | * @param numBits number of higest-order bits to return [0-32]. |
| 16 | * @return a numberic value of the 0-32 highest-order bits. |
| 17 | */ |
| 18 | int prefixBits(int numBits); |
| 19 | |
| 20 | /** @return the bitwise inverse of this value */ |
| 21 | H inverse(); |
| 22 | |
| 23 | /** or this value with another value value of the same type */ |
| 24 | H or(H other); |
| 25 | |
| 26 | /** and this value with another value value of the same type */ |
| 27 | H and(H other); |
| 28 | |
| 29 | /** xor this value with another value value of the same type */ |
| 30 | H xor(H other); |
| 31 | |
| 32 | /** calculate a combined hash value of this hash value (the <b>Key</b>) and the hash value |
| 33 | * specified as a parameter (the <b>Value</b>). |
| 34 | * <p> |
| 35 | * The value is constructed as follows: |
| 36 | * <ul> |
| 37 | * <li>the first keyBits bits are taken only from the Key |
| 38 | * <li>the other bits are taken from key xor value. |
| 39 | * </ul> |
| 40 | * The overall result looks like this: |
| 41 | * <pre> |
| 42 | * MSB LSB |
| 43 | * +---------+--------------+ |
| 44 | * | key | key ^ value | |
| 45 | * +---------+--------------+ |
| 46 | * |-keyBits-| |
| 47 | * </pre> |
| 48 | * |
| 49 | * @param value - hash value to be compared with this value (the key) |
| 50 | * @param keyBits number of prefix bits that are just taken from key |
| 51 | * @return the combined value. |
| 52 | */ |
| 53 | H combineWithValue(H value, int keyBits); |
| 54 | } |