Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,37 @@ jobs:
strategy:
matrix:
include:
- rust: stable
features:
- rust: stable
features: std
- rust: stable
features: serde
- rust: stable
features: std,serde
- rust: beta
features:
- rust: beta
features: std
- rust: beta
features: serde
- rust: beta
features: std,serde
- rust: nightly
features:

- rust: nightly
features: std
- rust: nightly
features: serde
- rust: nightly
features: std,serde
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Build
run: cargo build --verbose --features "${{ matrix.features }}"
run: cargo build --verbose --no-default-features --features "${{ matrix.features }}"

nostd_build:
runs-on: ubuntu-latest
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,38 @@ jobs:
strategy:
matrix:
include:
- rust: stable
features:
- rust: stable
features: std
- rust: stable
features: serde
- rust: stable
features: std,serde
- rust: beta
features:
- rust: beta
features: std
- rust: beta
features: serde
- rust: beta
features: std,serde
- rust: nightly
features:
- rust: nightly
features: std
- rust: nightly
features: serde
- rust: nightly
features: std,serde

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Run tests
run: cargo test --verbose --features "${{ matrix.features }}"
run: cargo test --verbose --no-default-features --features "${{ matrix.features }}"
- name: Run tests in release mode
run: cargo test --release --verbose --features "${{ matrix.features }}"
run: cargo test --release --verbose --no-default-features --features "${{ matrix.features }}"

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ rust-version = "1.65.0"
[dependencies]
equivalent = "1.0.1"
indexmap = {version = "2.2", features = [], default-features = false}
serde = { version = "1", optional = true }
serde = { version = "1", optional = true, features = ["alloc"], default-features = false }

[dev-dependencies]
serde_test = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
uuid = {version= "1", features = ["v4", "serde"] }
hashbrown = "0.14"
twox-hash = { version = "1.5", default-features = false }

[features]
default = ["std"]
std = ["indexmap/std"]
std = ["indexmap/std", "serde/std"]
benchmarks = []

[workspace]
Expand Down
18 changes: 16 additions & 2 deletions src/double_priority_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
///
Expand All @@ -486,6 +487,7 @@ where
///
/// assert_eq!(pq.peek_min(), Some((&"Bananas", &15)));
/// assert_eq!(pq.into_vec(), vec!["Bananas"]);
/// # }
/// ```
pub fn extract_if<F>(&mut self, predicate: F) -> ExtractIf<I, P, F, H>
where
Expand All @@ -512,6 +514,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
///
Expand All @@ -524,6 +527,7 @@ where
/// }), None);
///
/// assert_eq!(pq.pop_min(), Some(("Bananas", 10)));
/// # }
/// ```
pub fn pop_min_if<F>(&mut self, f: F) -> Option<(I, P)>
where
Expand Down Expand Up @@ -554,6 +558,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
/// pq.push("Apples", 5);
Expand All @@ -563,6 +568,7 @@ where
/// false
/// }), None);
/// assert_eq!(pq.pop_max(), Some(("Apples", 5)));
/// # }
/// ```
pub fn pop_max_if<F>(&mut self, f: F) -> Option<(I, P)>
where
Expand All @@ -583,6 +589,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
/// assert_eq!(pq.push("Apples", 5), None);
Expand All @@ -591,6 +598,7 @@ where
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// assert_eq!(pq.push("Apples", 4), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand Down Expand Up @@ -641,6 +649,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
/// assert_eq!(pq.push_increase("Apples", 5), None);
Expand All @@ -651,6 +660,7 @@ where
/// // priority is returned.
/// assert_eq!(pq.push_increase("Apples", 4), Some(4));
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand Down Expand Up @@ -679,6 +689,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
/// assert_eq!(pq.push_decrease("Apples", 5), None);
Expand All @@ -689,6 +700,7 @@ where
/// // priority is returned.
/// assert_eq!(pq.push_decrease("Apples", 6), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand All @@ -708,6 +720,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::DoublePriorityQueue;
/// let mut pq = DoublePriorityQueue::new();
/// assert_eq!(pq.change_priority("Apples", 5), None);
Expand All @@ -716,6 +729,7 @@ where
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// assert_eq!(pq.change_priority("Apples", 4), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// The item is found in **O(1)** thanks to the hash table.
Expand Down Expand Up @@ -1218,8 +1232,8 @@ where
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
mod serde {
use std::cmp::{Eq, Ord};
use std::hash::{BuildHasher, Hash};
use core::cmp::{Eq, Ord};
use core::hash::{BuildHasher, Hash};

use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
//!
//! # Examples
//! ```rust
//! # #[cfg(feature = "std")] {
//! use priority_queue::PriorityQueue;
//!
//! let mut pq = PriorityQueue::new();
Expand All @@ -71,10 +72,12 @@
//! for (item, _) in pq.into_sorted_iter() {
//! println!("{}", item); // Will print Bananas, Strawberries, Apples
//! }
//! # }
//! ```
//!
//! ## Reverse ordering
//! ```rust
//! # #[cfg(feature = "std")] {
//! use priority_queue::PriorityQueue;
//! use std::cmp::Reverse;
//!
Expand All @@ -90,6 +93,7 @@
//! for (item, _) in pq.into_sorted_iter() {
//! println!("{}", item); // Will print Apples, Bananas, Strawberries
//! }
//! # }
//! ```
//!
//! # Crate features
Expand Down
18 changes: 16 additions & 2 deletions src/priority_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use std::mem::replace;
///
/// # Example
/// ```rust
/// # #[cfg(feature = "std")] {
/// use priority_queue::PriorityQueue;
///
/// let mut pq = PriorityQueue::new();
Expand All @@ -79,6 +80,7 @@ use std::mem::replace;
/// for (item, _) in pq.into_sorted_iter() {
/// println!("{}", item);
/// }
/// # }
/// ```
#[derive(Clone, Debug)]
#[cfg(feature = "std")]
Expand Down Expand Up @@ -383,6 +385,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
///
Expand All @@ -396,6 +399,7 @@ where
///
/// assert_eq!(pq.peek(), Some((&"Bananas", &15)));
/// assert_eq!(pq.into_vec(), vec!["Bananas"]);
/// # }
/// ```
pub fn extract_if<F>(&mut self, predicate: F) -> ExtractIf<I, P, F, H>
where
Expand All @@ -422,6 +426,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
///
Expand All @@ -434,6 +439,7 @@ where
/// }), None);
///
/// assert_eq!(pq.pop(), Some(("Apples", 5)));
/// # }
/// ```
pub fn pop_if<F>(&mut self, predicate: F) -> Option<(I, P)>
where
Expand All @@ -458,6 +464,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
/// assert_eq!(pq.push("Apples", 5), None);
Expand All @@ -466,6 +473,7 @@ where
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// assert_eq!(pq.push("Apples", 4), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand Down Expand Up @@ -515,6 +523,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
/// assert_eq!(pq.push_increase("Apples", 5), None);
Expand All @@ -525,6 +534,7 @@ where
/// // priority is returned.
/// assert_eq!(pq.push_increase("Apples", 4), Some(4));
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand Down Expand Up @@ -553,6 +563,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
/// assert_eq!(pq.push_decrease("Apples", 5), None);
Expand All @@ -563,6 +574,7 @@ where
/// // priority is returned.
/// assert_eq!(pq.push_decrease("Apples", 6), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// Computes in **O(log(N))** time.
Expand All @@ -582,6 +594,7 @@ where
///
/// # Example
/// ```
/// # #[cfg(feature = "std")] {
/// # use priority_queue::PriorityQueue;
/// let mut pq = PriorityQueue::new();
/// assert_eq!(pq.change_priority("Apples", 5), None);
Expand All @@ -590,6 +603,7 @@ where
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
/// assert_eq!(pq.change_priority("Apples", 4), Some(6));
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
/// # }
/// ```
///
/// The item is found in **O(1)** thanks to the hash table.
Expand Down Expand Up @@ -970,8 +984,8 @@ where
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
mod serde {
use std::cmp::{Eq, Ord};
use std::hash::{BuildHasher, Hash};
use core::cmp::{Eq, Ord};
use core::hash::{BuildHasher, Hash};

use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
Expand Down
Loading
Loading