pub fn new(max_id: usize) -> IndexdMinHeap<T> {
IndexdMinHeap {
positions: vec![INVALID_POSITION; max_id],
pub fn new(max_id: usize) -> IndexdMinHeap<T> {
IndexdMinHeap {
positions: vec![INVALID_POSITION; max_id],
pub fn contains_index(&self, id: usize) -> bool {
self.positions[id] != INVALID_POSITION
}
pub fn contains_index(&self, id: usize) -> bool {
self.positions[id] != INVALID_POSITION
}
pub fn clear(&mut self) {
for element in &self.data {
self.positions[element.as_index()] = INVALID_POSITION;
pub fn clear(&mut self) {
for element in &self.data {
self.positions[element.as_index()] = INVALID_POSITION;
pub fn pop(&mut self) -> Option<T> {
self.data.pop().map(|mut item| {
self.positions[item.as_index()] = INVALID_POSITION;
pub fn pop(&mut self) -> Option<T> {
self.data.pop().map(|mut item| {
self.positions[item.as_index()] = INVALID_POSITION;
pub fn push(&mut self, element: T) {
assert!(!self.contains_index(element.as_index()));
let insert_position = self.len();
pub fn push(&mut self, element: T) {
assert!(!self.contains_index(element.as_index()));
let insert_position = self.len();
// Updates the key of an element if the new key is smaller than the old key.
// Does nothing if the new key is larger.
// Undefined if the element is not part of the queue.
// Updates the key of an element if the new key is smaller than the old key.
// Does nothing if the new key is larger.
// Undefined if the element is not part of the queue.
pub fn decrease_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
self.data[position] = element;
pub fn decrease_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
self.data[position] = element;
// Updates the key of an element if the new key is larger than the old key.
// Does nothing if the new key is smaller.
// Undefined if the element is not part of the queue.
// Updates the key of an element if the new key is larger than the old key.
// Does nothing if the new key is smaller.
// Undefined if the element is not part of the queue.
pub fn increase_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
self.data[position] = element;
pub fn increase_key(&mut self, element: T) {
let position = self.positions[element.as_index()];
self.data[position] = element;