/** Returns the next transactionId/positopm in the posting. Throws an exception if the * end of the posting has been reached (so be sure to use hasNextValue()). */ int nextValue() { int result = 0; int shift = 0; do { byte b = postingList.get(offset); offset++; result += (b & 127) << shift; if (b < 0) { shift += 7; } else { break; } } while (true); return result - 1; // since we stored transactionId/positions incremented by 1 }
/** Moves to the next posting in the posting list and returns true if such a posting * exists. */ boolean nextPosting() { do { offset++; if (offset >= postingList.size()) return false; } while (postingList.get(offset - 1) != 0); // previous byte is not a separator byte return true; } }
/** Is there another value in the posting? */ public boolean hasNextValue() { return offset < postingList.size() && postingList.get(offset) != 0; }
ByteArrayList temp = new ByteArrayList(postingList.size()); // copying necessary here; postingList reused for (int k = 0; k < postingList.size(); k++) { temp.add(postingList.get(k)); // bad API here; newer Trove versions support this directly