Skip to content

Commit cc7b0fa

Browse files
committed
Implement RFC 839 for BinaryHeap
1 parent 9b69b10 commit cc7b0fa

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/libcollections/binary_heap.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,10 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
760760
}
761761
}
762762
}
763+
764+
#[unstable(feature = "extend_ref", reason = "recently added")]
765+
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
766+
fn extend<I: IntoIterator<Item=&'a T>>(&mut self, iter: I) {
767+
self.extend(iter.into_iter().cloned());
768+
}
769+
}

src/libcollectionstest/binary_heap.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,28 @@ fn test_drain() {
217217

218218
assert!(q.is_empty());
219219
}
220+
221+
#[test]
222+
fn test_extend_ref() {
223+
let mut a = BinaryHeap::new();
224+
a.push(1);
225+
a.push(2);
226+
227+
a.extend(&[3, 4, 5]);
228+
229+
assert_eq!(a.len(), 5);
230+
assert_eq!(a.into_sorted_vec(), [1, 2, 3, 4, 5]);
231+
232+
let mut a = BinaryHeap::new();
233+
a.push(1);
234+
a.push(2);
235+
let mut b = BinaryHeap::new();
236+
b.push(3);
237+
b.push(4);
238+
b.push(5);
239+
240+
a.extend(&b);
241+
242+
assert_eq!(a.len(), 5);
243+
assert_eq!(a.into_sorted_vec(), [1, 2, 3, 4, 5]);
244+
}

0 commit comments

Comments
 (0)