Tolerance<unsigned int> and Tolerance<unsigned long long int> added.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 ///\brief Classes for representing heaps.
24 #ifndef LEMON_CONCEPT_HEAP_H
25 #define LEMON_CONCEPT_HEAP_H
27 #include <lemon/bits/invalid.h>
31 /// \addtogroup concept
35 /// \brief A concept structure describes the main interface of heaps.
37 /// A concept structure describes the main interface of heaps.
39 template <typename Item, typename Prio, typename ItemIntMap>
44 /// \brief Type to represent the items states.
46 /// Each Item element have a state associated to it. It may be "in heap",
47 /// "pre heap" or "post heap". The later two are indifferent from the
48 /// heap's point of view, but may be useful to the user.
50 /// The ItemIntMap _should_ be initialized in such way, that it maps
51 /// PRE_HEAP (-1) to any element to be put in the heap...
58 /// \brief The constructor.
61 /// \param _iim should be given to the constructor, since it is used
62 /// internally to handle the cross references. The value of the map
63 /// should be PRE_HEAP (-1) for each element.
64 explicit Heap(ItemIntMap &_iim) {}
66 /// \brief The number of items stored in the heap.
68 /// Returns the number of items stored in the heap.
69 int size() const { return 0; }
71 /// \brief Checks if the heap stores no items.
73 /// Returns \c true if and only if the heap stores no items.
74 bool empty() const { return false; }
76 /// \brief Makes empty this heap.
78 /// Makes this heap empty.
81 /// \brief Insert an item into the heap with the given heap.
83 /// Adds \c i to the heap with priority \c p.
84 /// \param i The item to insert.
85 /// \param p The priority of the item.
86 void push(const Item &i, const Prio &p) {}
88 /// \brief Returns the item with minimum priority.
90 /// This method returns the item with minimum priority.
91 /// \pre The heap must be nonempty.
94 /// \brief Returns the minimum priority.
96 /// It returns the minimum priority.
97 /// \pre The heap must be nonempty.
100 /// \brief Deletes the item with minimum priority.
102 /// This method deletes the item with minimum priority.
103 /// \pre The heap must be non-empty.
106 /// \brief Deletes \c i from the heap.
108 /// This method deletes item \c i from the heap, if \c i was
109 /// already stored in the heap.
110 /// \param i The item to erase.
111 void erase(const Item &i) {}
113 /// \brief Returns the priority of \c i.
115 /// This function returns the priority of item \c i.
116 /// \pre \c i must be in the heap.
117 /// \param i The item.
118 Prio operator[](const Item &i) const {}
120 /// \brief \c i gets to the heap with priority \c p independently
121 /// if \c i was already there.
123 /// This method calls \ref push(\c i, \c p) if \c i is not stored
124 /// in the heap and sets the priority of \c i to \c p otherwise.
125 /// It may throw an \e UnderFlowPriorityException.
126 /// \param i The item.
127 /// \param p The priority.
128 void set(const Item &i, const Prio &p) {}
130 /// \brief Decreases the priority of \c i to \c p.
132 /// This method decreases the priority of item \c i to \c p.
133 /// \pre \c i must be stored in the heap with priority at least \c p.
134 /// \param i The item.
135 /// \param p The priority.
136 void decrease(const Item &i, const Prio &p) {}
138 /// \brief Increases the priority of \c i to \c p.
140 /// This method sets the priority of item \c i to \c p.
141 /// \pre \c i must be stored in the heap with priority at most \c
142 /// p relative to \c Compare.
143 /// \param i The item.
144 /// \param p The priority.
145 void increase(const Item &i, const Prio &p) {}
147 /// \brief Returns if \c item is in, has already been in, or has
148 /// never been in the heap.
150 /// This method returns PRE_HEAP if \c item has never been in the
151 /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
152 /// otherwise. In the latter case it is possible that \c item will
153 /// get back to the heap again.
154 /// \param i The item.
155 state_enum state(const Item &i) const {}
157 /// \brief Sets the state of the \c item in the heap.
159 /// Sets the state of the \c item in the heap. It can be used to
160 /// manually clear the heap when it is important to achive the
161 /// better time complexity.
162 /// \param i The item.
163 /// \param st The state. It should not be \c IN_HEAP.
164 void state(const Item& i, state_enum st) {}
167 template <typename _Heap>
178 ignore_unused_variable_warning(item);
179 ignore_unused_variable_warning(prio);
181 typedef typename _Heap::state_enum state_enum;
184 ignore_unused_variable_warning(state);
186 _Heap heap1 = _Heap(map);
188 ignore_unused_variable_warning(heap1);
190 heap.push(item, prio);
197 heap.set(item, prio);
198 heap.decrease(item, prio);
199 heap.increase(item, prio);
204 state = heap.state(item);
206 state = _Heap::PRE_HEAP;
207 state = _Heap::IN_HEAP;
208 state = _Heap::POST_HEAP;
216 Constraints() : heap(0), map(0) {}
223 #endif // LEMON_CONCEPT_PATH_H