pike.git / lib / modules / ADT.pmod / Heap.pike

version» Context lines:

pike.git/lib/modules/ADT.pmod/Heap.pike:139:    Element ret;    if(pos>=0) {    ret = values[pos];    if(!adjust_up(pos))    adjust_down(pos);    }    verify_heap();    return ret;   }    - //! Removes and returns the item on top of the heap, + //! Removes and returns the @[Element] on top of the heap,   //! which also is the smallest value in the heap.   //! - //! @throws - //! Throws an error if the heap is empty. + //! @returns + //! Returns @[UNDEFINED] if the heap is empty.   //!   //! @seealso - //! @[peek()], @[push()], @[remove()] - mixed pop() + //! @[pop()], @[peek()], @[push()], @[remove()] + Element low_pop()   {    if(!num_values) -  error("Heap underflow!\n"); +  return UNDEFINED;       Element value = values[0];    value->pos = -1;    num_values--;    if(num_values)    {    (values[0] = values[num_values])->pos = 0;    adjust_down(0);       if(num_values * 3 + 10 < sizeof(values))    values=values[..num_values+10];    }    values[num_values]=0;    verify_heap(); -  +  return value; + } +  + //! Removes and returns the item on top of the heap, + //! which also is the smallest value in the heap. + //! + //! @throws + //! Throws an error if the heap is empty. + //! + //! @seealso + //! @[low_pop()], @[peek()], @[push()], @[remove()] + mixed pop() + { +  Element value = low_pop(); +  if(!value) +  error("Heap underflow!\n"); +     return value->value;   }      //! Returns the number of elements in the heap.   int _sizeof() { return num_values; }      //! Removes and returns the item on top of the heap,   //! which also is the smallest value in the heap.   //! @deprecated pop   __deprecated__ mixed top() { return pop(); }
pike.git/lib/modules/ADT.pmod/Heap.pike:188:   __deprecated__ int size() { return _sizeof(); }      //! Returns the @[Element] on top of the heap (which is also the one with   //! the smallest value in the heap) without removing it.   //!   //! @returns   //! Returns the smallest @[Element] on the heap if any, and   //! @expr{UNDEFINED@} otherwise.   //!   //! @seealso - //! @[peek()], @[pop()] + //! @[peek()], @[low_pop()], @[pop()]   Element low_peek()   {    if (!num_values)    return UNDEFINED;       return values[0];   }      //! Returns the item on top of the heap (which is also the smallest value   //! in the heap) without removing it.