use crate::identity_set::{IdentitySet, Iter};
use allocator_api2::alloc::Allocator;
use core::iter::FusedIterator;
#[must_use]
#[derive(Clone)]
pub struct Difference<'a, T, A>
where
T: Ord,
A: Allocator,
{
this: Iter<'a, T>,
other: &'a IdentitySet<T, A>,
}
impl<'a, T, A> Difference<'a, T, A>
where
T: Ord,
A: Allocator,
{
#[inline(always)]
pub(crate) fn new(this: &'a IdentitySet<T, A>, other: &'a IdentitySet<T, A>) -> Self {
let this = this.iter();
Self { this, other }
}
}
impl<T, A> FusedIterator for Difference<'_, T, A>
where
T: Ord,
A: Allocator,
{ }
impl<'a, T, A> Iterator for Difference<'a, T, A>
where
T: Ord,
A: Allocator,
{
type Item = &'a T;
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
for key in self.this.by_ref() {
if !self.other.contains(key) { return Some(key) };
}
None
}
#[inline(always)]
fn size_hint(&self) -> (usize, Option<usize>) {
let min = 0x0;
let max = self.this.len();
(min, Some(max))
}
}