[Lemon-commits] [lemon_svn] deba: r2477 - in hugo/trunk/lemon: . concept
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:52:58 CET 2006
Author: deba
Date: Wed Jan 25 13:10:18 2006
New Revision: 2477
Modified:
hugo/trunk/lemon/bin_heap.h
hugo/trunk/lemon/concept/heap.h
hugo/trunk/lemon/fib_heap.h
hugo/trunk/lemon/linear_heap.h
hugo/trunk/lemon/radix_heap.h
Log:
state setting function for heaps
If we know that which elements were in the heap then
we can clear it in better time complexity.
Modified: hugo/trunk/lemon/bin_heap.h
==============================================================================
--- hugo/trunk/lemon/bin_heap.h (original)
+++ hugo/trunk/lemon/bin_heap.h Wed Jan 25 13:10:18 2006
@@ -267,6 +267,25 @@
return state_enum(s);
}
+ /// \brief Sets the state of the \c item in the heap.
+ ///
+ /// Sets the state of the \c item in the heap. It can be used to
+ /// manually clear the heap when it is important to achive the
+ /// better time complexity.
+ /// \param i The item.
+ /// \param st The state. It should not be \c IN_HEAP.
+ void state(const Item& i, state_enum st) {
+ switch (st) {
+ case POST_HEAP:
+ case PRE_HEAP:
+ if (state(i) == IN_HEAP) {
+ erase(i);
+ }
+ index[i] = st;
+ break;
+ }
+ }
+
}; // class BinHeap
Modified: hugo/trunk/lemon/concept/heap.h
==============================================================================
--- hugo/trunk/lemon/concept/heap.h (original)
+++ hugo/trunk/lemon/concept/heap.h Wed Jan 25 13:10:18 2006
@@ -152,6 +152,15 @@
/// \param i The item.
state_enum state(const Item &i) const {}
+ /// \brief Sets the state of the \c item in the heap.
+ ///
+ /// Sets the state of the \c item in the heap. It can be used to
+ /// manually clear the heap when it is important to achive the
+ /// better time complexity.
+ /// \param i The item.
+ /// \param st The state. It should not be \c IN_HEAP.
+ void state(const Item& i, state_enum st) {}
+
template <typename _Heap>
struct Constraints {
Modified: hugo/trunk/lemon/fib_heap.h
==============================================================================
--- hugo/trunk/lemon/fib_heap.h (original)
+++ hugo/trunk/lemon/fib_heap.h Wed Jan 25 13:10:18 2006
@@ -216,6 +216,25 @@
}
return state_enum(i);
}
+
+ /// \brief Sets the state of the \c item in the heap.
+ ///
+ /// Sets the state of the \c item in the heap. It can be used to
+ /// manually clear the heap when it is important to achive the
+ /// better time complexity.
+ /// \param i The item.
+ /// \param st The state. It should not be \c IN_HEAP.
+ void state(const Item& i, state_enum st) {
+ switch (st) {
+ case POST_HEAP:
+ case PRE_HEAP:
+ if (state(i) == IN_HEAP) {
+ erase(i);
+ }
+ index[i] = st;
+ break;
+ }
+ }
private:
Modified: hugo/trunk/lemon/linear_heap.h
==============================================================================
--- hugo/trunk/lemon/linear_heap.h (original)
+++ hugo/trunk/lemon/linear_heap.h Wed Jan 25 13:10:18 2006
@@ -283,6 +283,25 @@
return state_enum(idx);
}
+ /// \brief Sets the state of the \c item in the heap.
+ ///
+ /// Sets the state of the \c item in the heap. It can be used to
+ /// manually clear the heap when it is important to achive the
+ /// better time complexity.
+ /// \param i The item.
+ /// \param st The state. It should not be \c IN_HEAP.
+ void state(const Item& i, state_enum st) {
+ switch (st) {
+ case POST_HEAP:
+ case PRE_HEAP:
+ if (state(i) == IN_HEAP) {
+ erase(i);
+ }
+ index[i] = st;
+ break;
+ }
+ }
+
private:
struct LinearItem {
@@ -459,6 +478,18 @@
return state_enum(idx);
}
+ void state(const Item& i, state_enum st) {
+ switch (st) {
+ case POST_HEAP:
+ case PRE_HEAP:
+ if (state(i) == IN_HEAP) {
+ erase(i);
+ }
+ index[i] = st;
+ break;
+ }
+ }
+
private:
struct LinearItem {
Modified: hugo/trunk/lemon/radix_heap.h
==============================================================================
--- hugo/trunk/lemon/radix_heap.h (original)
+++ hugo/trunk/lemon/radix_heap.h Wed Jan 25 13:10:18 2006
@@ -406,6 +406,25 @@
return state_enum(s);
}
+ /// \brief Sets the state of the \c item in the heap.
+ ///
+ /// Sets the state of the \c item in the heap. It can be used to
+ /// manually clear the heap when it is important to achive the
+ /// better time complexity.
+ /// \param i The item.
+ /// \param st The state. It should not be \c IN_HEAP.
+ void state(const Item& i, state_enum st) {
+ switch (st) {
+ case POST_HEAP:
+ case PRE_HEAP:
+ if (state(i) == IN_HEAP) {
+ erase(i);
+ }
+ index[i] = st;
+ break;
+ }
+ }
+
}; // class RadixHeap
} // namespace lemon
More information about the Lemon-commits
mailing list