public int Compare(byte[] x, byte[] y, int length) { CommonArray common = new CommonArray(); common.ByteArray = x; ulong[] array1 = common.UInt64Array; common.ByteArray = y; ulong[] array2 = common.UInt64Array; int len = length >> 3; int remainder = length & 7; int i = len; if (remainder > 0) { int shift = sizeof(ulong) - remainder; var v1 = (array1[i] << shift) >> shift; var v2 = (array2[i] << shift) >> shift; if (v1 < v2) { return(-1); } if (v1 > v2) { return(1); } } i--; while (i >= 0) { var v1 = array1[i]; var v2 = array2[i]; if (v1 < v2) { return(-1); } if (v1 > v2) { return(1); } i--; } return(0); }
public int Compare(byte[] x, byte[] y, int length) { CommonArray common = new CommonArray(); common.ByteArray = x; ulong[] array1 = common.UInt64Array; common.ByteArray = y; ulong[] array2 = common.UInt64Array; int len = length >> 3; for (int i = 0; i < len; i++) { var v1 = array1[i]; var v2 = array2[i]; if (v1 != v2) { for (int j = i << 3; ; j++) { byte b1 = x[j]; byte b2 = y[j]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } } } } int index = len << 3; switch (length & 7) { case 7: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 6; } case 6: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 5; } case 5: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 4; } case 4: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 3; } case 3: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 2; } case 2: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } index++; goto case 1; } case 1: { var b1 = x[index]; var b2 = y[index]; if (b1 < b2) { return(-1); } if (b1 > b2) { return(1); } break; } } return(0); }
public bool Equals(byte[] x, byte[] y) { if (x.Length != y.Length) { return(false); } CommonArray common = new CommonArray(); common.ByteArray = x; ulong[] array1 = common.UInt64Array; common.ByteArray = y; ulong[] array2 = common.UInt64Array; int length = x.Length; int remainder = length & 7; int len = length >> 3; int i = 0; while (i + 7 < len) { if (array1[i] != array2[i] || array1[i + 1] != array2[i + 1] || array1[i + 2] != array2[i + 2] || array1[i + 3] != array2[i + 3] || array1[i + 4] != array2[i + 4] || array1[i + 5] != array2[i + 5] || array1[i + 6] != array2[i + 6] || array1[i + 7] != array2[i + 7]) { return(false); } i += 8; } if (i + 3 < len) { if (array1[i] != array2[i] || array1[i + 1] != array2[i + 1] || array1[i + 2] != array2[i + 2] || array1[i + 3] != array2[i + 3]) { return(false); } i += 4; } if (i + 1 < len) { if (array1[i] != array2[i] || array1[i + 1] != array2[i + 1]) { return(false); } i += 2; } if (i < len) { if (array1[i] != array2[i]) { return(false); } i += 1; } if (remainder > 0) { int shift = sizeof(ulong) - remainder; if ((array1[i] << shift) >> shift != (array2[i] << shift) >> shift) { return(false); } } return(true); }
public bool Equals(byte[] x, byte[] y) { if (x.Length != y.Length) { return(false); } CommonArray common = new CommonArray(); common.ByteArray = x; ulong[] array1 = common.UInt64Array; common.ByteArray = y; ulong[] array2 = common.UInt64Array; int length = x.Length; int len = length >> 3; int remainder = length & 7; int i = len; if (remainder > 0) { int shift = sizeof(ulong) - remainder; if ((array1[i] << shift) >> shift != (array2[i] << shift) >> shift) { return(false); } } i--; while (i >= 7) { if (array1[i] != array2[i] || array1[i - 1] != array2[i - 1] || array1[i - 2] != array2[i - 2] || array1[i - 3] != array2[i - 3] || array1[i - 4] != array2[i - 4] || array1[i - 5] != array2[i - 5] || array1[i - 6] != array2[i - 6] || array1[i - 7] != array2[i - 7]) { return(false); } i -= 8; } if (i >= 3) { if (array1[i] != array2[i] || array1[i - 1] != array2[i - 1] || array1[i - 2] != array2[i - 2] || array1[i - 3] != array2[i - 3]) { return(false); } i -= 4; } if (i >= 1) { if (array1[i] != array2[i] || array1[i - 1] != array2[i - 1]) { return(false); } i -= 2; } if (i >= 0) { if (array1[i] != array2[i]) { return(false); } //i -= 1; } return(true); }