[Lemon-commits] Peter Kovacs: Unify member names in heaps (#299)

Lemon HG hg at lemon.cs.elte.hu
Mon Aug 31 20:30:37 CEST 2009


details:   http://lemon.cs.elte.hu/hg/lemon/rev/28cfac049a6a
changeset: 764:28cfac049a6a
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Wed Jul 08 17:47:01 2009 +0200
description:
	Unify member names in heaps (#299)

	The following renamings are made.

	Public members:
	 - UnderFlowPriorityError -> PriorityUnderflowError ("underflow" is
	only one word)

	Private members:
	 - bubble_up() -> bubbleUp()
	 - bubble_down() -> bubbleDown()
	 - second_child() -> secondChild()
	 - makeroot() -> makeRoot()
	 - relocate_last() -> relocateLast()
	 - data -> _data
	 - boxes -> _boxes

diffstat:

 lemon/bin_heap.h    |   26 ++++----
 lemon/bucket_heap.h |    6 +-
 lemon/fib_heap.h    |    6 +-
 lemon/radix_heap.h  |  156 ++++++++++++++++++++++++++--------------------------
 4 files changed, 97 insertions(+), 97 deletions(-)

diffs (truncated from 506 to 300 lines):

diff --git a/lemon/bin_heap.h b/lemon/bin_heap.h
--- a/lemon/bin_heap.h
+++ b/lemon/bin_heap.h
@@ -124,12 +124,12 @@
   private:
     static int parent(int i) { return (i-1)/2; }
 
-    static int second_child(int i) { return 2*i+2; }
+    static int secondChild(int i) { return 2*i+2; }
     bool less(const Pair &p1, const Pair &p2) const {
       return _comp(p1.second, p2.second);
     }
 
-    int bubble_up(int hole, Pair p) {
+    int bubbleUp(int hole, Pair p) {
       int par = parent(hole);
       while( hole>0 && less(p,_data[par]) ) {
         move(_data[par],hole);
@@ -140,8 +140,8 @@
       return hole;
     }
 
-    int bubble_down(int hole, Pair p, int length) {
-      int child = second_child(hole);
+    int bubbleDown(int hole, Pair p, int length) {
+      int child = secondChild(hole);
       while(child < length) {
         if( less(_data[child-1], _data[child]) ) {
           --child;
@@ -150,7 +150,7 @@
           goto ok;
         move(_data[child], hole);
         hole = child;
-        child = second_child(hole);
+        child = secondChild(hole);
       }
       child--;
       if( child<length && less(_data[child], p) ) {
@@ -178,7 +178,7 @@
     void push(const Pair &p) {
       int n = _data.size();
       _data.resize(n+1);
-      bubble_up(n, p);
+      bubbleUp(n, p);
     }
 
     /// \brief Insert an item into the heap with the given priority.
@@ -214,7 +214,7 @@
       int n = _data.size()-1;
       _iim.set(_data[0].first, POST_HEAP);
       if (n > 0) {
-        bubble_down(0, _data[n], n);
+        bubbleDown(0, _data[n], n);
       }
       _data.pop_back();
     }
@@ -230,8 +230,8 @@
       int n = _data.size()-1;
       _iim.set(_data[h].first, POST_HEAP);
       if( h < n ) {
-        if ( bubble_up(h, _data[n]) == h) {
-          bubble_down(h, _data[n], n);
+        if ( bubbleUp(h, _data[n]) == h) {
+          bubbleDown(h, _data[n], n);
         }
       }
       _data.pop_back();
@@ -261,10 +261,10 @@
         push(i,p);
       }
       else if( _comp(p, _data[idx].second) ) {
-        bubble_up(idx, Pair(i,p));
+        bubbleUp(idx, Pair(i,p));
       }
       else {
-        bubble_down(idx, Pair(i,p), _data.size());
+        bubbleDown(idx, Pair(i,p), _data.size());
       }
     }
 
@@ -276,7 +276,7 @@
     /// \pre \e i must be stored in the heap with priority at least \e p.
     void decrease(const Item &i, const Prio &p) {
       int idx = _iim[i];
-      bubble_up(idx, Pair(i,p));
+      bubbleUp(idx, Pair(i,p));
     }
 
     /// \brief Increase the priority of an item to the given value.
@@ -287,7 +287,7 @@
     /// \pre \e i must be stored in the heap with priority at most \e p.
     void increase(const Item &i, const Prio &p) {
       int idx = _iim[i];
-      bubble_down(idx, Pair(i,p), _data.size());
+      bubbleDown(idx, Pair(i,p), _data.size());
     }
 
     /// \brief Return the state of an item.
diff --git a/lemon/bucket_heap.h b/lemon/bucket_heap.h
--- a/lemon/bucket_heap.h
+++ b/lemon/bucket_heap.h
@@ -142,7 +142,7 @@
 
   private:
 
-    void relocate_last(int idx) {
+    void relocateLast(int idx) {
       if (idx + 1 < int(_data.size())) {
         _data[idx] = _data.back();
         if (_data[idx].prev != -1) {
@@ -243,7 +243,7 @@
       int idx = _first[_minimum];
       _iim[_data[idx].item] = -2;
       unlace(idx);
-      relocate_last(idx);
+      relocateLast(idx);
     }
 
     /// \brief Remove the given item from the heap.
@@ -256,7 +256,7 @@
       int idx = _iim[i];
       _iim[_data[idx].item] = -2;
       unlace(idx);
-      relocate_last(idx);
+      relocateLast(idx);
     }
 
     /// \brief The priority of the given item.
diff --git a/lemon/fib_heap.h b/lemon/fib_heap.h
--- a/lemon/fib_heap.h
+++ b/lemon/fib_heap.h
@@ -188,7 +188,7 @@
       if ( _data[_minimum].left_neighbor==_minimum ) {
         _data[_minimum].in=false;
         if ( _data[_minimum].degree!=0 ) {
-          makeroot(_data[_minimum].child);
+          makeRoot(_data[_minimum].child);
           _minimum=_data[_minimum].child;
           balance();
         }
@@ -201,7 +201,7 @@
           int child=_data[_minimum].child;
           int last_child=_data[child].left_neighbor;
 
-          makeroot(child);
+          makeRoot(child);
 
           _data[left].right_neighbor=child;
           _data[child].left_neighbor=left;
@@ -372,7 +372,7 @@
       } while ( s != m );
     }
 
-    void makeroot(int c) {
+    void makeRoot(int c) {
       int s=c;
       do {
         _data[s].parent=-1;
diff --git a/lemon/radix_heap.h b/lemon/radix_heap.h
--- a/lemon/radix_heap.h
+++ b/lemon/radix_heap.h
@@ -58,10 +58,10 @@
     /// This exception is thrown when an item is inserted into a
     /// RadixHeap with a priority smaller than the last erased one.
     /// \see RadixHeap
-    class UnderFlowPriorityError : public Exception {
+    class PriorityUnderflowError : public Exception {
     public:
       virtual const char* what() const throw() {
-        return "lemon::RadixHeap::UnderFlowPriorityError";
+        return "lemon::RadixHeap::PriorityUnderflowError";
       }
     };
 
@@ -94,8 +94,8 @@
       RadixBox(int _min, int _size) : first(-1), min(_min), size(_size) {}
     };
 
-    std::vector<RadixItem> data;
-    std::vector<RadixBox> boxes;
+    std::vector<RadixItem> _data;
+    std::vector<RadixBox> _boxes;
 
     ItemIntMap &_iim;
 
@@ -112,9 +112,9 @@
     RadixHeap(ItemIntMap &map, int minimum = 0, int capacity = 0)
       : _iim(map)
     {
-      boxes.push_back(RadixBox(minimum, 1));
-      boxes.push_back(RadixBox(minimum + 1, 1));
-      while (lower(boxes.size() - 1, capacity + minimum - 1)) {
+      _boxes.push_back(RadixBox(minimum, 1));
+      _boxes.push_back(RadixBox(minimum + 1, 1));
+      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
         extend();
       }
     }
@@ -122,12 +122,12 @@
     /// \brief The number of items stored in the heap.
     ///
     /// This function returns the number of items stored in the heap.
-    int size() const { return data.size(); }
+    int size() const { return _data.size(); }
 
     /// \brief Check if the heap is empty.
     ///
     /// This function returns \c true if the heap is empty.
-    bool empty() const { return data.empty(); }
+    bool empty() const { return _data.empty(); }
 
     /// \brief Make the heap empty.
     ///
@@ -139,10 +139,10 @@
     /// \param minimum The minimum value of the heap.
     /// \param capacity The capacity of the heap.
     void clear(int minimum = 0, int capacity = 0) {
-      data.clear(); boxes.clear();
-      boxes.push_back(RadixBox(minimum, 1));
-      boxes.push_back(RadixBox(minimum + 1, 1));
-      while (lower(boxes.size() - 1, capacity + minimum - 1)) {
+      _data.clear(); _boxes.clear();
+      _boxes.push_back(RadixBox(minimum, 1));
+      _boxes.push_back(RadixBox(minimum + 1, 1));
+      while (lower(_boxes.size() - 1, capacity + minimum - 1)) {
         extend();
       }
     }
@@ -150,58 +150,58 @@
   private:
 
     bool upper(int box, Prio pr) {
-      return pr < boxes[box].min;
+      return pr < _boxes[box].min;
     }
 
     bool lower(int box, Prio pr) {
-      return pr >= boxes[box].min + boxes[box].size;
+      return pr >= _boxes[box].min + _boxes[box].size;
     }
 
     // Remove item from the box list
     void remove(int index) {
-      if (data[index].prev >= 0) {
-        data[data[index].prev].next = data[index].next;
+      if (_data[index].prev >= 0) {
+        _data[_data[index].prev].next = _data[index].next;
       } else {
-        boxes[data[index].box].first = data[index].next;
+        _boxes[_data[index].box].first = _data[index].next;
       }
-      if (data[index].next >= 0) {
-        data[data[index].next].prev = data[index].prev;
+      if (_data[index].next >= 0) {
+        _data[_data[index].next].prev = _data[index].prev;
       }
     }
 
     // Insert item into the box list
     void insert(int box, int index) {
-      if (boxes[box].first == -1) {
-        boxes[box].first = index;
-        data[index].next = data[index].prev = -1;
+      if (_boxes[box].first == -1) {
+        _boxes[box].first = index;
+        _data[index].next = _data[index].prev = -1;
       } else {
-        data[index].next = boxes[box].first;
-        data[boxes[box].first].prev = index;
-        data[index].prev = -1;
-        boxes[box].first = index;
+        _data[index].next = _boxes[box].first;
+        _data[_boxes[box].first].prev = index;
+        _data[index].prev = -1;
+        _boxes[box].first = index;
       }
-      data[index].box = box;
+      _data[index].box = box;
     }
 
     // Add a new box to the box list
     void extend() {
-      int min = boxes.back().min + boxes.back().size;
-      int bs = 2 * boxes.back().size;
-      boxes.push_back(RadixBox(min, bs));
+      int min = _boxes.back().min + _boxes.back().size;
+      int bs = 2 * _boxes.back().size;
+      _boxes.push_back(RadixBox(min, bs));
     }
 
     // Move an item up into the proper box.
-    void bubble_up(int index) {
-      if (!lower(data[index].box, data[index].prio)) return;
+    void bubbleUp(int index) {
+      if (!lower(_data[index].box, _data[index].prio)) return;
       remove(index);
-      int box = findUp(data[index].box, data[index].prio);
+      int box = findUp(_data[index].box, _data[index].prio);
       insert(box, index);
     }



More information about the Lemon-commits mailing list