public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) { int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset); final byte[] lbytes = left.getBytes(), rbytes = right.getBytes(); final int loffset = left.getOffset(), roffset = right.getOffset(); for (int i = 0; i < maxCompares; ++i) { if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) { return i; } } return maxCompares; }
@Test public void testEmpty(){ Assert.assertTrue(SimpleMutableByteRange.isEmpty(null)); ByteRange r = new SimpleMutableByteRange(); Assert.assertTrue(SimpleMutableByteRange.isEmpty(r)); Assert.assertTrue(r.isEmpty()); r.set(new byte[0]); Assert.assertEquals(0, r.getBytes().length); Assert.assertEquals(0, r.getOffset()); Assert.assertEquals(0, r.getLength()); Assert.assertTrue(Bytes.equals(new byte[0], r.deepCopyToNewArray())); Assert.assertEquals(0, r.compareTo(new SimpleMutableByteRange(new byte[0], 0, 0))); Assert.assertEquals(0, r.hashCode()); }
@Test public void testBasics() { ByteRange r = new SimpleMutableByteRange(new byte[] { 1, 3, 2 }); Assert.assertFalse(SimpleMutableByteRange.isEmpty(r)); Assert.assertNotNull(r.getBytes());//should be empty byte[], but could change this behavior Assert.assertEquals(3, r.getBytes().length); Assert.assertEquals(0, r.getOffset()); Assert.assertEquals(3, r.getLength()); //cloning (deep copying) Assert.assertTrue(Bytes.equals(new byte[]{1, 3, 2}, r.deepCopyToNewArray())); Assert.assertNotSame(r.getBytes(), r.deepCopyToNewArray()); //hash code Assert.assertTrue(r.hashCode() > 0); Assert.assertEquals(r.hashCode(), r.deepCopy().hashCode()); //copying to arrays byte[] destination = new byte[]{-59};//junk r.deepCopySubRangeTo(2, 1, destination, 0); Assert.assertTrue(Bytes.equals(new byte[]{2}, destination)); //set length r.setLength(1); Assert.assertTrue(Bytes.equals(new byte[]{1}, r.deepCopyToNewArray())); r.setLength(2);//verify we retained the 2nd byte, but dangerous in real code Assert.assertTrue(Bytes.equals(new byte[]{1, 3}, r.deepCopyToNewArray())); }
@Override public ReturnCode filterCell(final Cell cell) throws IOException { if (curFamily.getBytes() == null || !(PrivateCellUtil.matchingFamily(cell, curFamily.getBytes(), curFamily.getOffset(), curFamily.getLength()))) { curFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); // For this family, all the columns can have max of curFamilyMaxVersions versions. No need to // consider the older versions for visibility label check. // Ideally this should have been done at a lower layer by HBase (?) curFamilyMaxVersions = cfVsMaxVersions.get(curFamily); // Family is changed. Just unset curQualifier. curQualifier.unset(); } if (curQualifier.getBytes() == null || !(PrivateCellUtil.matchingQualifier(cell, curQualifier.getBytes(), curQualifier.getOffset(), curQualifier.getLength()))) { curQualifier.set(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); curQualMetVersions = 0; } curQualMetVersions++; if (curQualMetVersions > curFamilyMaxVersions) { return ReturnCode.SKIP; } return this.expEvaluator.evaluate(cell) ? ReturnCode.INCLUDE : ReturnCode.SKIP; }
/******************* ByteRange *******************************/ public static ByteRange fillRowRange(Cell cell, ByteRange range) { return range.set(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); }
/** * @return true when {@code range} is of zero length, false otherwise. */ public static boolean isEmpty(ByteRange range) { return range == null || range.getLength() == 0; }
protected int store(ByteRange bytes) { int indexOfNewElement = numUniqueRanges; if (uniqueRanges.size() <= numUniqueRanges) { uniqueRanges.add(new SimpleMutableByteRange()); } ByteRange storedRange = uniqueRanges.get(numUniqueRanges); int neededBytes = numBytes + bytes.getLength(); byteAppender = ArrayUtils.growIfNecessary(byteAppender, neededBytes, 2 * neededBytes); bytes.deepCopyTo(byteAppender, numBytes); storedRange.set(byteAppender, numBytes, bytes.getLength());// this isn't valid yet numBytes += bytes.getLength(); uniqueIndexByUniqueRange.put(storedRange, indexOfNewElement); int newestUniqueIndex = numUniqueRanges; ++numUniqueRanges; return newestUniqueIndex; }
public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) { if (ranges == null) { return new ArrayList<>(0); } ArrayList<byte[]> arrays = Lists.newArrayListWithCapacity(ranges.size()); for (ByteRange range : ranges) { arrays.add(range.deepCopyToNewArray()); } return arrays; }
private Cell maybeCloneWithAllocator(Cell cell) { if (allocator == null) { return cell; } int len = KeyValueUtil.length(cell); ByteRange alloc = allocator.allocateBytes(len); if (alloc == null) { // The allocation was too large, allocator decided // not to do anything with it. return cell; } assert alloc.getBytes() != null; KeyValueUtil.appendToByteArray(cell, alloc.getBytes(), alloc.getOffset()); KeyValue newKv = new KeyValue(alloc.getBytes(), alloc.getOffset(), len); newKv.setSequenceId(cell.getSequenceId()); return newKv; }
protected int appendTokenAndRepointByteRange(final ByteRange token, int inputTokenOffset) { int newOffset = tokensLength; int inputTokenLength = token.getLength() - inputTokenOffset; int newMinimum = tokensLength + inputTokenLength; tokens = ArrayUtils.growIfNecessary(tokens, newMinimum, 2 * newMinimum); token.deepCopySubRangeTo(inputTokenOffset, inputTokenLength, tokens, tokensLength); tokensLength += inputTokenLength; return newOffset; }
public void setTokenBytes(ByteRange source) { source.deepCopySubRangeTo(0, tokenLength, token, 0); }
token, numTokenBytesToRetain); token.setLength(numTokenBytesToRetain);//shorten current token from BAA to B numOccurrences = 0;//current node is now a branch
return ReturnCode.INCLUDE; if (prevFam.getBytes() == null || !(PrivateCellUtil.matchingFamily(cell, prevFam.getBytes(), prevFam.getOffset(), prevFam.getLength()))) { prevFam.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); prevQual.unset(); if (prevQual.getBytes() == null || !(PrivateCellUtil.matchingQualifier(cell, prevQual.getBytes(), prevQual.getOffset(), prevQual.getLength()))) { prevQual.set(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); currentVersions = 0;
public static ByteRange fillQualifierRange(Cell cell, ByteRange range) { return range.set(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); }
/** * @return true when {@code range} is of zero length, false otherwise. */ public static boolean isEmpty(ByteRange range) { return range == null || range.getLength() == 0; }
protected int store(ByteRange bytes) { int indexOfNewElement = numUniqueRanges; if (uniqueRanges.size() <= numUniqueRanges) { uniqueRanges.add(new SimpleMutableByteRange()); } ByteRange storedRange = uniqueRanges.get(numUniqueRanges); int neededBytes = numBytes + bytes.getLength(); byteAppender = ArrayUtils.growIfNecessary(byteAppender, neededBytes, 2 * neededBytes); bytes.deepCopyTo(byteAppender, numBytes); storedRange.set(byteAppender, numBytes, bytes.getLength());// this isn't valid yet numBytes += bytes.getLength(); uniqueIndexByUniqueRange.put(storedRange, indexOfNewElement); int newestUniqueIndex = numUniqueRanges; ++numUniqueRanges; return newestUniqueIndex; }
public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) { if (ranges == null) { return new ArrayList<>(0); } ArrayList<byte[]> arrays = Lists.newArrayListWithCapacity(ranges.size()); for (ByteRange range : ranges) { arrays.add(range.deepCopyToNewArray()); } return arrays; }
protected int appendTokenAndRepointByteRange(final ByteRange token, int inputTokenOffset) { int newOffset = tokensLength; int inputTokenLength = token.getLength() - inputTokenOffset; int newMinimum = tokensLength + inputTokenLength; tokens = ArrayUtils.growIfNecessary(tokens, newMinimum, 2 * newMinimum); token.deepCopySubRangeTo(inputTokenOffset, inputTokenLength, tokens, tokensLength); tokensLength += inputTokenLength; return newOffset; }