@Override void writeValue(ReftableOutputStream os) throws IOException { int cnt = blockPos.size(); if (cnt == 0) { os.writeVarint(0); return; } if (cnt > VALUE_TYPE_MASK) { os.writeVarint(cnt); } os.writeVarint(blockPos.get(0)); for (int j = 1; j < cnt; j++) { long prior = blockPos.get(j - 1); long b = blockPos.get(j); os.writeVarint(b - prior); } } }
@Nullable LongList readBlockPositionList() { int n = valueType & VALUE_TYPE_MASK; if (n == 0) { n = readVarint32(); if (n == 0) { return null; } } LongList b = new LongList(n); b.add(readVarint64()); for (int j = 1; j < n; j++) { long prior = b.get(j - 1); b.add(prior + readVarint64()); } return b; }
/** * Pad the list with entries. * * @param toIndex * index position to stop filling at. 0 inserts no filler. 1 * ensures the list has a size of 1, adding <code>val</code> if * the list is currently empty. * @param val * value to insert into padded positions. */ public void fillTo(int toIndex, long val) { while (count < toIndex) add(val); }
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }
private boolean isCorrupt(long offset) { LongList list = corruptObjects; if (list == null) return false; synchronized (list) { return list.contains(offset); } }
@Override protected void onPackHeader(long objCnt) throws IOException { if (Integer.MAX_VALUE < objCnt) { throw new DhtException(MessageFormat.format( DhtText.get().tooManyObjectsInPack, Long.valueOf(objCnt))); } objStreamPos = new LongList((int) objCnt); objChunkPtrs = new LongList((int) objCnt); if (saveAsCachedPack == null) setSaveAsCachedPack(1000 < objCnt); }
@Override int valueType() { int cnt = blockPos.size(); return cnt != 0 && cnt <= VALUE_TYPE_MASK ? cnt : 0; }
/** * Add an entry to the end of the list. * * @param n * the number to add. */ public void add(long n) { if (count == entries.length) grow(); entries[count++] = n; }
void markScanRequired() { blockPos.clear(); }
@Nullable LongList readBlockPositionList() { int n = valueType & VALUE_TYPE_MASK; if (n == 0) { n = readVarint32(); if (n == 0) { return null; } } LongList b = new LongList(n); b.add(readVarint64()); for (int j = 1; j < n; j++) { long prior = b.get(j - 1); b.add(prior + readVarint64()); } return b; }
/** * Assign an entry in the list. * * @param index * index to set, must be in the range [0, {@link #size()}). * @param n * value to store at the position. */ public void set(int index, long n) { if (count < index) throw new ArrayIndexOutOfBoundsException(index); else if (count == index) add(n); else entries[index] = n; }
@Override protected void onBeginOfsDelta(long deltaPos, long basePos, long inflatedSize) throws IOException { long basePtr = objChunkPtrs.get(findStreamIndex(basePos)); int type = typeOf(basePtr); currType = type; currPackedSize = 0; currInflatedSize = inflatedSize; currBasePtr = basePtr; objStreamPos.add(deltaPos); ChunkFormatter w = begin(type); if (isInCurrentChunk(basePtr)) { if (w.ofsDelta(inflatedSize, w.position() - offsetOf(basePtr))) { currDataPos = w.position(); return; } endChunk(type); w = begin(type); } if (!longOfsDelta(w, inflatedSize, basePtr)) { endChunk(type); w = begin(type); if (!longOfsDelta(w, inflatedSize, basePtr)) throw panicCannotInsert(); } currDataPos = w.position(); }
boolean isCorrupt(long offset) { LongList list = corruptObjects; if (list == null) return false; synchronized (list) { return list.contains(offset); } }
@Override protected void onPackHeader(long objCnt) throws IOException { if (Integer.MAX_VALUE < objCnt) { throw new DhtException(MessageFormat.format( DhtText.get().tooManyObjectsInPack, Long.valueOf(objCnt))); } objStreamPos = new LongList((int) objCnt); objChunkPtrs = new LongList((int) objCnt); if (saveAsCachedPack == null) setSaveAsCachedPack(1000 < objCnt); }
@Override int valueType() { int cnt = blockPos.size(); return cnt != 0 && cnt <= VALUE_TYPE_MASK ? cnt : 0; }
/** * Add an entry to the end of the list. * * @param n * the number to add. */ public void add(final long n) { if (count == entries.length) grow(); entries[count++] = n; }
void markScanRequired() { blockPos.clear(); }
@Override int valueSize() { int cnt = blockPos.size(); if (cnt == 0) { return computeVarintSize(0); } int n = 0; if (cnt > VALUE_TYPE_MASK) { n += computeVarintSize(cnt); } n += computeVarintSize(blockPos.get(0)); for (int j = 1; j < cnt; j++) { long prior = blockPos.get(j - 1); long b = blockPos.get(j); n += computeVarintSize(b - prior); } return n; }