ca# orx-priority-queue Priority queue traits; binary and generalized d-ary heap implementations.

Traits

This crate defines two priority queue traits for (node, key) pairs with the following features:

separating more advanced PriorityQueueDecKey from the basic queue since additional functionalities are often made available through usage of additional memory.

Implementations

d-ary Heap

The core d-ary heap is implemented thanks to const generics. Three structs are created from this core struct:

Example

```rust use orxpriorityqueue::{PriorityQueue, PriorityQueueDecKey};

fn testpriorityqueue

(mut pq: P) where P: PriorityQueue, { println!("\ntestpriorityqueue"); pq.clear();

pq.push(0, 42.0);
assert_eq!(Some(&(0, 42.0)), pq.peek());

let popped = pq.pop();
assert_eq!(Some((0, 42.0)), popped);
assert!(pq.is_empty());

pq.push(0, 42.0);
pq.push(1, 7.0);
pq.push(2, 24.0);
pq.push(10, 3.0);

while let Some(popped) = pq.pop() {
    println!("pop {:?}", popped);
}

} fn testpriorityqueuedeckey

(mut pq: P) where P: PriorityQueueDecKey, { println!("\ntestpriorityqueuedeckey"); pq.clear();

pq.push(0, 42.0);
assert_eq!(Some(&(0, 42.0)), pq.peek());

let popped = pq.pop();
assert_eq!(Some((0, 42.0)), popped);
assert!(pq.is_empty());

pq.push(0, 42.0);
assert!(pq.contains(&0));

pq.decrease_key(&0, &7.0);
assert_eq!(Some(&(0, 7.0)), pq.peek());

let is_key_decreased = pq.try_decrease_key(&0, &10.0);
assert!(!is_key_decreased);
assert_eq!(Some(&(0, 7.0)), pq.peek());

while let Some(popped) = pq.pop() {
    println!("pop {:?}", popped);
}

}

fn main() { use orxpriorityqueue::*;

// d of the d-ary heap
const D: usize = 4;

test_priority_queue(DaryHeap::<usize, f64, D>::default());
test_priority_queue(DaryHeapWithMap::<usize, f64, D>::default());
test_priority_queue(DaryHeapOfIndices::<usize, f64, D>::with_upper_limit(100));

test_priority_queue_deckey(DaryHeapWithMap::<usize, f64, D>::default());
test_priority_queue_deckey(DaryHeapOfIndices::<usize, f64, D>::with_upper_limit(100));

} ```

License

This library is licensed under MIT license. See LICENSE for details.