diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml index 2733e20..ba76936 100644 --- a/.github/workflows/static-checks.yml +++ b/.github/workflows/static-checks.yml @@ -34,3 +34,11 @@ jobs: with: components: miri - run: cargo miri test + + msrv-verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo install cargo-msrv + - run: cargo msrv verify --all-features diff --git a/Cargo.toml b/Cargo.toml index 42afaad..0d0a14a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,8 @@ readme = "README.md" keywords = ["priority", "queue", "heap"] categories = ["data-structures", "algorithms"] license = "LGPL-3.0-or-later OR MPL-2.0" -edition = "2024" +edition = "2021" +rust-version = "1.65.0" [build-dependencies] autocfg = "1" diff --git a/README.md b/README.md index 304cde3..c7f32bf 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [](https://crates.io/crates/priority-queue) [](https://github.com/garro95/priority-queue/actions/workflows/build.yml) [](https://github.com/garro95/priority-queue/actions/workflows/test.yml) + This crate implements a Priority Queue with a function to change the priority of an object. Priority and items are stored in an `IndexMap` and the queue is implemented as a Heap of indexes. diff --git a/benches/priority_queue.rs b/benches/priority_queue.rs index b79edfc..4a195ae 100644 --- a/benches/priority_queue.rs +++ b/benches/priority_queue.rs @@ -33,7 +33,7 @@ mod benchmarks { extern crate test; use hashbrown::hash_map::DefaultHashBuilder; use priority_queue::{DoublePriorityQueue, PriorityQueue}; - use test::{Bencher, black_box}; + use test::{black_box, Bencher}; #[bench] fn push_and_pop(b: &mut Bencher) { diff --git a/src/double_priority_queue/mod.rs b/src/double_priority_queue/mod.rs index d798fe8..8aa387d 100644 --- a/src/double_priority_queue/mod.rs +++ b/src/double_priority_queue/mod.rs @@ -34,9 +34,9 @@ pub mod iterators; #[cfg(not(feature = "std"))] use std::vec::Vec; -use crate::TryReserveError; use crate::core_iterators::*; use crate::store::{Index, Position, Store}; +use crate::TryReserveError; use iterators::*; use std::borrow::Borrow; @@ -612,7 +612,7 @@ where /// /// Computes in **O(log(N))** time. pub fn push_increase(&mut self, item: I, priority: P) -> Option
{ - if self.get_priority(&item).is_none_or(|p| priority > *p) { + if self.get_priority(&item).map_or(true, |p| priority > *p) { self.push(item, priority) } else { Some(priority) @@ -650,7 +650,7 @@ where /// /// Computes in **O(log(N))** time. pub fn push_decrease(&mut self, item: I, priority: P) -> Option
{ - if self.get_priority(&item).is_none_or(|p| priority < *p) { + if self.get_priority(&item).map_or(true, |p| priority < *p) { self.push(item, priority) } else { Some(priority) diff --git a/src/priority_queue/mod.rs b/src/priority_queue/mod.rs index a286f58..f9ab242 100644 --- a/src/priority_queue/mod.rs +++ b/src/priority_queue/mod.rs @@ -35,9 +35,9 @@ pub mod iterators; #[cfg(not(feature = "std"))] use std::vec::Vec; -use crate::TryReserveError; use crate::core_iterators::*; use crate::store::{Index, Position, Store}; +use crate::TryReserveError; use iterators::*; use std::borrow::Borrow; @@ -486,7 +486,7 @@ where /// /// Computes in **O(log(N))** time. pub fn push_increase(&mut self, item: I, priority: P) -> Option
{ - if self.get_priority(&item).is_none_or(|p| priority > *p) { + if self.get_priority(&item).map_or(true, |p| priority > *p) { self.push(item, priority) } else { Some(priority) @@ -524,7 +524,7 @@ where /// /// Computes in **O(log(N))** time. pub fn push_decrease(&mut self, item: I, priority: P) -> Option
{
- if self.get_priority(&item).is_none_or(|p| priority < *p) {
+ if self.get_priority(&item).map_or(true, |p| priority < *p) {
self.push(item, priority)
} else {
Some(priority)
diff --git a/src/store.rs b/src/store.rs
index 018bf86..2431b7c 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -30,8 +30,8 @@ use std::vec::Vec;
// an improvement in terms of complexity would be to use a bare HashMap
// as vec instead of the IndexMap
-use crate::TryReserveError;
use crate::core_iterators::*;
+use crate::TryReserveError;
use std::borrow::Borrow;
use std::cmp::{Eq, Ord};
@@ -332,8 +332,8 @@ where
self.map.retain2(predicate);
if self.map.len() != self.size {
self.size = self.map.len();
- self.heap = (0..self.size).into_iter().map(|i| Index(i)).collect();
- self.qp = (0..self.size).into_iter().map(|p| Position(p)).collect();
+ self.heap = (0..self.size).map(Index).collect();
+ self.qp = (0..self.size).map(Position).collect();
}
}
diff --git a/tests/double_priority_queue.rs b/tests/double_priority_queue.rs
index 0f7a168..6a608eb 100644
--- a/tests/double_priority_queue.rs
+++ b/tests/double_priority_queue.rs
@@ -1040,7 +1040,7 @@ mod doublepq_tests {
#[cfg(all(feature = "serde", test))]
mod serde_tests_basics {
use priority_queue::DoublePriorityQueue;
- use serde_test::{Token, assert_tokens};
+ use serde_test::{assert_tokens, Token};
#[test]
fn serde_empty() {
let pq: DoublePriorityQueue