@Override public int hashCode() { int hash = 1; if (isBackedByArray()) { byte[] data = getBackingArray(); int end = offset() + length(); for (int i = offset(); i < end; i++) hash = (31 * hash) + data[i]; } else { for (int i = 0; i < length(); i++) hash = (31 * hash) + byteAt(i); } return hash; }
public static ByteSequence shorten(ByteSequence prev, ByteSequence current) { int minLen = Math.min(prev.length(), current.length()); for (int i = 0; i < minLen; i++) { int pb = 0xff & prev.byteAt(i); int cb = 0xff & current.byteAt(i); int diff = cb - pb; if (diff == 1) { int newLen = findNonFF(prev, i + 1); byte[] successor; if (newLen < prev.length()) { successor = Bytes.concat(prev.subSequence(0, newLen).toArray(), BFF); } else { successor = Bytes.concat(prev.subSequence(0, newLen).toArray(), B00); } return new ArrayByteSequence(successor); } else if (diff > 1) { byte[] copy = new byte[i + 1]; System.arraycopy(prev.subSequence(0, i + 1).toArray(), 0, copy, 0, i + 1); copy[i] = (byte) ((0xff & copy[i]) + 1); return new ArrayByteSequence(copy); } } ArrayByteSequence successor = new ArrayByteSequence(Bytes.concat(prev.toArray(), B00)); if (successor.equals(current)) { return null; } return successor; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o == null || !(o instanceof Condition)) { return false; } Condition c = (Condition) o; if (!(c.cf.equals(cf))) { return false; } if (!(c.cq.equals(cq))) { return false; } if (!(c.cv.equals(cv))) { return false; } if (!(c.val == null ? val == null : c.val.equals(val))) { return false; } if (!(c.ts == null ? ts == null : c.ts.equals(ts))) { return false; } return Arrays.equals(c.iterators, iterators); }
@Override public byte[] getBytes() { if (bsrow.isBackedByArray() && bsrow.offset() == 0) return bsrow.getBackingArray(); return bsrow.toArray(); } };
public MutableByteSequence(ByteSequence bs) { super(new byte[Math.max(64, bs.length())]); System.arraycopy(bs.getBackingArray(), bs.offset(), data, 0, bs.length()); this.length = bs.length(); this.offset = 0; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); String sep = ""; for (ByteSequence auth : auths) { sb.append(sep); sep = ","; sb.append(new String(auth.toArray(), UTF_8)); } return sb.toString(); }
Entry<Key,Value> entry = source.next(); if (entry.getKey().getRowData().equals(row)) { buffer.add(entry); } else { else { Text lastRowText = new Text(); lastRowText.set(lastRow.getBackingArray(), lastRow.offset(), lastRow.length()); Key startKey = new Key(lastRowText).followingKey(PartialKey.ROW); if (!range.afterEndKey(startKey)) {
private void consumeRow(ByteSequence row) throws IOException { // try reading a few and if still not to next row, then seek int count = 0; while (source.hasTop() && source.getTopKey().getRowData().equals(row)) { source.next(); count++; if (count >= 10) { Key nextRowStart = new Key(new Text(row.toArray())).followingKey(PartialKey.ROW); reseek(nextRowStart); count = 0; } } }
@Override public Key transform(org.apache.accumulo.core.data.Key acuKey) { byte keyData[]; ByteSequence row = acuKey.getRowData(); keyData = new byte[row.length()]; System.arraycopy(row.getBackingArray(), 0, keyData, 0, row.length()); return new Key(keyData, 1.0); }
public static float getProgress(ByteSequence start, ByteSequence end, ByteSequence position) { int maxDepth = Math.min(Math.max(end.length(), start.length()), position.length()); BigInteger startBI = new BigInteger(SplitUtils.extractBytes(start, maxDepth)); BigInteger endBI = new BigInteger(SplitUtils.extractBytes(end, maxDepth)); BigInteger positionBI = new BigInteger(SplitUtils.extractBytes(position, maxDepth)); return (float) (positionBI.subtract(startBI).doubleValue() / endBI.subtract(startBI).doubleValue()); }
public static ByteSequence parseDataType(Key k) { ByteSequence cq = k.getColumnQualifierData(); int i = cq.length(); while (cq.byteAt(--i) != 0x00) ; return cq.subSequence(++i, cq.length()); } }
@Override public int hashCode() { int result = 0; for (ByteSequence b : auths) result += b.hashCode(); return result; }
private void putByteSquence(ByteSequence data, DataOutput hasher) throws IOException { hasher.write(data.getBackingArray(), data.offset(), data.length()); }
public ConditionalMutation(ByteSequence row, Condition... conditions) { // TODO add ByteSequence methods to mutations super(row.toArray()); init(conditions); }
@Override public void next() throws IOException { if (source.hasTop()) { ByteSequence currentRow = source.getTopKey().getRowData(); ByteSequence currentColf = source.getTopKey().getColumnFamilyData(); long ts = source.getTopKey().getTimestamp(); source.next(); int count = 1; while (source.hasTop() && source.getTopKey().getRowData().equals(currentRow) && source.getTopKey().getColumnFamilyData().equals(currentColf)) { count++; source.next(); } this.key = new Key(currentRow.toArray(), currentColf.toArray(), new byte[0], new byte[0], ts); this.value = new Value(Integer.toString(count).getBytes(UTF_8)); } else { this.key = null; this.value = null; } }
@Override protected boolean accept(Key k, Value v) { return k.getColumnVisibilityData().length() == 0; } }