# HG changeset patch # User jacint # Date 1078857734 0 # Node ID 743fa50c442e37c64383a950d58ec2102085891b # Parent f1a7005e9dff74185e90d9a8a1aaf3767a4a0221 *** empty log message *** diff -r f1a7005e9dff -r 743fa50c442e src/work/jacint/fib_heap.h --- a/src/work/jacint/fib_heap.h Tue Mar 09 15:53:19 2004 +0000 +++ b/src/work/jacint/fib_heap.h Tue Mar 09 18:42:14 2004 +0000 @@ -15,8 +15,11 @@ * *bool empty() : true iff size()=0 * - *void push(Item, Prio) : pushes Item to the heap with priority Prio. If - * Item was already in the heap, it calls decrease(Item, Prio) + *void set(Item, Prio) : calls push(Item, Prio) if Item is not + * in the heap, and calls decrease/increase(Item, Prio) otherwise + * + *void push(Item, Prio) : pushes Item to the heap with priority Prio. Item + * mustn't be in the heap. * *Item top() : returns the Item with least Prio * @@ -28,13 +31,10 @@ * *void erase(Item) : deletes Item from the heap if it was already there * - *void decrease(Item, P) : If Item was not in the heap, then it calls - * push(Item, P). If item is in the heap with Prio more than P - * then sets its Prio to P. + *void decrease(Item, P) : decreases prio of Item to P. Item must be in the heap + * with prio at least P. * - *void increase(Item, P) : If Item was not in the heap, then it calls - * push(Item, P). If item is in the heap with Prio less than P - * then sets its Prio to P. + *void increase(Item, P) : sets prio of Item to P. * * *In Fibonacci heaps, increase and erase are not efficient, in case of @@ -80,42 +80,44 @@ } - bool empty() const { return blank; } + bool empty() const { return blank; } + + + void set (Item const it, PrioType const value) { + int i=iimap.get(it); + if ( i >= 0 && container[i].in ) { + if ( !comp(container[i].prio, value) ) decrease(it, value); + if ( comp(container[i].prio, value) ) increase(it, value); + } else push(it, value); + } + + void push (Item const it, PrioType const value) { + int i=iimap.get(it); + if ( i < 0 ) { + int s=container.size(); + iimap.set( it, s ); + store st; + st.name=it; + container.push_back(st); + i=s; + } + + if ( !blank ) { + container[container[minimum].right_neighbor].left_neighbor=i; + container[i].right_neighbor=container[minimum].right_neighbor; + container[minimum].right_neighbor=i; + container[i].left_neighbor=minimum; + if ( !comp( container[minimum].prio, value) ) minimum=i; + + } else { + container[i].right_neighbor=container[i].left_neighbor=i; + minimum=i; + blank=false; + } + container[i].prio=value; + } - void push (Item const it, PrioType const value) - { - - int i=iimap.get(it); - - if ( i >= 0 && container[i].in ) decrease(it, value); - else { - if ( i < 0 ) { - int s=container.size(); - iimap.set( it, s ); - store st; - st.name=it; - container.push_back(st); - i=s; - } - - if ( !blank ) { - container[container[minimum].right_neighbor].left_neighbor=i; - container[i].right_neighbor=container[minimum].right_neighbor; - container[minimum].right_neighbor=i; - container[i].left_neighbor=minimum; - if ( !comp( container[minimum].prio, value) ) minimum=i; - - - - } else { - container[i].right_neighbor=container[i].left_neighbor=i; - minimum=i; - blank=false; - } - container[i].prio=value; - } - } Item top() const { @@ -199,36 +201,22 @@ } - void decrease (Item it, PrioType const value) { - int i=iimap.get(it); - if ( i >= 0 && container[i].in ) { - - if ( comp(value, container[i].prio) ) { - container[i].prio=value; - - if ( container[i].parent!=-1 ) { - int p=container[i].parent; - - if ( !comp(container[p].prio, value) ) { - cut(i,p); - cascade(p); - if ( comp(value, container[minimum].prio) ) minimum=i; - } - } - } - } else push(it, value); - } + void decrease (Item it, PrioType const value) { + int i=iimap.get(it); + container[i].prio=value; + int p=container[i].parent; + + if ( p!=-1 && comp(value, container[p].prio) ) { + cut(i,p); + cascade(p); + if ( comp(value, container[minimum].prio) ) minimum=i; + } + } void increase (Item it, PrioType const value) { - int i=iimap.get(it); - - if ( i >= 0 && container[i].in ) { - if ( comp(container[i].prio, value) ) { - erase(it); - push(it, value); - } - } else push(it, value); + erase(it); + push(it, value); }