sclass GlobalID implements Comparable { // We need 76 bits for 26^16 IDs long a; // lower 64 bits int b; // 76-64=12 higher bits; could be short. change to short when unstructure() is smarter *() {} *(S id) { assertGlobalID(id); BigInt value = bigint(0); for (int i = 0; i < l(id); i++) value = plus(mul(value, 26), charDiff(id.charAt(i), 'a')); ifdef GlobalID_debug print("value in constructor: " + value); endifdef a = value.longValue(); value = value.shiftRight(64); b = value.shortValue(); } toString { BigInt value = bigint(b); value = value.shiftLeft(32); value = plus(value, (a >> 32) & 0xFFFFFFFFL); value = value.shiftLeft(32); value = plus(value, a & 0xFFFFFFFFL); ifdef GlobalID_debug print("value in toString: " + value); endifdef ret bigintToGlobalID(value); } public bool equals(O o) { if (!o instanceof GlobalID) false; ret o/GlobalID.a == a && o/GlobalID.b == b; } public int hashCode() { ret (int) a; } public int compareTo(GlobalID id) { int diff = b-id.b; ret diff != 0 ? diff : Long.compareUnsigned(a, id.a); } }