Changeset 855:65a0521e744e in lemon-main
- Timestamp:
- 09/29/09 13:32:01 (15 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
lemon/Makefile.am
r708 r855 61 61 lemon/bfs.h \ 62 62 lemon/bin_heap.h \ 63 lemon/binom _heap.h \63 lemon/binomial_heap.h \ 64 64 lemon/bucket_heap.h \ 65 65 lemon/cbc.h \ … … 73 73 lemon/cplex.h \ 74 74 lemon/dfs.h \ 75 lemon/dheap.h \ 75 76 lemon/dijkstra.h \ 76 77 lemon/dim2.h \ … … 81 82 lemon/euler.h \ 82 83 lemon/fib_heap.h \ 83 lemon/fourary_heap.h \84 84 lemon/full_graph.h \ 85 85 lemon/glpk.h \ … … 88 88 lemon/grid_graph.h \ 89 89 lemon/hypercube_graph.h \ 90 lemon/kary_heap.h \91 90 lemon/kruskal.h \ 92 91 lemon/hao_orlin.h \ … … 106 105 lemon/path.h \ 107 106 lemon/preflow.h \ 107 lemon/quad_heap.h \ 108 108 lemon/radix_heap.h \ 109 109 lemon/radix_sort.h \ -
lemon/binomial_heap.h
r707 r855 17 17 */ 18 18 19 #ifndef LEMON_BINOM _HEAP_H20 #define LEMON_BINOM _HEAP_H19 #ifndef LEMON_BINOMIAL_HEAP_H 20 #define LEMON_BINOMIAL_HEAP_H 21 21 22 22 ///\file … … 54 54 template <typename PR, typename IM, typename CMP = std::less<PR> > 55 55 #endif 56 class Binom Heap {56 class BinomialHeap { 57 57 public: 58 58 /// Type of the item-int map. … … 95 95 /// It is used internally to handle the cross references. 96 96 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 97 explicit Binom Heap(ItemIntMap &map)97 explicit BinomialHeap(ItemIntMap &map) 98 98 : _min(0), _head(-1), _iim(map), _num_items(0) {} 99 99 … … 105 105 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 106 106 /// \param comp The function object used for comparing the priorities. 107 Binom Heap(ItemIntMap &map, const Compare &comp)107 BinomialHeap(ItemIntMap &map, const Compare &comp) 108 108 : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {} 109 109 … … 425 425 426 426 class Store { 427 friend class Binom Heap;427 friend class BinomialHeap; 428 428 429 429 Item name; … … 442 442 } //namespace lemon 443 443 444 #endif //LEMON_BINOM _HEAP_H445 444 #endif //LEMON_BINOMIAL_HEAP_H 445 -
lemon/dheap.h
r706 r855 17 17 */ 18 18 19 #ifndef LEMON_ KARY_HEAP_H20 #define LEMON_ KARY_HEAP_H19 #ifndef LEMON_DHEAP_H 20 #define LEMON_DHEAP_H 21 21 22 22 ///\ingroup heaps 23 23 ///\file 24 ///\brief Fourary heap implementation.24 ///\brief D-ary heap implementation. 25 25 26 26 #include <vector> … … 32 32 /// \ingroup heaps 33 33 /// 34 ///\brief K-ary heap data structure.35 /// 36 /// This class implements the \e K-ary \e heap data structure.34 ///\brief D-ary heap data structure. 35 /// 36 /// This class implements the \e D-ary \e heap data structure. 37 37 /// It fully conforms to the \ref concepts::Heap "heap concept". 38 38 /// 39 /// The \ref KaryHeap "K-ary heap" is a generalization of the39 /// The \ref DHeap "D-ary heap" is a generalization of the 40 40 /// \ref BinHeap "binary heap" structure, its nodes have at most 41 /// \c Kchildren, instead of two.42 /// \ref BinHeap and \ref FouraryHeap are specialized implementations43 /// of this structure for <tt> K=2</tt> and <tt>K=4</tt>, respectively.41 /// \c D children, instead of two. 42 /// \ref BinHeap and \ref QuadHeap are specialized implementations 43 /// of this structure for <tt>D=2</tt> and <tt>D=4</tt>, respectively. 44 44 /// 45 45 /// \tparam PR Type of the priorities of the items. 46 46 /// \tparam IM A read-writable item map with \c int values, used 47 47 /// internally to handle the cross references. 48 /// \tparam K The degree of the heap, each node have at most \e K48 /// \tparam D The degree of the heap, each node have at most \e D 49 49 /// children. The default is 16. Powers of two are suggested to use 50 50 /// so that the multiplications and divisions needed to traverse the … … 56 56 ///\sa FouraryHeap 57 57 #ifdef DOXYGEN 58 template <typename PR, typename IM, int K, typename CMP>58 template <typename PR, typename IM, int D, typename CMP> 59 59 #else 60 template <typename PR, typename IM, int K= 16,60 template <typename PR, typename IM, int D = 16, 61 61 typename CMP = std::less<PR> > 62 62 #endif 63 class KaryHeap {63 class DHeap { 64 64 public: 65 65 /// Type of the item-int map. … … 100 100 /// It is used internally to handle the cross references. 101 101 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 102 explicit KaryHeap(ItemIntMap &map) : _iim(map) {}102 explicit DHeap(ItemIntMap &map) : _iim(map) {} 103 103 104 104 /// \brief Constructor. … … 109 109 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 110 110 /// \param comp The function object used for comparing the priorities. 111 KaryHeap(ItemIntMap &map, const Compare &comp)111 DHeap(ItemIntMap &map, const Compare &comp) 112 112 : _iim(map), _comp(comp) {} 113 113 … … 132 132 133 133 private: 134 int parent(int i) { return (i-1)/ K; }135 int firstChild(int i) { return K*i+1; }134 int parent(int i) { return (i-1)/D; } 135 int firstChild(int i) { return D*i+1; } 136 136 137 137 bool less(const Pair &p1, const Pair &p2) const { … … 152 152 if( length>1 ) { 153 153 int child = firstChild(hole); 154 while( child+ K<=length ) {154 while( child+D<=length ) { 155 155 int min=child; 156 for (int i=1; i< K; ++i) {156 for (int i=1; i<D; ++i) { 157 157 if( less(_data[child+i], _data[min]) ) 158 158 min=child+i; … … 346 346 } 347 347 348 }; // class KaryHeap348 }; // class DHeap 349 349 350 350 } // namespace lemon 351 351 352 #endif // LEMON_ KARY_HEAP_H352 #endif // LEMON_DHEAP_H -
lemon/quad_heap.h
r706 r855 17 17 */ 18 18 19 #ifndef LEMON_ FOURARY_HEAP_H20 #define LEMON_ FOURARY_HEAP_H19 #ifndef LEMON_QUAD_HEAP_H 20 #define LEMON_QUAD_HEAP_H 21 21 22 22 ///\ingroup heaps 23 23 ///\file 24 ///\brief Fourary heap implementation.24 ///\brief Fourary (quaternary) heap implementation. 25 25 26 26 #include <vector> … … 32 32 /// \ingroup heaps 33 33 /// 34 ///\brief Fourary heap data structure. 35 /// 36 /// This class implements the \e fourary \e heap data structure. 34 ///\brief Fourary (quaternary) heap data structure. 35 /// 36 /// This class implements the \e Fourary (\e quaternary) \e heap 37 /// data structure. 37 38 /// It fully conforms to the \ref concepts::Heap "heap concept". 38 39 /// 39 /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap"40 /// for <tt> K=4</tt>. It is similar to the \ref BinHeap "binary heap",40 /// The fourary heap is a specialization of the \ref DHeap "D-ary heap" 41 /// for <tt>D=4</tt>. It is similar to the \ref BinHeap "binary heap", 41 42 /// but its nodes have at most four children, instead of two. 42 43 /// … … 48 49 /// 49 50 ///\sa BinHeap 50 ///\sa KaryHeap51 ///\sa DHeap 51 52 #ifdef DOXYGEN 52 53 template <typename PR, typename IM, typename CMP> … … 54 55 template <typename PR, typename IM, typename CMP = std::less<PR> > 55 56 #endif 56 class FouraryHeap {57 class QuadHeap { 57 58 public: 58 59 /// Type of the item-int map. … … 93 94 /// It is used internally to handle the cross references. 94 95 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 95 explicit FouraryHeap(ItemIntMap &map) : _iim(map) {}96 explicit QuadHeap(ItemIntMap &map) : _iim(map) {} 96 97 97 98 /// \brief Constructor. … … 102 103 /// The assigned value must be \c PRE_HEAP (<tt>-1</tt>) for each item. 103 104 /// \param comp The function object used for comparing the priorities. 104 FouraryHeap(ItemIntMap &map, const Compare &comp)105 QuadHeap(ItemIntMap &map, const Compare &comp) 105 106 : _iim(map), _comp(comp) {} 106 107 … … 336 337 } 337 338 338 }; // class FouraryHeap339 }; // class QuadHeap 339 340 340 341 } // namespace lemon -
test/heap_test.cc
r702 r855 31 31 32 32 #include <lemon/bin_heap.h> 33 #include <lemon/ fourary_heap.h>34 #include <lemon/ kary_heap.h>33 #include <lemon/quad_heap.h> 34 #include <lemon/dheap.h> 35 35 #include <lemon/fib_heap.h> 36 36 #include <lemon/pairing_heap.h> 37 37 #include <lemon/radix_heap.h> 38 #include <lemon/binom _heap.h>38 #include <lemon/binomial_heap.h> 39 39 #include <lemon/bucket_heap.h> 40 40 … … 186 186 } 187 187 188 // FouraryHeap189 { 190 typedef FouraryHeap<Prio, ItemIntMap> IntHeap;191 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 192 heapSortTest<IntHeap>(); 193 heapIncreaseTest<IntHeap>(); 194 195 typedef FouraryHeap<Prio, IntNodeMap > NodeHeap;196 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); 197 dijkstraHeapTest<NodeHeap>(digraph, length, source); 198 } 199 200 // KaryHeap201 { 202 typedef KaryHeap<Prio, ItemIntMap> IntHeap;203 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 204 heapSortTest<IntHeap>(); 205 heapIncreaseTest<IntHeap>(); 206 207 typedef KaryHeap<Prio, IntNodeMap > NodeHeap;188 // QuadHeap 189 { 190 typedef QuadHeap<Prio, ItemIntMap> IntHeap; 191 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 192 heapSortTest<IntHeap>(); 193 heapIncreaseTest<IntHeap>(); 194 195 typedef QuadHeap<Prio, IntNodeMap > NodeHeap; 196 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); 197 dijkstraHeapTest<NodeHeap>(digraph, length, source); 198 } 199 200 // DHeap 201 { 202 typedef DHeap<Prio, ItemIntMap> IntHeap; 203 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 204 heapSortTest<IntHeap>(); 205 heapIncreaseTest<IntHeap>(); 206 207 typedef DHeap<Prio, IntNodeMap > NodeHeap; 208 208 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); 209 209 dijkstraHeapTest<NodeHeap>(digraph, length, source); … … 246 246 } 247 247 248 // Binom Heap249 { 250 typedef Binom Heap<Prio, ItemIntMap> IntHeap;251 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 252 heapSortTest<IntHeap>(); 253 heapIncreaseTest<IntHeap>(); 254 255 typedef Binom Heap<Prio, IntNodeMap > NodeHeap;248 // BinomialHeap 249 { 250 typedef BinomialHeap<Prio, ItemIntMap> IntHeap; 251 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 252 heapSortTest<IntHeap>(); 253 heapIncreaseTest<IntHeap>(); 254 255 typedef BinomialHeap<Prio, IntNodeMap > NodeHeap; 256 256 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); 257 257 dijkstraHeapTest<NodeHeap>(digraph, length, source);
Note: See TracChangeset
for help on using the changeset viewer.