Skip to content

Commit 467713b

Browse files
committed
Implement RFC 839 for BTreeMap
1 parent 554069c commit 467713b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/libcollections/btree/map.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,13 @@ impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
879879
}
880880
}
881881

882+
#[unstable(feature = "extend_ref", reason = "recently added")]
883+
impl<'a, K: Ord + Copy, V: Copy> Extend<(&'a K, &'a V)> for BTreeMap<K, V> {
884+
fn extend<I: IntoIterator<Item=(&'a K, &'a V)>>(&mut self, iter: I) {
885+
self.extend(iter.into_iter().map(|(&key, &value)| (key, value)));
886+
}
887+
}
888+
882889
#[stable(feature = "rust1", since = "1.0.0")]
883890
impl<K: Hash, V: Hash> Hash for BTreeMap<K, V> {
884891
fn hash<H: Hasher>(&self, state: &mut H) {

src/libcollectionstest/btree/map.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ fn test_entry(){
249249
assert_eq!(map.len(), 6);
250250
}
251251

252+
#[test]
253+
fn test_extend_ref() {
254+
let mut a = BTreeMap::new();
255+
a.insert(1, "one");
256+
let mut b = BTreeMap::new();
257+
b.insert(2, "two");
258+
b.insert(3, "three");
259+
260+
a.extend(&b);
261+
262+
assert_eq!(a.len(), 3);
263+
assert_eq!(a[&1], "one");
264+
assert_eq!(a[&2], "two");
265+
assert_eq!(a[&3], "three");
266+
}
267+
252268
mod bench {
253269
use std::collections::BTreeMap;
254270
use std::__rand::{Rng, thread_rng};

0 commit comments

Comments
 (0)