pub struct ReusableDeduplicator<T> { /* private fields */ }
Expand description
A helper for deduplicating items in an iterator while amortizing the storage cost of deduplication.
When deduplicating items in an iterator, a set of which items have been seen must be kept. This involves underlying storage that grows as more items are seen for the first time. When many iterators are being deduplicated, this storage cost can add up in terms of the number of underlying allocations, and resizing operations of the set.
ReusableDeduplicator
allows for reuse of the underlying set between iterations.
§Safety
In order to support reusing the underlying storage between iterations, without having to clone the items, we directly hash items and track the presence of their hash value. This is a subtle distinction compared to using the items themselves, as it means that we lose the typical fallback of comparing items for equality if there is a hash collision detected. Consistent with other code in this repository that deals with things like metric tags, we use a high-quality hash function and make a calculated bet that collisions are extremely unlikely.
Implementations§
Source§impl<T: Eq + Hash> ReusableDeduplicator<T>
impl<T: Eq + Hash> ReusableDeduplicator<T>
Sourcepub fn deduplicated<'item, I>(
&mut self,
iter: I,
) -> Deduplicated<'_, 'item, I, T> ⓘ
pub fn deduplicated<'item, I>( &mut self, iter: I, ) -> Deduplicated<'_, 'item, I, T> ⓘ
Creates a wrapper iterator over the given iterator that deduplicates the items.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ReusableDeduplicator<T>
impl<T> RefUnwindSafe for ReusableDeduplicator<T>where
T: RefUnwindSafe,
impl<T> Send for ReusableDeduplicator<T>where
T: Send,
impl<T> Sync for ReusableDeduplicator<T>where
T: Sync,
impl<T> Unpin for ReusableDeduplicator<T>where
T: Unpin,
impl<T> UnwindSafe for ReusableDeduplicator<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more