@@ -94,26 +94,92 @@ impl<T> BTreeSet<T> {
94
94
95
95
impl < T : Ord > BTreeSet < T > {
96
96
/// Visits the values representing the difference, in ascending order.
97
+ ///
98
+ /// # Example
99
+ ///
100
+ /// ```
101
+ /// use std::collections::BTreeSet;
102
+ ///
103
+ /// let mut a = BTreeSet::new();
104
+ /// a.insert(1u);
105
+ /// a.insert(2u);
106
+ ///
107
+ /// let mut b = BTreeSet::new();
108
+ /// b.insert(2u);
109
+ /// b.insert(3u);
110
+ ///
111
+ /// let diff: Vec<uint> = a.difference(&b).cloned().collect();
112
+ /// assert_eq!(diff, vec![1u]);
113
+ /// ```
97
114
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
98
115
pub fn difference < ' a > ( & ' a self , other : & ' a BTreeSet < T > ) -> DifferenceItems < ' a , T > {
99
116
DifferenceItems { a : self . iter ( ) . peekable ( ) , b : other. iter ( ) . peekable ( ) }
100
117
}
101
118
102
119
/// Visits the values representing the symmetric difference, in ascending order.
120
+ ///
121
+ /// # Example
122
+ ///
123
+ /// ```
124
+ /// use std::collections::BTreeSet;
125
+ ///
126
+ /// let mut a = BTreeSet::new();
127
+ /// a.insert(1u);
128
+ /// a.insert(2u);
129
+ ///
130
+ /// let mut b = BTreeSet::new();
131
+ /// b.insert(2u);
132
+ /// b.insert(3u);
133
+ ///
134
+ /// let sym_diff: Vec<uint> = a.symmetric_difference(&b).cloned().collect();
135
+ /// assert_eq!(sym_diff, vec![1u,3]);
136
+ /// ```
103
137
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
104
138
pub fn symmetric_difference < ' a > ( & ' a self , other : & ' a BTreeSet < T > )
105
139
-> SymDifferenceItems < ' a , T > {
106
140
SymDifferenceItems { a : self . iter ( ) . peekable ( ) , b : other. iter ( ) . peekable ( ) }
107
141
}
108
142
109
143
/// Visits the values representing the intersection, in ascending order.
144
+ ///
145
+ /// # Example
146
+ ///
147
+ /// ```
148
+ /// use std::collections::BTreeSet;
149
+ ///
150
+ /// let mut a = BTreeSet::new();
151
+ /// a.insert(1u);
152
+ /// a.insert(2u);
153
+ ///
154
+ /// let mut b = BTreeSet::new();
155
+ /// b.insert(2u);
156
+ /// b.insert(3u);
157
+ ///
158
+ /// let intersection: Vec<uint> = a.intersection(&b).cloned().collect();
159
+ /// assert_eq!(intersection, vec![2u]);
160
+ /// ```
110
161
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
111
162
pub fn intersection < ' a > ( & ' a self , other : & ' a BTreeSet < T > )
112
163
-> IntersectionItems < ' a , T > {
113
164
IntersectionItems { a : self . iter ( ) . peekable ( ) , b : other. iter ( ) . peekable ( ) }
114
165
}
115
166
116
167
/// Visits the values representing the union, in ascending order.
168
+ ///
169
+ /// # Example
170
+ ///
171
+ /// ```
172
+ /// use std::collections::BTreeSet;
173
+ ///
174
+ /// let mut a = BTreeSet::new();
175
+ /// a.insert(1u);
176
+ ///
177
+ /// let mut b = BTreeSet::new();
178
+ /// b.insert(2u);
179
+ ///
180
+ /// let union: Vec<uint> = a.union(&b).cloned().collect();
181
+ /// assert_eq!(union, vec![1u,2]);
182
+ /// ```
117
183
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
118
184
pub fn union < ' a > ( & ' a self , other : & ' a BTreeSet < T > ) -> UnionItems < ' a , T > {
119
185
UnionItems { a : self . iter ( ) . peekable ( ) , b : other. iter ( ) . peekable ( ) }
0 commit comments