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

version» Context lines:

pike.git/lib/modules/ADT.pmod/Heap.pike:64:    elem=parent;    }    adjust_down(elem);    return 1;    }    return 0;   }      //! Push an element onto the heap. The heap will automatically sort itself   //! so that the smallest value will be at the top. + //! + //! @seealso + //! @[pop()], @[remove()]   void push(mixed value)   {    if(num_values >= sizeof(values))    values+=allocate(10+sizeof(values)/4);       values[num_values++]=value;    adjust_up(num_values-1);    verify_heap();   }   
pike.git/lib/modules/ADT.pmod/Heap.pike:87:   {    int pos=search(values, value);    if(pos>=0)    if(!adjust_up(pos))    adjust_down(pos);    verify_heap();   }      //! 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 + //! @[peek()], @[push()], @[remove()]   mixed pop()   {    mixed ret;    if(!num_values)    error("Heap underflow!\n");       ret=values[0];    if(sizeof(values) > 1)    {    num_values--;
pike.git/lib/modules/ADT.pmod/Heap.pike:113:    }    verify_heap();    return ret;   }      //! Returns the number of elements in the heap.   int _sizeof() { return num_values; }      //! Returns the item on top of the heap (which is also the smallest value   //! in the heap) without removing it. + //! + //! @returns + //! Returns the smallest value on the heap if any, and + //! @expr{UNDEFINED@} otherwise. + //! + //! @seealso + //! @[pop()]   mixed peek()   {    if (!num_values)    return UNDEFINED;       return values[0];   }      //! Remove a value from the heap.   //!