/** * Sort a collection of references and write them to the reftable. * * @param refsToPack * references to sort and write. * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter sortAndWriteRefs(Collection<Ref> refsToPack) throws IOException { Iterator<RefEntry> itr = refsToPack.stream() .map(r -> new RefEntry(r, maxUpdateIndex - minUpdateIndex)) .sorted(Entry::compare) .iterator(); while (itr.hasNext()) { RefEntry entry = itr.next(); long blockPos = refs.write(entry); indexRef(entry.ref, blockPos); } return this; }
/** * Write one reference to the reftable. * <p> * References must be passed in sorted order. * * @param ref * the reference to store. * @param updateIndex * the updateIndex that modified this reference. Must be * {@code >= minUpdateIndex} for this file. * @throws java.io.IOException * if reftable cannot be written. */ public void writeRef(Ref ref, long updateIndex) throws IOException { if (updateIndex < minUpdateIndex) { throw new IllegalArgumentException(); } long d = updateIndex - minUpdateIndex; long blockPos = refs.write(new RefEntry(ref, d)); indexRef(ref, blockPos); }
/** * Sort a collection of references and write them to the reftable. * * @param refsToPack * references to sort and write. * @return {@code this} * @throws java.io.IOException * if reftable cannot be written. */ public ReftableWriter sortAndWriteRefs(Collection<Ref> refsToPack) throws IOException { Iterator<RefEntry> itr = refsToPack.stream() .map(r -> new RefEntry(r, maxUpdateIndex - minUpdateIndex)) .sorted(Entry::compare) .iterator(); while (itr.hasNext()) { RefEntry entry = itr.next(); long blockPos = refs.write(entry); indexRef(entry.ref, blockPos); } return this; }
/** * Write one reference to the reftable. * <p> * References must be passed in sorted order. * * @param ref * the reference to store. * @param updateIndex * the updateIndex that modified this reference. Must be * {@code >= minUpdateIndex} for this file. * @throws java.io.IOException * if reftable cannot be written. */ public void writeRef(Ref ref, long updateIndex) throws IOException { if (updateIndex < minUpdateIndex) { throw new IllegalArgumentException(); } long d = updateIndex - minUpdateIndex; long blockPos = refs.write(new RefEntry(ref, d)); indexRef(ref, blockPos); }