/** * Compute the normalized key of the byte array. * The normalized key in Hyracks is mainly used to speedup the comparison between pointable data. * In the ByteArray case, we compute the integer value by using the first 4 bytes. * The comparator will first use this integer to get the result ( <,>, or =), it will check * the actual bytes only if the normalized key is equal. Thus this normalized key must be * consistent with the comparison result. * * @param bytesPtr * @param start * @return */ public static int normalize(byte[] bytesPtr, int start) { int len = getContentLength(bytesPtr, start); long nk = 0; start = start + getNumberBytesToStoreMeta(len); for (int i = 0; i < 4; ++i) { nk <<= 8; if (i < len) { nk |= bytesPtr[start + i] & 0xff; } } return (int) (nk >> 1); // make it always positive. }
public static ByteArrayPointable generatePointableFromPureBytes(byte[] bytes, int start, int length) { int metaLen = getNumberBytesToStoreMeta(length); byte[] ret = new byte[length + metaLen]; VarLenIntEncoderDecoder.encode(length, ret, 0); for (int i = 0; i < length; ++i) { ret[i + metaLen] = bytes[start + i]; } ByteArrayPointable ptr = new ByteArrayPointable(); ptr.set(ret, 0, ret.length); return ptr; }
@Override protected void afterReset() { contentLength = getContentLength(getByteArray(), getStartOffset()); metaLength = getNumberBytesToStoreMeta(contentLength); hash = 0; }
@Override public int compareTo(byte[] thatBytes, int thatStart, int thatLength) { int thisArrayLen = getContentLength(this.bytes, this.start); int thatArrayLen = getContentLength(thatBytes, thatStart); int thisArrayStart = this.getContentStartOffset(); int thatArrayStart = thatStart + getNumberBytesToStoreMeta(thatArrayLen); for (int thisIndex = 0, thatIndex = 0; thisIndex < thisArrayLen && thatIndex < thatArrayLen; ++thisIndex, ++thatIndex) { if (this.bytes[thisArrayStart + thisIndex] != thatBytes[thatArrayStart + thatIndex]) { return (0xff & this.bytes[thisArrayStart + thisIndex]) - (0xff & thatBytes[thatArrayStart + thatIndex]); } } return thisArrayLen - thatArrayLen; }
if (tagged) { int len = ByteArrayPointable.getContentLength(serNonTaggedAObject, offset + 1); return len + ByteArrayPointable.getNumberBytesToStoreMeta(len); } else { int len = ByteArrayPointable.getContentLength(serNonTaggedAObject, offset); return len + ByteArrayPointable.getNumberBytesToStoreMeta(len);