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

version» Context lines:

pike.git/lib/modules/ADT.pmod/Heap.pike:1:   #pike __REAL_VERSION__      //! This class implements a (min-)heap. The value of a child node will   //! always be greater than or equal to the value of its parent node.   //! Thus, the top node of the heap will always hold the smallest value.      #define SWAP(X,Y) do{ mixed tmp=values[X]; values[X]=values[Y]; values[Y]=tmp; }while(0)    - static private array values=allocate(10); - static private int num_values; + protected private array values=allocate(10); + protected private int num_values;      #ifdef DEBUG   void verify_heap()   {    for(int e=1; e<num_values; e++)    if(values[(e-1)/2] > values[e])    error("Error in HEAP (%d, %d) num_values=%d\n",    (e-1)/2, e, num_values);   }   #else   #define verify_heap()   #endif    - static void adjust_down(int elem) + protected void adjust_down(int elem)   {    while(1)    {    int child=elem*2+1;    if(child >= num_values) break;       if(child+1==num_values || values[child] < values[child+1])    {    if(values[child] < values[elem])    {
pike.git/lib/modules/ADT.pmod/Heap.pike:43:    {    SWAP(elem, child+1);    elem=child+1;    continue;    }    }    break;    }   }    - static int adjust_up(int elem) + protected int adjust_up(int elem)   {    int parent=(elem-1)/2;       if(elem && values[elem] < values[parent])    {    SWAP(elem, parent);    elem=parent;    while(elem && (values[elem] < values[parent=(elem -1)/2]))    {    SWAP(elem, parent);