/**
  * Get Position instance for this absolute position; this is allowed to be arbitrarily far "in
  * the future" but cannot be before the last freeBefore.
  */
 public Position get(int pos) {
   while (pos >= nextPos) {
     // System.out.println("count=" + count + " vs len=" + positions.length);
     if (count == positions.length) {
       Position[] newPositions =
           new Position[ArrayUtil.oversize(1 + count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
       // System.out.println("grow positions " + newPositions.length);
       System.arraycopy(positions, nextWrite, newPositions, 0, positions.length - nextWrite);
       System.arraycopy(positions, 0, newPositions, positions.length - nextWrite, nextWrite);
       for (int i = positions.length; i < newPositions.length; i++) {
         newPositions[i] = new Position();
       }
       nextWrite = positions.length;
       positions = newPositions;
     }
     if (nextWrite == positions.length) {
       nextWrite = 0;
     }
     // Should have already been reset:
     assert positions[nextWrite].count == 0;
     positions[nextWrite++].pos = nextPos++;
     count++;
   }
   assert inBounds(pos);
   final int index = getIndex(pos);
   assert positions[index].pos == pos;
   return positions[index];
 }
    public void growForward() {
      forwardPos = ArrayUtil.grow(forwardPos, 1 + forwardCount);
      forwardID = ArrayUtil.grow(forwardID, 1 + forwardCount);
      forwardIndex = ArrayUtil.grow(forwardIndex, 1 + forwardCount);

      // NOTE: sneaky: grow separately because
      // ArrayUtil.grow will otherwise pick a different
      // length than the int[]s we just grew:
      final Type[] newForwardType = new Type[forwardPos.length];
      System.arraycopy(forwardType, 0, newForwardType, 0, forwardType.length);
      forwardType = newForwardType;
    }
    public void grow() {
      costs = ArrayUtil.grow(costs, 1 + count);
      lastRightID = ArrayUtil.grow(lastRightID, 1 + count);
      backPos = ArrayUtil.grow(backPos, 1 + count);
      backIndex = ArrayUtil.grow(backIndex, 1 + count);
      backID = ArrayUtil.grow(backID, 1 + count);

      // NOTE: sneaky: grow separately because
      // ArrayUtil.grow will otherwise pick a different
      // length than the int[]s we just grew:
      final Type[] newBackType = new Type[backID.length];
      System.arraycopy(backType, 0, newBackType, 0, backType.length);
      backType = newBackType;
    }