Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Garrisi committed Aug 9, 2024
1 parent 83a5dab commit ccdd365
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 48 deletions.
18 changes: 6 additions & 12 deletions src/core_iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ pub(crate) mod std {
/// `(item, priority)` in the queue.
///
/// It can be obtained calling the `drain` method.
pub struct Drain<'a, I: 'a, P: 'a>
{
pub struct Drain<'a, I: 'a, P: 'a> {
pub(crate) iter: ::indexmap::map::Drain<'a, I, P>,
}

impl<'a, I: 'a, P: 'a> Iterator for Drain<'a, I, P>
{
impl<'a, I: 'a, P: 'a> Iterator for Drain<'a, I, P> {
type Item = (I, P);
fn next(&mut self) -> Option<(I, P)> {
self.iter.next()
Expand All @@ -73,13 +71,11 @@ impl<I, P> FusedIterator for Drain<'_, I, P> {}
/// `(item, priority)` in the queue.
///
/// It can be obtained calling the `iter` method.
pub struct Iter<'a, I: 'a, P: 'a>
{
pub struct Iter<'a, I: 'a, P: 'a> {
pub(crate) iter: ::indexmap::map::Iter<'a, I, P>,
}

impl<'a, I: 'a, P: 'a> Iterator for Iter<'a, I, P>
{
impl<'a, I: 'a, P: 'a> Iterator for Iter<'a, I, P> {
type Item = (&'a I, &'a P);
fn next(&mut self) -> Option<(&'a I, &'a P)> {
self.iter.next()
Expand All @@ -104,13 +100,11 @@ impl<I, P> FusedIterator for Iter<'_, I, P> {}
/// `(item, priority)` that consumes the queue.
///
/// It can be obtained calling the `into_iter` method from the `IntoIterator` trait.
pub struct IntoIter<I, P>
{
pub struct IntoIter<I, P> {
pub(crate) iter: ::indexmap::map::IntoIter<I, P>,
}

impl<I, P> Iterator for IntoIter<I, P>
{
impl<I, P> Iterator for IntoIter<I, P> {
type Item = (I, P);
fn next(&mut self) -> Option<(I, P)> {
self.iter.next()
Expand Down
9 changes: 3 additions & 6 deletions src/double_priority_queue/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ impl<'a, I, P, H> FusedIterator for IterMut<'_, I, P, H>
where
P: Ord,
H: BuildHasher,
{}
{
}

impl<'a, I: 'a, P: 'a, H: 'a> Drop for IterMut<'a, I, P, H>
where
Expand Down Expand Up @@ -197,8 +198,4 @@ where
}
}

impl<I, P, H> FusedIterator for IntoSortedIter<I, P, H>
where
P: Ord,
{}

impl<I, P, H> FusedIterator for IntoSortedIter<I, P, H> where P: Ord {}
11 changes: 2 additions & 9 deletions src/double_priority_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ use std::mem::replace;
/// ```
#[derive(Clone)]
#[cfg(feature = "std")]
pub struct DoublePriorityQueue<I, P, H = RandomState>
{
pub struct DoublePriorityQueue<I, P, H = RandomState> {
pub(crate) store: Store<I, P, H>,
}

#[derive(Clone)]
#[cfg(not(feature = "std"))]
pub struct DoublePriorityQueue<I, P, H>
{
pub struct DoublePriorityQueue<I, P, H> {
pub(crate) store: Store<I, P, H>,
}

Expand Down Expand Up @@ -247,7 +245,6 @@ impl<I, P, H> DoublePriorityQueue<I, P, H>
where
P: Ord,
{

/// Return an iterator in arbitrary order over the
/// (item, priority) elements in the queue.
///
Expand All @@ -262,7 +259,6 @@ where
IterMut::new(self)
}


/// Returns the couple (item, priority) with the greatest
/// priority in the queue, or None if it is empty.
///
Expand Down Expand Up @@ -364,7 +360,6 @@ where
P: Ord,
H: BuildHasher,
{

/// Returns the couple (item, priority) with the greatest
/// priority in the queue, or None if it is empty.
///
Expand All @@ -388,14 +383,12 @@ where
}
}


impl<I, P, H> DoublePriorityQueue<I, P, H>
where
P: Ord,
I: Hash + Eq,
H: BuildHasher,
{

/// Insert the item-priority pair into the queue.
///
/// If an element equal to `item` was already into the queue,
Expand Down
6 changes: 2 additions & 4 deletions src/priority_queue/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,12 @@ where
///
/// It can be obtained calling the `into_sorted_iter` method.
#[cfg(feature = "std")]
pub struct IntoSortedIter<I, P, H = RandomState>
{
pub struct IntoSortedIter<I, P, H = RandomState> {
pub(crate) pq: PriorityQueue<I, P, H>,
}

#[cfg(not(feature = "std"))]
pub struct IntoSortedIter<I, P, H>
{
pub struct IntoSortedIter<I, P, H> {
pub(crate) pq: PriorityQueue<I, P, H>,
}

Expand Down
7 changes: 2 additions & 5 deletions src/priority_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ use std::mem::replace;
/// ```
#[derive(Clone, Debug)]
#[cfg(feature = "std")]
pub struct PriorityQueue<I, P, H = RandomState>
{
pub struct PriorityQueue<I, P, H = RandomState> {
pub(crate) store: Store<I, P, H>,
}

#[derive(Clone, Debug)]
#[cfg(not(feature = "std"))]
pub struct PriorityQueue<I, P, H>
{
pub struct PriorityQueue<I, P, H> {
pub(crate) store: Store<I, P, H>,
}

Expand Down Expand Up @@ -168,7 +166,6 @@ where
}
}


impl<I, P, H> PriorityQueue<I, P, H> {
/// Returns an iterator in arbitrary order over the
/// (item, priority) elements in the queue
Expand Down
19 changes: 8 additions & 11 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub(crate) struct Position(pub usize);
/// Internal storage of PriorityQueue and DoublePriorityQueue
#[derive(Clone)]
#[cfg(feature = "std")]
pub(crate) struct Store<I, P, H = RandomState>
{
pub(crate) struct Store<I, P, H = RandomState> {
pub map: IndexMap<I, P, H>, // Stores the items and assign them an index
pub heap: Vec<Index>, // Implements the heap of indexes
pub qp: Vec<Position>, // Performs the translation from the index
Expand All @@ -63,8 +62,7 @@ pub(crate) struct Store<I, P, H = RandomState>

#[derive(Clone)]
#[cfg(not(feature = "std"))]
pub(crate) struct Store<I, P, H>
{
pub(crate) struct Store<I, P, H> {
pub map: IndexMap<I, P, H>, // Stores the items and assign them an index
pub heap: Vec<Index>, // Implements the heap of indexes
pub qp: Vec<Position>, // Performs the translation from the index
Expand Down Expand Up @@ -176,7 +174,9 @@ impl<I, P, H> Store<I, P, H> {
self.qp.clear();
self.size = 0;

Drain{iter: self.map.drain(..)}
Drain {
iter: self.map.drain(..),
}
}

/// Returns the number of elements the internal map can hold without
Expand Down Expand Up @@ -419,8 +419,7 @@ where
}
}

impl<I, P, H> IntoIterator for Store<I, P, H>
{
impl<I, P, H> IntoIterator for Store<I, P, H> {
type Item = (I, P);
type IntoIter = IntoIter<I, P>;
fn into_iter(self) -> IntoIter<I, P> {
Expand All @@ -430,8 +429,7 @@ impl<I, P, H> IntoIterator for Store<I, P, H>
}
}

impl<'a, I, P, H> IntoIterator for &'a Store<I, P, H>
{
impl<'a, I, P, H> IntoIterator for &'a Store<I, P, H> {
type Item = (&'a I, &'a P);
type IntoIter = Iter<'a, I, P>;
fn into_iter(self) -> Iter<'a, I, P> {
Expand Down Expand Up @@ -565,8 +563,7 @@ mod serde {

use serde::ser::{Serialize, SerializeSeq, Serializer};

impl<I, P, H> Serialize for Store<I, P, H>
{
impl<I, P, H> Serialize for Store<I, P, H> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down
1 change: 0 additions & 1 deletion tests/double_priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ mod doublepq_tests {
assert_eq!(queue.pop_max(), None);
}


#[test]
fn extend() {
let mut pq = DoublePriorityQueue::new();
Expand Down

0 comments on commit ccdd365

Please sign in to comment.