public void gotoMark() {
   for (int i = 0; i < _free; i++) {
     _heap[i].gotoMark();
   }
   // rebuild heap after call last() function. fix for bug 20913
   for (int i = (_heapSize = _cachedHeapSize) / 2; i >= 0; i--) {
     heapify(i);
   }
   _returnedLast = _cachedReturnedLast;
 }
  public DTMAxisIterator reset() {
    for (int i = 0; i < _free; i++) {
      _heap[i].reset();
      _heap[i].step();
    }

    // build heap
    for (int i = (_heapSize = _free) / 2; i >= 0; i--) {
      heapify(i);
    }

    _returnedLast = END;
    return resetPosition();
  }
 public int next() {
   while (_heapSize > 0) {
     final int smallest = _heap[0]._node;
     if (smallest == END) { // iterator _heap[0] is done
       if (_heapSize > 1) {
         // Swap first and last (iterator must be restartable)
         final HeapNode temp = _heap[0];
         _heap[0] = _heap[--_heapSize];
         _heap[_heapSize] = temp;
       } else {
         return END;
       }
     } else if (smallest == _returnedLast) { // duplicate
       _heap[0].step(); // value consumed
     } else {
       _heap[0].step(); // value consumed
       heapify(0);
       return returnNode(_returnedLast = smallest);
     }
     // fallthrough if not returned above
     heapify(0);
   }
   return END;
 }
 public DTMAxisIterator setStartNode(int node) {
   if (_isRestartable) {
     _startNode = node;
     for (int i = 0; i < _free; i++) {
       if (!_heap[i]._isStartSet) {
         _heap[i].setStartNode(node);
         _heap[i].step(); // to get the first node
         _heap[i]._isStartSet = true;
       }
     }
     // build heap
     for (int i = (_heapSize = _free) / 2; i >= 0; i--) {
       heapify(i);
     }
     _returnedLast = END;
     return resetPosition();
   }
   return this;
 }