code: boolean addIndex(WriteStream out,
                      Page page,
                      Page newPage,
                      int saveSequence,
                      Type type,
                      int pid,
                      int nextPid,
                      int pageOffset, 
                      int pageLength,
                      Result<Integer> result)
       throws IOException
    {
      int head;
      
      while ((head = _segment.writePageIndex(_indexBuffer, 
                                         _indexTail,
                                         type.ordinal(), pid, nextPid, 
                                         pageOffset, pageLength)) < 0) {
        writeIndexBlock();
        
        // isCont is true if the new page/entry fits in the segment
        boolean isCont = _position + 2 * BLOCK_SIZE <= _indexAddress;
        
        if (! isCont) {
          // close();
  
          return false;
        }
        
        _indexAddress -= BLOCK_SIZE;
        fillHeader();
      }
      
      _isDirty = true;
      _indexTail = head;
      
      int position = pageOffset; 
      
      //System.out.print(" [" + page.getId() + ",seq=" + page.getSequence() + "]");
      
      if (isClosed()) {
        System.out.println("FLUSH_AFTER_CLOSE");
      }
      
      _pendingFlushEntries.add(new PendingEntry(page, newPage, saveSequence,
                                                position,
                                                _indexAddress, head,
                                                result));
      
      return true;
    }
docs: <pre>
  data(0)
  ...
  data(n)
  ...
  entry(m)
  entry(m-1)
  ...
  entry(0)
  </pre>