public static int Compare(Key a, Key b) { // if (a.length != b.length) throw new Exception("Cannot compare keys of different length."); int r = memcmp(a.bytes, b.bytes, Math.Min(a.bytes.Length, b.bytes.Length)); if (r != 0) return r; int al = a.bytes.Length, bl = b.bytes.Length; if (al < bl && IsNotEmpty(b.bytes, al, bl)) return -1; if (al > bl && IsNotEmpty(a.bytes, bl, al)) return 1; return 0; }
public int CompareTo(Key other) { return Compare(this, other); }
// Micro optimization public static Key Composite(Key a, Key b) { Key i; i.length = a.length + b.length; i.bytes = new byte[i.length]; Buffer.BlockCopy(a.bytes, 0, i.bytes, 0, Math.Min(a.bytes.Length, a.length)); Buffer.BlockCopy(b.bytes, 0, i.bytes, a.length, Math.Min(b.bytes.Length, b.length)); return i; }