Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
heap.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file heap.hh
11 /// @brief class definition for a heap object based on Charlie
12 /// Strauss's heap code ported over from rosetta++. Stores a sorted list of
13 /// integers based on floating-point values.
14 /// @author James Thompson
15 
16 #ifndef INCLUDED_utility_heap_hh
17 #define INCLUDED_utility_heap_hh
18 
19 // Unit headers
20 #include <utility/heap.fwd.hh>
21 
22 // TEMP
23 
24 // ObjexxFCL Headers
25 #include <utility/vector0.hh>
26 
27 // Utility headers
29 
30 namespace utility {
31 
33 
34 public:
35 
36  /// @brief Create a heap with this number of items.
37  heap( int max_items ) {
38  // somewhere in porting this over, I made an off-by-one error in the rest of
39  // the heap machinery. So, decrement max_items by 1 to actually do the right
40  // thing. I recognize that this is a stupid thing to do, but at least it was
41  // quick!
42  heap_ .resize( max_items + 2 );
43  coheap_.resize( max_items + 2 );
44  // two extra values are for storing maximum and current number of items
45  heap_init( max_items );
46  }
47 
48  virtual ~heap() ; // auto-removing definition from header{}
49 
50  /// @brief Inserts a value into the heap that is sorted by coval.
51  void
52  heap_insert( int val, float coval, bool & err );
53 
54  /// @brief Extracts the val,coval pair with the lowest coval from the heap.
55  /// This modifies the heap, and the returned values are put into the arguments
56  /// val and coval.
57  void
58  heap_extract( int & val, float & coval, bool & err );
59 
60  void
61  heap_replace( int val, float coval );
62 
63  void
64  reset_coval( int val, float coval );
65 
66  /// @brief returns the smallest covalue stored in the heap.
67  float
68  heap_head() const;
69 
70  float
71  coval( int index ) const;
72 
73  int
74  val( int index ) const;
75 
76  int
77  size() const;
78 
79  int
80  capacity() const;
81 
82 private:
83  void
84  heap_init( int max_items );
85 
86  void
87  heap_down( int index_in );
88 
89  void
90  heap_up( int index_in );
91 
92  int & heap_size();
93  int & heap_capacity();
94 
95  void
96  decrease_coval( int index, float coval );
97 
98  void
99  increase_coval( int index, float coval );
100 
101  int index_for_val( int val );
102 
103 private:
106 
107 }; // class heap
108 
109 } // ns utility
110 
111 #endif
void heap_replace(int val, float coval)
Definition: heap.cc:142
virtual ~heap()
Definition: heap.cc:25
int & heap_capacity()
Definition: heap.cc:291
ReferenceCount base class – dispatch class.
vector0: std::vector with assert-checked bounds
void increase_coval(int index, float coval)
Definition: heap.cc:305
void heap_insert(int val, float coval, bool &err)
Inserts a value into the heap that is sorted by coval.
Definition: heap.cc:115
void heap_extract(int &val, float &coval, bool &err)
Extracts the val,coval pair with the lowest coval from the heap. This modifies the heap...
Definition: heap.cc:73
utility::vector0< float > coheap_
Definition: heap.hh:105
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
Definition: Fstring.hh:2180
float heap_head() const
returns the smallest covalue stored in the heap.
Definition: heap.cc:173
Base class for reference-counted polymorphic classes.
forward class definition of class heap
void heap_init(int max_items)
sets up an empty heap and stores the dimensioned size
Definition: heap.cc:59
void heap_down(int index_in)
Definition: heap.cc:206
int capacity() const
Definition: heap.cc:197
void decrease_coval(int index, float coval)
Definition: heap.cc:298
int val(int index) const
Definition: heap.cc:185
int & heap_size()
Definition: heap.cc:285
int index_for_val(int val)
Definition: heap.cc:312
void reset_coval(int val, float coval)
Definition: heap.cc:158
int size() const
Definition: heap.cc:191
utility::vector0< int > heap_
Definition: heap.hh:104
void heap_up(int index_in)
Definition: heap.cc:256
heap(int max_items)
Create a heap with this number of items.
Definition: heap.hh:37
float coval(int index) const
Definition: heap.cc:179