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 | * |
kjwon15 | 7bc8540 | 2015-02-12 15:07:42 +0900 | [diff] [blame] | 8 | * @author Andreas Wundsam {@literal <}andreas.wundsam@bigswitch.com{@literal >} |
Andreas Wundsam | 19dfc1e | 2014-04-24 19:00:27 -0700 | [diff] [blame] | 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 | |
Andreas Wundsam | c277520 | 2014-06-30 21:31:40 -0700 | [diff] [blame] | 20 | /** perform an arithmetic addition of this value and other. Wraps around on |
| 21 | * overflow of the defined word size. |
| 22 | * |
| 23 | * @param other |
| 24 | * @return this + other |
| 25 | */ |
| 26 | H add(H other); |
| 27 | |
| 28 | /** |
| 29 | * arithmetically substract the given 'other' value from this value. |
| 30 | * around on overflow. |
| 31 | * |
| 32 | * @param other |
| 33 | * @return this - other |
| 34 | */ |
| 35 | H subtract(H other); |
| 36 | |
Andreas Wundsam | 19dfc1e | 2014-04-24 19:00:27 -0700 | [diff] [blame] | 37 | /** @return the bitwise inverse of this value */ |
| 38 | H inverse(); |
| 39 | |
| 40 | /** or this value with another value value of the same type */ |
| 41 | H or(H other); |
| 42 | |
| 43 | /** and this value with another value value of the same type */ |
| 44 | H and(H other); |
| 45 | |
| 46 | /** xor this value with another value value of the same type */ |
| 47 | H xor(H other); |
Andreas Wundsam | 3ea5f7e | 2014-07-01 12:21:28 -0700 | [diff] [blame] | 48 | |
| 49 | /** create and return a builder */ |
| 50 | Builder<H> builder(); |
| 51 | |
| 52 | /** a mutator for HashValues. Allows perfomring a series of |
| 53 | * operations on a hashv value without the associated cost of object |
| 54 | * reallocation. |
| 55 | * |
kjwon15 | 7bc8540 | 2015-02-12 15:07:42 +0900 | [diff] [blame] | 56 | * @author Andreas Wundsam {@literal <}andreas.wundsam@bigswitch.com{@literal >} |
Andreas Wundsam | 3ea5f7e | 2014-07-01 12:21:28 -0700 | [diff] [blame] | 57 | * |
| 58 | * @param <H> - the hashvalue |
| 59 | */ |
| 60 | public interface Builder<H> { |
| 61 | /** perform an arithmetic addition of this value and other. Wraps around on |
| 62 | * overflow of the defined word size. |
| 63 | * |
| 64 | * @param other |
| 65 | * @return this mutator |
| 66 | */ |
| 67 | Builder<H> add(H other); |
| 68 | |
| 69 | /** |
| 70 | * arithmetically substract the given 'other' value from the value stored in this mutator. |
| 71 | * around on overflow. |
| 72 | * |
| 73 | * @param other |
| 74 | * @return this mutator |
| 75 | */ |
| 76 | Builder<H> subtract(H other); |
| 77 | |
| 78 | /** bitwise invert the value stored in this mutator |
| 79 | * |
| 80 | * @return this mutator |
| 81 | */ |
| 82 | Builder<H> invert(); |
| 83 | |
| 84 | /** or the value stored in this mutator with another value value of the same type |
| 85 | * @return this mutator |
| 86 | */ |
| 87 | Builder<H> or(H other); |
| 88 | |
| 89 | /** and the value stored in this mutator with another value value of the same type |
| 90 | * @return this mutator |
| 91 | */ |
| 92 | Builder<H> and(H other); |
| 93 | |
| 94 | /** xor the value stored in this mutator with another value value of the same type |
| 95 | * @return this mutator |
| 96 | */ |
| 97 | Builder<H> xor(H other); |
| 98 | |
| 99 | /** @return the hash value */ |
| 100 | public H build(); |
| 101 | } |
kjwon15 | 7bc8540 | 2015-02-12 15:07:42 +0900 | [diff] [blame] | 102 | } |