Skip to content

Commit 699514c

Browse files
committed
implement Comparable<Int128>
1 parent 0801666 commit 699514c

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/de/tilman_neumann/jml/base/Int128.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Tilman Neumann
3030
*/
31-
public class Int128 {
31+
public class Int128 implements Comparable<Int128> {
3232
@SuppressWarnings("unused")
3333
private static final Logger LOG = LogManager.getLogger(Int128.class);
3434

@@ -49,6 +49,26 @@ public long getLow() {
4949
return low;
5050
}
5151

52+
@Override
53+
public int compareTo(Int128 b) {
54+
return high != b.high ? Long.compareUnsigned(high, b.high) : Long.compareUnsigned(low, b.low);
55+
}
56+
57+
@Override
58+
public boolean equals(Object o) {
59+
if (o instanceof Int128) {
60+
Int128 b = (Int128) o;
61+
return high == b.high && low == b.low;
62+
}
63+
// we could treat other number classes here like Long but this is sufficient for a start
64+
return false;
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
return Long.hashCode(high) * 31 + Long.hashCode(low);
70+
}
71+
5272
/**
5373
* Add two 128 bit integers.
5474
* @param b

0 commit comments

Comments
 (0)