blob: 3030e3e2839b6664ae7461a10736b0fbb69da91d [file] [log] [blame]
alshabib1f44e8e2014-08-14 15:19:57 -07001package org.projectfloodlight.openflow.types;
2
3import 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
13public 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
alshabib86ac11c2014-08-14 16:14:41 -070020 /** 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
alshabib1f44e8e2014-08-14 15:19:57 -070037 /** @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);
48
alshabib86ac11c2014-08-14 16:14:41 -070049 /** 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.
alshabib1f44e8e2014-08-14 15:19:57 -070055 *
alshabib86ac11c2014-08-14 16:14:41 -070056 * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
57 *
58 * @param <H> - the hashvalue
alshabib1f44e8e2014-08-14 15:19:57 -070059 */
alshabib86ac11c2014-08-14 16:14:41 -070060 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 }
alshabib1f44e8e2014-08-14 15:19:57 -0700102}