diff options
| author | pravic <[email protected]> | 2016-06-06 23:05:39 +0300 |
|---|---|---|
| committer | pravic <[email protected]> | 2016-06-06 23:05:39 +0300 |
| commit | ddc401e0bf4f972bc2916601797d12bb97c5f1dc (patch) | |
| tree | 8aa799e4fdf089c5060f3ea8b567943681603b85 /libcollections/btree/set.rs | |
| parent | update libcore to 2016-04-29 nightly (diff) | |
| download | kmd-env-rs-ddc401e0bf4f972bc2916601797d12bb97c5f1dc.tar.xz kmd-env-rs-ddc401e0bf4f972bc2916601797d12bb97c5f1dc.zip | |
update to 2016-06-06
Diffstat (limited to 'libcollections/btree/set.rs')
| -rw-r--r-- | libcollections/btree/set.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/libcollections/btree/set.rs b/libcollections/btree/set.rs index 5419d7a..765595b 100644 --- a/libcollections/btree/set.rs +++ b/libcollections/btree/set.rs @@ -477,9 +477,9 @@ impl<T: Ord> BTreeSet<T> { /// Adds a value to the set. /// - /// If the set did not have a value present, `true` is returned. + /// If the set did not have this value present, `true` is returned. /// - /// If the set did have this key present, `false` is returned, and the + /// If the set did have this value present, `false` is returned, and the /// entry is not updated. See the [module-level documentation] for more. /// /// [module-level documentation]: index.html#insert-and-complex-keys @@ -580,6 +580,43 @@ impl<T: Ord> BTreeSet<T> { pub fn append(&mut self, other: &mut Self) { self.map.append(&mut other.map); } + + /// Splits the collection into two at the given key. Returns everything after the given key, + /// including the key. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(btree_split_off)] + /// use std::collections::BTreeMap; + /// + /// let mut a = BTreeMap::new(); + /// a.insert(1, "a"); + /// a.insert(2, "b"); + /// a.insert(3, "c"); + /// a.insert(17, "d"); + /// a.insert(41, "e"); + /// + /// let b = a.split_off(&3); + /// + /// assert_eq!(a.len(), 2); + /// assert_eq!(b.len(), 3); + /// + /// assert_eq!(a[&1], "a"); + /// assert_eq!(a[&2], "b"); + /// + /// assert_eq!(b[&3], "c"); + /// assert_eq!(b[&17], "d"); + /// assert_eq!(b[&41], "e"); + /// ``` + #[unstable(feature = "btree_split_off", + reason = "recently added as part of collections reform 2", + issue = "19986")] + pub fn split_off<Q: ?Sized + Ord>(&mut self, key: &Q) -> Self where T: Borrow<Q> { + BTreeSet { map: self.map.split_off(key) } + } } #[stable(feature = "rust1", since = "1.0.0")] |