1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Lazy deduplication for iterators.
//!
//! This module provides [`Dedup`], an iterator adapter that filters out duplicate elements while
//! preserving the order of first occurrences. Unlike collecting into a set and iterating, this
//! approach is lazy — duplicates are filtered on-the-fly as items are consumed.
//!
//! The [`Deduped`] extension trait adds the [`dedup`](Deduped::dedup) method to any iterator whose
//! items implement `Hash + Eq + Clone`.
//!
//! # Example
//!
//! ```rust,no_run
//! # use zhc_utils::iter::Deduped;
//! let items = vec![1, 2, 3, 2, 1, 4, 3, 5];
//! let unique: Vec<_> = items.into_iter().dedup().collect();
//! assert_eq!(unique, vec![1, 2, 3, 4, 5]);
//! ```
use Hash;
use crateSmallSet;
/// An iterator adapter that yields each unique element only once, in encounter order.
///
/// `Dedup` wraps an underlying iterator and maintains a set of previously seen items. When the
/// underlying iterator produces a value, `Dedup` checks whether it has been seen before: if so,
/// the value is skipped; if not, it is recorded and yielded.
///
/// This adapter is lazy — it processes elements one at a time as they are requested, making it
/// suitable for large or infinite iterators where collecting all elements upfront would be
/// impractical.
///
/// `Dedup` is typically created by calling [`dedup`](Deduped::dedup) on an iterator, rather than
/// constructing it directly.
/// An extension trait that provides lazy deduplication for iterators.
///
/// `Deduped` is automatically implemented for any iterator whose items implement `Hash + Eq +
/// Clone`. Importing this trait brings the [`dedup`](Deduped::dedup) method into scope, enabling
/// fluent chaining with other iterator adapters.