| 16 | import java.math.BigDecimal; |
| 17 | |
| 18 | public final class BigInt extends Number implements IHashEq{ |
| 19 | |
| 20 | private static final long serialVersionUID = 5097771279236135022L; |
| 21 | |
| 22 | final public long lpart; |
| 23 | final public BigInteger bipart; |
| 24 | |
| 25 | final public static BigInt ZERO = new BigInt(0,null); |
| 26 | final public static BigInt ONE = new BigInt(1,null); |
| 27 | |
| 28 | |
| 29 | //must follow Long |
| 30 | public int hashCode(){ |
| 31 | if(bipart == null) |
| 32 | return (int) (this.lpart ^ (this.lpart >>> 32)); |
| 33 | return bipart.hashCode(); |
| 34 | } |
| 35 | |
| 36 | public int hasheq(){ |
| 37 | if(bipart == null) |
| 38 | return Murmur3.hashLong(lpart); |
| 39 | return bipart.hashCode(); |
| 40 | |
| 41 | } |
| 42 | |
| 43 | public boolean equals(Object obj){ |
| 44 | if(this == obj) |
| 45 | return true; |
| 46 | if(obj instanceof BigInt) |
| 47 | { |
| 48 | BigInt o = (BigInt) obj; |
| 49 | if(bipart == null) |
| 50 | return o.bipart == null && this.lpart == o.lpart; |
| 51 | return o.bipart != null && this.bipart.equals(o.bipart); |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | private BigInt(long lpart, BigInteger bipart){ |
| 57 | this.lpart = lpart; |
| 58 | this.bipart = bipart; |
| 59 | } |
| 60 | |
| 61 | public static BigInt fromBigInteger(BigInteger val){ |
| 62 | if(val.bitLength() < 64) |
| 63 | return new BigInt(val.longValue(), null); |
| 64 | else |
| 65 | return new BigInt(0, val); |
| 66 | } |
| 67 | |
| 68 | public static BigInt fromLong(long val){ |
| 69 | return new BigInt(val, null); |
| 70 | } |
| 71 | |
| 72 | public BigInteger toBigInteger(){ |
| 73 | if(bipart == null) |
| 74 | return BigInteger.valueOf(lpart); |
| 75 | else |
nothing calls this directly
no outgoing calls
no test coverage detected