final OutputBitStream frequencies = new OutputBitStream( outputBasename + DiskBasedIndex.FREQUENCIES_EXTENSION );
// To write the new term list
final PrintWriter termFile = new PrintWriter( new BufferedWriter( new OutputStreamWriter( new FileOutputStream( outputBasename + DiskBasedIndex.TERMS_EXTENSION ), "UTF-8" ), bufferSize ) );
// The current term
MutableString currTerm;
// Total number of pointers and occurrences
long numPointers = 0;
pl.expectedUpdates = writeGlobCounts ? numberOfOccurrences : -1;
pl.itemsName = writeGlobCounts ? "occurrences" : "terms";
pl.logInterval = logInterval;
pl.start( "Combining lists..." );
int totalFrequency, numTerms = 0, numUsedIndices, k;
long totalGlobCount = 0;
predictedSize = -1;
predictedLengthNumBits = -1;
// Discard first zero from offsets
if ( p != 0 ) for( InputBitStream ibs: offsets ) ibs.readGamma();
// TODO: use the front of the queue?
while( ! termQueue.isEmpty() ) {
numUsedIndices = 0;
// We read a new word from the queue, copy it and write it to the term file
currTerm = term[ k = usedIndex[ numUsedIndices++ ] = termQueue.first() ].copy();
if ( DEBUG ) System.err.println( "Merging term " + currTerm );
currTerm.println( termFile );
if ( termReader[ k ].readLine( term[ k ] ) == null ) termQueue.dequeue();
else termQueue.changed();
// Then, we extract all equal words from the queue, accumulating the set of indices in inIndex and currIndex
while( ! termQueue.isEmpty() && term[ termQueue.first() ].equals( currTerm ) ) {