bitsOut = new BitOutputStream(bytesOut);
Iterator<Map.Entry<Integer, int[]>> it = termPositionsMap.entrySet().iterator();
Map.Entry<Integer, int[]> posting = it.next();
int[] positions = posting.getValue();
TermPositions tp = new TermPositions();
// Write out the first termid.
int lastTerm = posting.getKey().intValue();
bitsOut.writeBinary(32, lastTerm);
// Write out the tf value.
bitsOut.writeGamma((short) positions.length);
tp.set(positions, (short) positions.length);
// Write out the positions.
writePositions(bitsOut, tp);
int curTerm;
while (it.hasNext()) {
posting = it.next();
curTerm = posting.getKey().intValue();
positions = posting.getValue();
int tgap = curTerm - lastTerm;
if (tgap <= 0) {
throw new RuntimeException("Error: encountered invalid t-gap. termid=" + curTerm);
}
// Write out the gap.
bitsOut.writeGamma(tgap);
tp.set(positions, (short) positions.length);
// Write out the tf value.
bitsOut.writeGamma((short) positions.length);
// Write out the positions.
writePositions(bitsOut, tp);
lastTerm = curTerm;