projects
/
Mitarbeiter
/
Tim-Zeitz
/
stud-rust-base.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
0cce9e7
)
make heap api more robust
author
Tim "tim3z" Zeitz
<dev@tim3z.net>
Thu, 16 Dec 2021 09:46:28 +0000
(10:46 +0100)
committer
Tim "tim3z" Zeitz
<dev@tim3z.net>
Thu, 16 Dec 2021 09:46:28 +0000
(10:46 +0100)
src/index_heap.rs
patch
|
blob
|
history
diff --git
a/src/index_heap.rs
b/src/index_heap.rs
index 477dc879cf610d95dd8c2658bde1a3227a257cf1..5850ae802a3005775e593a86e1d6091931421d18 100644
(file)
--- a/
src/index_heap.rs
+++ b/
src/index_heap.rs
@@
-123,19
+123,19
@@
impl<T: Ord + Indexing> IndexdMinHeap<T> {
}
/// Updates the key of an element if the new key is smaller than the old key.
}
/// Updates the key of an element if the new key is smaller than the old key.
- /// Does nothing if the new key is larger.
- /// Panics if the element is not part of the queue.
+ /// Panics if the element is not part of the queue or if the new key is larger.
pub fn decrease_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
pub fn decrease_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
+ assert!(element <= self.data[position]);
self.data[position] = element;
self.move_up_in_tree(position);
}
/// Updates the key of an element if the new key is larger than the old key.
self.data[position] = element;
self.move_up_in_tree(position);
}
/// Updates the key of an element if the new key is larger than the old key.
- /// Does nothing if the new key is smaller.
- /// Panics if the element is not part of the queue.
+ /// Panics if the element is not part of the queue or if the new key is smaller.
pub fn increase_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
pub fn increase_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
+ assert!(element >= self.data[position]);
self.data[position] = element;
self.move_down_in_tree(position);
}
self.data[position] = element;
self.move_down_in_tree(position);
}