diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 2427422f743..64e10e69a2e 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -161,6 +161,7 @@ use vec::{mod, Vec}; /// /// This will be a max-heap. #[deriving(Clone)] +#[stable] pub struct BinaryHeap { data: Vec, } @@ -168,7 +169,6 @@ pub struct BinaryHeap { #[stable] impl Default for BinaryHeap { #[inline] - #[stable] fn default() -> BinaryHeap { BinaryHeap::new() } } @@ -182,7 +182,7 @@ impl BinaryHeap { /// let mut heap = BinaryHeap::new(); /// heap.push(4u); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> BinaryHeap { BinaryHeap { data: vec![] } } /// Creates an empty `BinaryHeap` with a specific capacity. @@ -197,7 +197,7 @@ impl BinaryHeap { /// let mut heap = BinaryHeap::with_capacity(10); /// heap.push(4u); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(capacity: uint) -> BinaryHeap { BinaryHeap { data: Vec::with_capacity(capacity) } } @@ -235,7 +235,7 @@ impl BinaryHeap { /// println!("{}", x); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter(&self) -> Iter { Iter { iter: self.data.iter() } } @@ -256,7 +256,7 @@ impl BinaryHeap { /// println!("{}", x); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { IntoIter { iter: self.data.into_iter() } } @@ -291,7 +291,7 @@ impl BinaryHeap { /// assert!(heap.capacity() >= 100); /// heap.push(4u); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.data.capacity() } /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the @@ -314,7 +314,7 @@ impl BinaryHeap { /// assert!(heap.capacity() >= 100); /// heap.push(4u); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_exact(&mut self, additional: uint) { self.data.reserve_exact(additional); } @@ -335,13 +335,13 @@ impl BinaryHeap { /// assert!(heap.capacity() >= 100); /// heap.push(4u); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve(&mut self, additional: uint) { self.data.reserve(additional); } /// Discards as much additional capacity as possible. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn shrink_to_fit(&mut self) { self.data.shrink_to_fit(); } @@ -359,7 +359,7 @@ impl BinaryHeap { /// assert_eq!(heap.pop(), Some(1)); /// assert_eq!(heap.pop(), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop(&mut self) -> Option { self.data.pop().map(|mut item| { if !self.is_empty() { @@ -384,7 +384,7 @@ impl BinaryHeap { /// assert_eq!(heap.len(), 3); /// assert_eq!(heap.peek(), Some(&5)); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push(&mut self, item: T) { let old_len = self.len(); self.data.push(item); @@ -539,11 +539,11 @@ impl BinaryHeap { } /// Returns the length of the binary heap. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.data.len() } /// Checks if the binary heap is empty. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } /// Clears the binary heap, returning an iterator over the removed elements. @@ -554,7 +554,7 @@ impl BinaryHeap { } /// Drops all items from the binary heap. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { self.drain(); } } @@ -570,6 +570,7 @@ impl<'a, T> Clone for Iter<'a, T> { } } +#[stable] impl<'a, T> Iterator<&'a T> for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { self.iter.next() } @@ -578,11 +579,13 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } +#[stable] impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} /// An iterator that moves out of a `BinaryHeap`. @@ -590,6 +593,7 @@ pub struct IntoIter { iter: vec::IntoIter, } +#[stable] impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.iter.next() } @@ -598,11 +602,13 @@ impl Iterator for IntoIter { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() } } +#[stable] impl ExactSizeIterator for IntoIter {} /// An iterator that drains a `BinaryHeap`. @@ -610,6 +616,7 @@ pub struct Drain<'a, T: 'a> { iter: vec::Drain<'a, T>, } +#[stable] impl<'a, T: 'a> Iterator for Drain<'a, T> { #[inline] fn next(&mut self) -> Option { self.iter.next() } @@ -618,19 +625,23 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() } } +#[stable] impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} +#[stable] impl FromIterator for BinaryHeap { fn from_iter>(iter: Iter) -> BinaryHeap { BinaryHeap::from_vec(iter.collect()) } } +#[stable] impl Extend for BinaryHeap { fn extend>(&mut self, mut iter: Iter) { let (lower, _) = iter.size_hint(); diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index e29f19bbed3..d8dfc02c97a 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -88,14 +88,15 @@ use core::fmt; use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take, repeat}; use core::iter; use core::num::Int; -use core::slice::{Iter, IterMut}; +use core::slice; use core::{u8, u32, uint}; +use bitv_set; //so meta use core::hash; use Vec; -type Blocks<'a> = Cloned>; -type MutBlocks<'a> = IterMut<'a, u32>; +type Blocks<'a> = Cloned>; +type MutBlocks<'a> = slice::IterMut<'a, u32>; type MatchWords<'a> = Chain>, Skip>>>>; fn reverse_bits(byte: u8) -> u8 { @@ -152,6 +153,7 @@ static FALSE: bool = false; /// println!("{}", bv.to_string()); /// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count()); /// ``` +#[stable] pub struct Bitv { /// Internal representation of the bit vector storage: Vec, @@ -162,7 +164,7 @@ pub struct Bitv { // FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) impl Index for Bitv { #[inline] - fn index<'a>(&'a self, i: &uint) -> &'a bool { + fn index(&self, i: &uint) -> &bool { if self.get(*i).expect("index out of bounds") { &TRUE } else { @@ -245,7 +247,7 @@ impl Bitv { /// use std::collections::Bitv; /// let mut bv = Bitv::new(); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> Bitv { Bitv { storage: Vec::new(), nbits: 0 } } @@ -281,7 +283,7 @@ impl Bitv { /// /// It is important to note that this function does not specify the /// *length* of the returned bitvector, but only the *capacity*. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(nbits: uint) -> Bitv { Bitv { storage: Vec::with_capacity(blocks_for_bits(nbits)), @@ -367,7 +369,7 @@ impl Bitv { /// assert_eq!(bv[1], true); /// ``` #[inline] - #[unstable = "panic semantics are likely to change in the future"] + #[stable] pub fn get(&self, i: uint) -> Option { if i >= self.nbits { return None; @@ -578,9 +580,9 @@ impl Bitv { /// assert_eq!(bv.iter().filter(|x| *x).count(), 7); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Bits<'a> { - Bits { bitv: self, next_idx: 0, end_idx: self.nbits } + #[stable] + pub fn iter(&self) -> Iter { + Iter { bitv: self, next_idx: 0, end_idx: self.nbits } } /// Returns `true` if all bits are 0. @@ -705,7 +707,7 @@ impl Bitv { /// bv.truncate(2); /// assert!(bv.eq_vec(&[false, true])); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn truncate(&mut self, len: uint) { if len < self.len() { self.nbits = len; @@ -732,7 +734,7 @@ impl Bitv { /// assert_eq!(bv.len(), 3); /// assert!(bv.capacity() >= 13); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve(&mut self, additional: uint) { let desired_cap = self.len().checked_add(additional).expect("capacity overflow"); let storage_len = self.storage.len(); @@ -762,7 +764,7 @@ impl Bitv { /// assert_eq!(bv.len(), 3); /// assert!(bv.capacity() >= 13); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_exact(&mut self, additional: uint) { let desired_cap = self.len().checked_add(additional).expect("capacity overflow"); let storage_len = self.storage.len(); @@ -784,7 +786,7 @@ impl Bitv { /// assert!(bv.capacity() >= 10); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.storage.capacity().checked_mul(u32::BITS).unwrap_or(uint::MAX) } @@ -855,7 +857,7 @@ impl Bitv { /// assert_eq!(bv.pop(), Some(false)); /// assert_eq!(bv.len(), 6); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop(&mut self) -> Option { if self.is_empty() { None @@ -885,7 +887,7 @@ impl Bitv { /// bv.push(false); /// assert!(bv.eq_vec(&[true, false])); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push(&mut self, elem: bool) { if self.nbits % u32::BITS == 0 { self.storage.push(0); @@ -897,17 +899,17 @@ impl Bitv { /// Return the total number of bits in this vector #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.nbits } /// Returns true if there are no bits in this vector #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } /// Clears all bits in this vector. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { for w in self.storage.iter_mut() { *w = 0u32; } } @@ -928,10 +930,10 @@ pub fn from_fn(len: uint, f: F) -> Bitv where F: FnMut(uint) -> bool { #[stable] impl Default for Bitv { #[inline] - #[stable] fn default() -> Bitv { Bitv::new() } } +#[stable] impl FromIterator for Bitv { fn from_iter>(iterator: I) -> Bitv { let mut ret = Bitv::new(); @@ -940,6 +942,7 @@ impl FromIterator for Bitv { } } +#[stable] impl Extend for Bitv { #[inline] fn extend>(&mut self, mut iterator: I) { @@ -981,6 +984,7 @@ impl Ord for Bitv { } } +#[stable] impl fmt::Show for Bitv { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { for bit in self.iter() { @@ -990,6 +994,7 @@ impl fmt::Show for Bitv { } } +#[stable] impl hash::Hash for Bitv { fn hash(&self, state: &mut S) { self.nbits.hash(state); @@ -1014,14 +1019,16 @@ impl cmp::PartialEq for Bitv { impl cmp::Eq for Bitv {} /// An iterator for `Bitv`. +#[stable] #[deriving(Clone)] -pub struct Bits<'a> { +pub struct Iter<'a> { bitv: &'a Bitv, next_idx: uint, end_idx: uint, } -impl<'a> Iterator for Bits<'a> { +#[stable] +impl<'a> Iterator for Iter<'a> { #[inline] fn next(&mut self) -> Option { if self.next_idx != self.end_idx { @@ -1039,7 +1046,8 @@ impl<'a> Iterator for Bits<'a> { } } -impl<'a> DoubleEndedIterator for Bits<'a> { +#[stable] +impl<'a> DoubleEndedIterator for Iter<'a> { #[inline] fn next_back(&mut self) -> Option { if self.next_idx != self.end_idx { @@ -1051,9 +1059,11 @@ impl<'a> DoubleEndedIterator for Bits<'a> { } } -impl<'a> ExactSizeIterator for Bits<'a> {} +#[stable] +impl<'a> ExactSizeIterator for Iter<'a> {} -impl<'a> RandomAccessIterator for Bits<'a> { +#[stable] +impl<'a> RandomAccessIterator for Iter<'a> { #[inline] fn indexable(&self) -> uint { self.end_idx - self.next_idx @@ -1108,15 +1118,18 @@ impl<'a> RandomAccessIterator for Bits<'a> { /// assert!(bv[3]); /// ``` #[deriving(Clone)] +#[stable] pub struct BitvSet { bitv: Bitv, } +#[stable] impl Default for BitvSet { #[inline] fn default() -> BitvSet { BitvSet::new() } } +#[stable] impl FromIterator for BitvSet { fn from_iter>(iterator: I) -> BitvSet { let mut ret = BitvSet::new(); @@ -1125,6 +1138,7 @@ impl FromIterator for BitvSet { } } +#[stable] impl Extend for BitvSet { #[inline] fn extend>(&mut self, mut iterator: I) { @@ -1175,7 +1189,7 @@ impl BitvSet { /// let mut s = BitvSet::new(); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> BitvSet { BitvSet { bitv: Bitv::new() } } @@ -1192,7 +1206,7 @@ impl BitvSet { /// assert!(s.capacity() >= 100); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(nbits: uint) -> BitvSet { let bitv = Bitv::from_elem(nbits, false); BitvSet::from_bitv(bitv) @@ -1230,7 +1244,7 @@ impl BitvSet { /// assert!(s.capacity() >= 100); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.bitv.capacity() } @@ -1251,7 +1265,7 @@ impl BitvSet { /// s.reserve_len(10); /// assert!(s.capacity() >= 10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_len(&mut self, len: uint) { let cur_len = self.bitv.len(); if len >= cur_len { @@ -1277,7 +1291,7 @@ impl BitvSet { /// s.reserve_len_exact(10); /// assert!(s.capacity() >= 10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_len_exact(&mut self, len: uint) { let cur_len = self.bitv.len(); if len >= cur_len { @@ -1320,7 +1334,7 @@ impl BitvSet { /// assert_eq!(bv[0], true); /// ``` #[inline] - pub fn get_ref<'a>(&'a self) -> &'a Bitv { + pub fn get_ref(&self) -> &Bitv { &self.bitv } @@ -1371,7 +1385,7 @@ impl BitvSet { /// println!("new capacity: {}", s.capacity()); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn shrink_to_fit(&mut self) { let bitv = &mut self.bitv; // Obtain original length @@ -1399,9 +1413,9 @@ impl BitvSet { /// } /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> BitPositions<'a> { - BitPositions {set: self, next_idx: 0u} + #[stable] + pub fn iter(&self) -> bitv_set::Iter { + SetIter {set: self, next_idx: 0u} } /// Iterator over each u32 stored in `self` union `other`. @@ -1421,17 +1435,17 @@ impl BitvSet { /// } /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> { + #[stable] + pub fn union<'a>(&'a self, other: &'a BitvSet) -> Union<'a> { fn or(w1: u32, w2: u32) -> u32 { w1 | w2 } - TwoBitPositions { + Union(TwoBitPositions { set: self, other: other, merge: or, current_word: 0u32, next_idx: 0u - } + }) } /// Iterator over each uint stored in `self` intersect `other`. @@ -1451,17 +1465,17 @@ impl BitvSet { /// } /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take> { + #[stable] + pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Intersection<'a> { fn bitand(w1: u32, w2: u32) -> u32 { w1 & w2 } let min = cmp::min(self.bitv.len(), other.bitv.len()); - TwoBitPositions { + Intersection(TwoBitPositions { set: self, other: other, merge: bitand, current_word: 0u32, next_idx: 0 - }.take(min) + }.take(min)) } /// Iterator over each uint stored in the `self` setminus `other`. @@ -1488,17 +1502,17 @@ impl BitvSet { /// } /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> { + #[stable] + pub fn difference<'a>(&'a self, other: &'a BitvSet) -> Difference<'a> { fn diff(w1: u32, w2: u32) -> u32 { w1 & !w2 } - TwoBitPositions { + Difference(TwoBitPositions { set: self, other: other, merge: diff, current_word: 0u32, next_idx: 0 - } + }) } /// Iterator over each u32 stored in the symmetric difference of `self` and `other`. @@ -1519,17 +1533,17 @@ impl BitvSet { /// } /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> { + #[stable] + pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> SymmetricDifference<'a> { fn bitxor(w1: u32, w2: u32) -> u32 { w1 ^ w2 } - TwoBitPositions { + SymmetricDifference(TwoBitPositions { set: self, other: other, merge: bitxor, current_word: 0u32, next_idx: 0 - } + }) } /// Unions in-place with the specified other bit vector. @@ -1636,28 +1650,28 @@ impl BitvSet { /// Return the number of set bits in this set. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.bitv.blocks().fold(0, |acc, n| acc + n.count_ones()) } /// Returns whether there are no bits set in this set #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.bitv.none() } /// Clears all bits in this set #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { self.bitv.clear(); } /// Returns `true` if this set contains the specified integer. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains(&self, value: &uint) -> bool { let bitv = &self.bitv; *value < bitv.nbits && bitv[*value] @@ -1666,14 +1680,14 @@ impl BitvSet { /// Returns `true` if the set has no elements in common with `other`. /// This is equivalent to checking for an empty intersection. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_disjoint(&self, other: &BitvSet) -> bool { self.intersection(other).next().is_none() } /// Returns `true` if the set is a subset of another. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_subset(&self, other: &BitvSet) -> bool { let self_bitv = &self.bitv; let other_bitv = &other.bitv; @@ -1687,14 +1701,14 @@ impl BitvSet { /// Returns `true` if the set is a superset of another. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_superset(&self, other: &BitvSet) -> bool { other.is_subset(self) } /// Adds a value to the set. Returns `true` if the value was not already /// present in the set. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, value: uint) -> bool { if self.contains(&value) { return false; @@ -1712,7 +1726,7 @@ impl BitvSet { /// Removes a value from the set. Returns `true` if the value was /// present in the set. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, value: &uint) -> bool { if !self.contains(value) { return false; @@ -1749,14 +1763,15 @@ impl hash::Hash for BitvSet { /// An iterator for `BitvSet`. #[deriving(Clone)] -pub struct BitPositions<'a> { +#[stable] +pub struct SetIter<'a> { set: &'a BitvSet, next_idx: uint } /// An iterator combining two `BitvSet` iterators. #[deriving(Clone)] -pub struct TwoBitPositions<'a> { +struct TwoBitPositions<'a> { set: &'a BitvSet, other: &'a BitvSet, merge: fn(u32, u32) -> u32, @@ -1764,7 +1779,17 @@ pub struct TwoBitPositions<'a> { next_idx: uint } -impl<'a> Iterator for BitPositions<'a> { +#[stable] +pub struct Union<'a>(TwoBitPositions<'a>); +#[stable] +pub struct Intersection<'a>(Take>); +#[stable] +pub struct Difference<'a>(TwoBitPositions<'a>); +#[stable] +pub struct SymmetricDifference<'a>(TwoBitPositions<'a>); + +#[stable] +impl<'a> Iterator for SetIter<'a> { fn next(&mut self) -> Option { while self.next_idx < self.set.bitv.len() { let idx = self.next_idx; @@ -1784,6 +1809,7 @@ impl<'a> Iterator for BitPositions<'a> { } } +#[stable] impl<'a> Iterator for TwoBitPositions<'a> { fn next(&mut self) -> Option { while self.next_idx < self.set.bitv.len() || @@ -1819,8 +1845,29 @@ impl<'a> Iterator for TwoBitPositions<'a> { } } +#[stable] +impl<'a> Iterator for Union<'a> { + #[inline] fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } +} +#[stable] +impl<'a> Iterator for Intersection<'a> { + #[inline] fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } +} +#[stable] +impl<'a> Iterator for Difference<'a> { + #[inline] fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } +} + +#[stable] +impl<'a> Iterator for SymmetricDifference<'a> { + #[inline] fn next(&mut self) -> Option { self.0.next() } + #[inline] fn size_hint(&self) -> (uint, Option) { self.0.size_hint() } +} #[cfg(test)] diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index a3dff3e8706..87b40aa1cee 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -80,6 +80,7 @@ use self::Continuation::{Continue, Finished}; /// done on each operation isn't *catastrophic*, and *is* still bounded by O(B logBn), /// it is certainly much slower when it does. #[deriving(Clone)] +#[stable] pub struct BTreeMap { root: Node, length: uint, @@ -96,26 +97,31 @@ struct AbsIter { } /// An iterator over a BTreeMap's entries. +#[stable] pub struct Iter<'a, K: 'a, V: 'a> { inner: AbsIter> } /// A mutable iterator over a BTreeMap's entries. +#[stable] pub struct IterMut<'a, K: 'a, V: 'a> { inner: AbsIter> } /// An owning iterator over a BTreeMap's entries. +#[stable] pub struct IntoIter { inner: AbsIter> } /// An iterator over a BTreeMap's keys. +#[stable] pub struct Keys<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> } /// An iterator over a BTreeMap's values. +#[stable] pub struct Values<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> } @@ -141,7 +147,7 @@ pub struct OccupiedEntry<'a, K:'a, V:'a> { impl BTreeMap { /// Makes a new empty BTreeMap with a reasonable choice for B. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> BTreeMap { //FIXME(Gankro): Tune this as a function of size_of? BTreeMap::with_b(6) @@ -172,7 +178,7 @@ impl BTreeMap { /// a.clear(); /// assert!(a.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { let b = self.b; // avoid recursive destructors by manually traversing the tree @@ -208,7 +214,7 @@ impl BTreeMap { /// assert_eq!(map.get(&1), Some(&"a")); /// assert_eq!(map.get(&2), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get(&self, key: &Q) -> Option<&V> where Q: BorrowFrom + Ord { let mut cur_node = &self.root; loop { @@ -240,7 +246,7 @@ impl BTreeMap { /// assert_eq!(map.contains_key(&1), true); /// assert_eq!(map.contains_key(&2), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains_key(&self, key: &Q) -> bool where Q: BorrowFrom + Ord { self.get(key).is_some() } @@ -270,7 +276,7 @@ impl BTreeMap { /// assert_eq!(map[1], "b"); /// ``` // See `get` for implementation notes, this is basically a copy-paste with mut's added - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> where Q: BorrowFrom + Ord { // temp_node is a Borrowck hack for having a mutable value outlive a loop iteration let mut temp_node = &mut self.root; @@ -337,7 +343,7 @@ impl BTreeMap { /// assert_eq!(map.insert(37, "c"), Some("b")); /// assert_eq!(map[37], "c"); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, mut key: K, mut value: V) -> Option { // This is a stack of rawptrs to nodes paired with indices, respectively // representing the nodes and edges of our search path. We have to store rawptrs @@ -452,7 +458,7 @@ impl BTreeMap { /// assert_eq!(map.remove(&1), Some("a")); /// assert_eq!(map.remove(&1), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, key: &Q) -> Option where Q: BorrowFrom + Ord { // See `swap` for a more thorough description of the stuff going on in here let mut stack = stack::PartialSearchStack::new(self); @@ -810,6 +816,7 @@ mod stack { } } +#[stable] impl FromIterator<(K, V)> for BTreeMap { fn from_iter>(iter: T) -> BTreeMap { let mut map = BTreeMap::new(); @@ -818,6 +825,7 @@ impl FromIterator<(K, V)> for BTreeMap { } } +#[stable] impl Extend<(K, V)> for BTreeMap { #[inline] fn extend>(&mut self, mut iter: T) { @@ -827,6 +835,7 @@ impl Extend<(K, V)> for BTreeMap { } } +#[stable] impl, V: Hash> Hash for BTreeMap { fn hash(&self, state: &mut S) { for elt in self.iter() { @@ -870,6 +879,7 @@ impl Ord for BTreeMap { } } +#[stable] impl Show for BTreeMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -883,6 +893,7 @@ impl Show for BTreeMap { } } +#[stable] impl Index for BTreeMap where Q: BorrowFrom + Ord { @@ -891,6 +902,7 @@ impl Index for BTreeMap } } +#[stable] impl IndexMut for BTreeMap where Q: BorrowFrom + Ord { @@ -1036,53 +1048,64 @@ impl + DoubleEndedIterator>> } } +#[stable] impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Iter<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next_back() } } +#[stable] impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Iter<'a, K, V> {} - +#[stable] impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() } } +#[stable] impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {} - +#[stable] impl Iterator<(K, V)> for IntoIter { fn next(&mut self) -> Option<(K, V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl DoubleEndedIterator<(K, V)> for IntoIter { fn next_back(&mut self) -> Option<(K, V)> { self.inner.next_back() } } +#[stable] impl ExactSizeIterator<(K, V)> for IntoIter {} - +#[stable] impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { fn next(&mut self) -> Option<(&'a K)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> DoubleEndedIterator<&'a K> for Keys<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K)> { self.inner.next_back() } } +#[stable] impl<'a, K, V> ExactSizeIterator<&'a K> for Keys<'a, K, V> {} - +#[stable] impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> { fn next(&mut self) -> Option<(&'a V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> DoubleEndedIterator<&'a V> for Values<'a, K, V> { fn next_back(&mut self) -> Option<(&'a V)> { self.inner.next_back() } } +#[stable] impl<'a, K, V> ExactSizeIterator<&'a V> for Values<'a, K, V> {} @@ -1143,8 +1166,8 @@ impl BTreeMap { /// let (first_key, first_value) = map.iter().next().unwrap(); /// assert_eq!((*first_key, *first_value), (1u, "a")); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Iter<'a, K, V> { + #[stable] + pub fn iter(&self) -> Iter { let len = self.len(); Iter { inner: AbsIter { @@ -1175,8 +1198,8 @@ impl BTreeMap { /// } /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, K, V> { + #[stable] + pub fn iter_mut(&mut self) -> IterMut { let len = self.len(); IterMut { inner: AbsIter { @@ -1204,7 +1227,7 @@ impl BTreeMap { /// println!("{}: {}", key, value); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { let len = self.len(); IntoIter { @@ -1231,7 +1254,7 @@ impl BTreeMap { /// let keys: Vec = a.keys().cloned().collect(); /// assert_eq!(keys, vec![1u,2,]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn pointer @@ -1253,7 +1276,7 @@ impl BTreeMap { /// let values: Vec<&str> = a.values().cloned().collect(); /// assert_eq!(values, vec!["a","b"]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn pointer @@ -1273,7 +1296,7 @@ impl BTreeMap { /// a.insert(1u, "a"); /// assert_eq!(a.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.length } /// Return true if the map contains no elements. @@ -1288,7 +1311,7 @@ impl BTreeMap { /// a.insert(1u, "a"); /// assert!(!a.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } } diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 2935692ed15..f3f6727f1c0 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -28,39 +28,46 @@ use core::fmt::Show; /// See BTreeMap's documentation for a detailed discussion of this collection's performance /// benefits and drawbacks. #[deriving(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)] +#[stable] pub struct BTreeSet{ map: BTreeMap, } /// An iterator over a BTreeSet's items. +#[stable] pub struct Iter<'a, T: 'a> { iter: Keys<'a, T, ()> } /// An owning iterator over a BTreeSet's items. +#[stable] pub struct IntoIter { iter: Map<(T, ()), T, ::btree_map::IntoIter, fn((T, ())) -> T> } /// A lazy iterator producing elements in the set difference (in-order). +#[stable] pub struct Difference<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set symmetric difference (in-order). +#[stable] pub struct SymmetricDifference<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set intersection (in-order). +#[stable] pub struct Intersection<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set union (in-order). +#[stable] pub struct Union<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, @@ -76,7 +83,7 @@ impl BTreeSet { /// /// let mut set: BTreeSet = BTreeSet::new(); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> BTreeSet { BTreeSet { map: BTreeMap::new() } } @@ -84,6 +91,7 @@ impl BTreeSet { /// Makes a new BTreeSet with the given B. /// /// B cannot be less than 2. + #[unstable = "probably want this to be on the type, eventually"] pub fn with_b(b: uint) -> BTreeSet { BTreeSet { map: BTreeMap::with_b(b) } } @@ -106,8 +114,8 @@ impl BTreeSet { /// let v: Vec = set.iter().map(|&x| x).collect(); /// assert_eq!(v, vec![1u,2,3,4]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Iter<'a, T> { + #[stable] + pub fn iter(&self) -> Iter { Iter { iter: self.map.keys() } } @@ -123,7 +131,7 @@ impl BTreeSet { /// let v: Vec = set.into_iter().collect(); /// assert_eq!(v, vec![1u,2,3,4]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { fn first((a, _): (A, B)) -> A { a } let first: fn((T, ())) -> T = first; // coerce to fn pointer @@ -151,7 +159,7 @@ impl BTreeSet { /// let diff: Vec = a.difference(&b).cloned().collect(); /// assert_eq!(diff, vec![1u]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn difference<'a>(&'a self, other: &'a BTreeSet) -> Difference<'a, T> { Difference{a: self.iter().peekable(), b: other.iter().peekable()} } @@ -174,7 +182,7 @@ impl BTreeSet { /// let sym_diff: Vec = a.symmetric_difference(&b).cloned().collect(); /// assert_eq!(sym_diff, vec![1u,3]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet) -> SymmetricDifference<'a, T> { SymmetricDifference{a: self.iter().peekable(), b: other.iter().peekable()} @@ -198,7 +206,7 @@ impl BTreeSet { /// let intersection: Vec = a.intersection(&b).cloned().collect(); /// assert_eq!(intersection, vec![2u]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn intersection<'a>(&'a self, other: &'a BTreeSet) -> Intersection<'a, T> { Intersection{a: self.iter().peekable(), b: other.iter().peekable()} @@ -220,7 +228,7 @@ impl BTreeSet { /// let union: Vec = a.union(&b).cloned().collect(); /// assert_eq!(union, vec![1u,2]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn union<'a>(&'a self, other: &'a BTreeSet) -> Union<'a, T> { Union{a: self.iter().peekable(), b: other.iter().peekable()} } @@ -237,7 +245,7 @@ impl BTreeSet { /// v.insert(1i); /// assert_eq!(v.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.map.len() } /// Returns true if the set contains no elements @@ -252,7 +260,7 @@ impl BTreeSet { /// v.insert(1i); /// assert!(!v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } /// Clears the set, removing all values. @@ -267,7 +275,7 @@ impl BTreeSet { /// v.clear(); /// assert!(v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { self.map.clear() } @@ -287,7 +295,7 @@ impl BTreeSet { /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains(&self, value: &Q) -> bool where Q: BorrowFrom + Ord { self.map.contains_key(value) } @@ -309,7 +317,7 @@ impl BTreeSet { /// b.insert(1); /// assert_eq!(a.is_disjoint(&b), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_disjoint(&self, other: &BTreeSet) -> bool { self.intersection(other).next().is_none() } @@ -330,7 +338,7 @@ impl BTreeSet { /// set.insert(4); /// assert_eq!(set.is_subset(&sup), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_subset(&self, other: &BTreeSet) -> bool { // Stolen from TreeMap let mut x = self.iter(); @@ -375,7 +383,7 @@ impl BTreeSet { /// set.insert(2); /// assert_eq!(set.is_superset(&sub), true); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_superset(&self, other: &BTreeSet) -> bool { other.is_subset(self) } @@ -394,7 +402,7 @@ impl BTreeSet { /// assert_eq!(set.insert(2i), false); /// assert_eq!(set.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()).is_none() } @@ -417,12 +425,13 @@ impl BTreeSet { /// assert_eq!(set.remove(&2), true); /// assert_eq!(set.remove(&2), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, value: &Q) -> bool where Q: BorrowFrom + Ord { self.map.remove(value).is_some() } } +#[stable] impl FromIterator for BTreeSet { fn from_iter>(iter: Iter) -> BTreeSet { let mut set = BTreeSet::new(); @@ -431,6 +440,7 @@ impl FromIterator for BTreeSet { } } +#[stable] impl Extend for BTreeSet { #[inline] fn extend>(&mut self, mut iter: Iter) { @@ -448,7 +458,7 @@ impl Default for BTreeSet { } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet { /// Returns the difference of `self` and `rhs` as a new `BTreeSet`. /// @@ -469,7 +479,7 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet, BTreeSet> for &'a BTreeSet< } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeSet { /// Returns the symmetric difference of `self` and `rhs` as a new `BTreeSet`. /// @@ -490,7 +500,7 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet, BTreeSet> for &'a BTreeS } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeSet { /// Returns the intersection of `self` and `rhs` as a new `BTreeSet`. /// @@ -511,7 +521,7 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet, BTreeSet> for &'a BTreeS } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet, BTreeSet> for &'a BTreeSet { /// Returns the union of `self` and `rhs` as a new `BTreeSet`. /// @@ -532,6 +542,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet, BTreeSet> for &'a BTreeSe } } +#[stable] impl Show for BTreeSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -545,23 +556,28 @@ impl Show for BTreeSet { } } +#[stable] impl<'a, T> Iterator<&'a T> for Iter<'a, T> { fn next(&mut self) -> Option<&'a T> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } +#[stable] impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} - +#[stable] impl Iterator for IntoIter { fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option { self.iter.next_back() } } +#[stable] impl ExactSizeIterator for IntoIter {} /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None @@ -574,6 +590,7 @@ fn cmp_opt(x: Option<&T>, y: Option<&T>, } } +#[stable] impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { @@ -586,6 +603,7 @@ impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> { } } +#[stable] impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { @@ -598,6 +616,7 @@ impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> { } } +#[stable] impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { @@ -616,6 +635,7 @@ impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> { } } +#[stable] impl<'a, T: Ord> Iterator<&'a T> for Union<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 82dabedd871..ff177f2200b 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -30,6 +30,7 @@ use core::ptr; use std::hash::{Writer, Hash}; /// A doubly-linked list. +#[stable] pub struct DList { length: uint, list_head: Link, @@ -53,20 +54,27 @@ struct Node { } /// An iterator over references to the items of a `DList`. +#[stable] pub struct Iter<'a, T:'a> { head: &'a Link, tail: Rawlink>, nelem: uint, } -// FIXME #11820: the &'a Option<> of the Link stops clone working. +// FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone). +#[stable] impl<'a, T> Clone for Iter<'a, T> { - fn clone(&self) -> Iter<'a, T> { *self } + fn clone(&self) -> Iter<'a, T> { + Iter { + head: self.head.clone(), + tail: self.tail, + nelem: self.nelem, + } + } } -impl<'a,T> Copy for Iter<'a,T> {} - /// An iterator over mutable references to the items of a `DList`. +#[stable] pub struct IterMut<'a, T:'a> { list: &'a mut DList, head: Rawlink>, @@ -76,6 +84,7 @@ pub struct IterMut<'a, T:'a> { /// An iterator over mutable references to the items of a `DList`. #[deriving(Clone)] +#[stable] pub struct IntoIter { list: DList } @@ -204,59 +213,21 @@ impl Default for DList { impl DList { /// Creates an empty `DList`. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> DList { DList{list_head: None, list_tail: Rawlink::none(), length: 0} } - /// Moves the last element to the front of the list. - /// - /// If the list is empty, does nothing. - /// - /// # Examples - /// - /// ```rust - /// use std::collections::DList; - /// - /// let mut dl = DList::new(); - /// dl.push_back(1i); - /// dl.push_back(2); - /// dl.push_back(3); - /// - /// dl.rotate_forward(); - /// - /// for e in dl.iter() { - /// println!("{}", e); // prints 3, then 1, then 2 - /// } - /// ``` - #[inline] + /// Deprecated: Not clearly useful enough; use split and append when available. + #[deprecated = "Not clearly useful enough; use split and append when available"] pub fn rotate_forward(&mut self) { self.pop_back_node().map(|tail| { self.push_front_node(tail) }); } - /// Moves the first element to the back of the list. - /// - /// If the list is empty, does nothing. - /// - /// # Examples - /// - /// ```rust - /// use std::collections::DList; - /// - /// let mut dl = DList::new(); - /// dl.push_back(1i); - /// dl.push_back(2); - /// dl.push_back(3); - /// - /// dl.rotate_backward(); - /// - /// for e in dl.iter() { - /// println!("{}", e); // prints 2, then 3, then 1 - /// } - /// ``` - #[inline] + /// Deprecated: Not clearly useful enough; use split and append when available. + #[deprecated = "Not clearly useful enough; use split and append when available"] pub fn rotate_backward(&mut self) { self.pop_front_node().map(|head| { self.push_back_node(head) @@ -285,6 +256,7 @@ impl DList { /// println!("{}", e); // prints 1, then 2, then 3, then 4 /// } /// ``` + #[unstable = "append should be by-mutable-reference"] pub fn append(&mut self, mut other: DList) { match self.list_tail.resolve() { None => *self = other, @@ -304,57 +276,15 @@ impl DList { } } - /// Adds all elements from `other` to the beginning of the list. - /// - /// This operation should compute in O(1) time. - /// - /// # Examples - /// - /// ```rust - /// use std::collections::DList; - /// - /// let mut a = DList::new(); - /// let mut b = DList::new(); - /// a.push_back(1i); - /// a.push_back(2); - /// b.push_back(3i); - /// b.push_back(4); - /// - /// a.prepend(b); - /// - /// for e in a.iter() { - /// println!("{}", e); // prints 3, then 4, then 1, then 2 - /// } - /// ``` - #[inline] + /// Deprecated: Use append and a swap instead. + #[deprecated = "Use append and a swap instead"] pub fn prepend(&mut self, mut other: DList) { mem::swap(self, &mut other); self.append(other); } - /// Inserts `elt` before the first `x` in the list where `f(x, elt)` is - /// true, or at the end. - /// - /// This operation should compute in O(N) time. - /// - /// # Examples - /// - /// ```rust - /// use std::collections::DList; - /// - /// let mut a: DList = DList::new(); - /// a.push_back(2i); - /// a.push_back(4); - /// a.push_back(7); - /// a.push_back(8); - /// - /// // insert 11 before the first odd number in the list - /// a.insert_when(11, |&e, _| e % 2 == 1); - /// - /// for e in a.iter() { - /// println!("{}", e); // prints 2, then 4, then 11, then 7, then 8 - /// } - /// ``` + /// Deprecated: Use custom methods on IterMut. + #[deprecated = "Use custom methods on IterMut"] pub fn insert_when(&mut self, elt: T, mut f: F) where F: FnMut(&T, &T) -> bool { let mut it = self.iter_mut(); loop { @@ -367,12 +297,8 @@ impl DList { it.insert_next(elt); } - /// Merges `other` into this `DList`, using the function `f`. - /// - /// Iterates both `DList`s with `a` from self and `b` from `other`, and - /// put `a` in the result if `f(a, b)` is true, and otherwise `b`. - /// - /// This operation should compute in O(max(N, M)) time. + /// Deprecated: Use custom methods on IterMut. + #[deprecated = "Use custom methods on IterMut"] pub fn merge(&mut self, mut other: DList, mut f: F) where F: FnMut(&T, &T) -> bool { { let mut it = self.iter_mut(); @@ -395,15 +321,15 @@ impl DList { /// Provides a forward iterator. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Iter<'a, T> { + #[stable] + pub fn iter(&self) -> Iter { Iter{nelem: self.len(), head: &self.list_head, tail: self.list_tail} } /// Provides a forward iterator with mutable references. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { + #[stable] + pub fn iter_mut(&mut self) -> IterMut { let head_raw = match self.list_head { Some(ref mut h) => Rawlink::some(&mut **h), None => Rawlink::none(), @@ -418,7 +344,7 @@ impl DList { /// Consumes the list into an iterator yielding elements by value. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { IntoIter{list: self} } @@ -427,7 +353,7 @@ impl DList { /// /// This operation should compute in O(1) time. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.list_head.is_none() } @@ -436,7 +362,7 @@ impl DList { /// /// This operation should compute in O(1) time. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.length } @@ -445,7 +371,7 @@ impl DList { /// /// This operation should compute in O(n) time. #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { *self = DList::new() } @@ -485,7 +411,7 @@ impl DList { /// Adds an element first in the list. /// /// This operation should compute in O(1) time. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push_front(&mut self, elt: T) { self.push_front_node(box Node::new(elt)) } @@ -494,7 +420,7 @@ impl DList { /// empty. /// /// This operation should compute in O(1) time. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop_front(&mut self) -> Option { self.pop_front_node().map(|box Node{value, ..}| value) } @@ -517,7 +443,7 @@ impl DList { /// d.push_back(3); /// assert_eq!(3, *d.back().unwrap()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push_back(&mut self, elt: T) { self.push_back_node(box Node::new(elt)) } @@ -542,23 +468,23 @@ impl DList { /// d.push_back(3); /// assert_eq!(d.pop_back(), Some(3)); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop_back(&mut self) -> Option { self.pop_back_node().map(|box Node{value, ..}| value) } } impl DList { - /// Inserts `elt` sorted in ascending order. - /// - /// This operation should compute in O(N) time. - #[inline] + /// Deprecated: Why are you maintaining a sorted DList? + #[deprecated = "Why are you maintaining a sorted DList?"] + #[allow(deprecated)] pub fn insert_ordered(&mut self, elt: T) { self.insert_when(elt, |a, b| a >= b) } } #[unsafe_destructor] +#[stable] impl Drop for DList { fn drop(&mut self) { // Dissolve the dlist in backwards direction @@ -580,7 +506,7 @@ impl Drop for DList { } } - +#[stable] impl<'a, A> Iterator<&'a A> for Iter<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { @@ -600,6 +526,7 @@ impl<'a, A> Iterator<&'a A> for Iter<'a, A> { } } +#[stable] impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { @@ -614,8 +541,10 @@ impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { } } +#[stable] impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {} +#[stable] impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { @@ -638,6 +567,7 @@ impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { } } +#[stable] impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { @@ -652,6 +582,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { } } +#[stable] impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {} /// Allows mutating a `DList` while iterating. @@ -713,6 +644,7 @@ impl<'a, A> IterMut<'a, A> { /// } /// ``` #[inline] + #[unstable = "this is probably better handled by a cursor type -- we'll see"] pub fn insert_next(&mut self, elt: A) { self.insert_next_node(box Node::new(elt)) } @@ -733,6 +665,7 @@ impl<'a, A> IterMut<'a, A> { /// assert_eq!(it.next().unwrap(), &2); /// ``` #[inline] + #[unstable = "this is probably better handled by a cursor type -- we'll see"] pub fn peek_next(&mut self) -> Option<&mut A> { if self.nelem == 0 { return None @@ -741,6 +674,7 @@ impl<'a, A> IterMut<'a, A> { } } +#[stable] impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.list.pop_front() } @@ -751,11 +685,13 @@ impl Iterator for IntoIter { } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.list.pop_back() } } +#[stable] impl FromIterator for DList { fn from_iter>(iterator: T) -> DList { let mut ret = DList::new(); @@ -764,6 +700,7 @@ impl FromIterator for DList { } } +#[stable] impl Extend for DList { fn extend>(&mut self, mut iterator: T) { for elt in iterator { self.push_back(elt); } @@ -808,6 +745,7 @@ impl Clone for DList { } } +#[stable] impl fmt::Show for DList { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "[")); @@ -821,6 +759,7 @@ impl fmt::Show for DList { } } +#[stable] impl> Hash for DList { fn hash(&self, state: &mut S) { self.len().hash(state); diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 688214140c1..cbd8d4955b2 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -64,11 +64,12 @@ pub mod vec; pub mod vec_map; pub mod bitv { - pub use bit::{Bitv, Bits, from_fn, from_bytes}; + pub use bit::{Bitv, Iter, from_fn, from_bytes}; } pub mod bitv_set { - pub use bit::{BitvSet, BitPositions, TwoBitPositions}; + pub use bit::{BitvSet, Union, Intersection, Difference, SymmetricDifference}; + pub use bit::SetIter as Iter; } pub mod btree_map { diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index aeda7309064..12148947a19 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -35,6 +35,7 @@ static MINIMUM_CAPACITY: uint = 2u; // be scrapped anyway. Defer to rewrite? /// `RingBuf` is a circular buffer, which can be used as a double-ended queue efficiently. +#[stable] pub struct RingBuf { // tail and head are pointers into the buffer. Tail always points // to the first element that could be read, Head always points @@ -62,6 +63,7 @@ impl Clone for RingBuf { } #[unsafe_destructor] +#[stable] impl Drop for RingBuf { fn drop(&mut self) { self.clear(); @@ -77,7 +79,6 @@ impl Drop for RingBuf { #[stable] impl Default for RingBuf { - #[stable] #[inline] fn default() -> RingBuf { RingBuf::new() } } @@ -85,13 +86,13 @@ impl Default for RingBuf { impl RingBuf { /// Turn ptr into a slice #[inline] - unsafe fn buffer_as_slice<'a>(&'a self) -> &'a [T] { + unsafe fn buffer_as_slice(&self) -> &[T] { mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap }) } /// Turn ptr into a mut slice #[inline] - unsafe fn buffer_as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { + unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] { mem::transmute(RawSlice { data: self.ptr as *const T, len: self.cap }) } @@ -131,13 +132,13 @@ impl RingBuf { impl RingBuf { /// Creates an empty `RingBuf`. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> RingBuf { RingBuf::with_capacity(INITIAL_CAPACITY) } /// Creates an empty `RingBuf` with space for at least `n` elements. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(n: uint) -> RingBuf { // +1 since the ringbuffer always leaves one space empty let cap = cmp::max(n + 1, MINIMUM_CAPACITY).next_power_of_two(); @@ -175,7 +176,7 @@ impl RingBuf { /// buf.push_back(5); /// assert_eq!(buf.get(1).unwrap(), &4); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get(&self, i: uint) -> Option<&T> { if i < self.len() { let idx = self.wrap_index(self.tail + i); @@ -205,7 +206,7 @@ impl RingBuf { /// /// assert_eq!(buf[1], 7); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get_mut(&mut self, i: uint) -> Option<&mut T> { if i < self.len() { let idx = self.wrap_index(self.tail + i); @@ -257,7 +258,7 @@ impl RingBuf { /// assert!(buf.capacity() >= 10); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.cap - 1 } /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the @@ -280,7 +281,7 @@ impl RingBuf { /// buf.reserve_exact(10); /// assert!(buf.capacity() >= 11); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_exact(&mut self, additional: uint) { self.reserve(additional); } @@ -301,7 +302,7 @@ impl RingBuf { /// buf.reserve(10); /// assert!(buf.capacity() >= 11); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve(&mut self, additional: uint) { let new_len = self.len() + additional; assert!(new_len + 1 > self.len(), "capacity overflow"); @@ -382,7 +383,7 @@ impl RingBuf { /// let b: &[_] = &[&5, &3, &4]; /// assert_eq!(buf.iter().collect::>().as_slice(), b); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter(&self) -> Iter { Iter { tail: self.tail, @@ -408,7 +409,7 @@ impl RingBuf { /// let b: &[_] = &[&mut 3, &mut 1, &mut 2]; /// assert_eq!(buf.iter_mut().collect::>()[], b); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { IterMut { tail: self.tail, @@ -420,7 +421,7 @@ impl RingBuf { } /// Consumes the list into an iterator yielding elements by value. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { IntoIter { inner: self, @@ -481,7 +482,7 @@ impl RingBuf { /// v.push_back(1i); /// assert_eq!(v.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { count(self.tail, self.head, self.cap) } /// Returns true if the buffer contains no elements @@ -496,7 +497,7 @@ impl RingBuf { /// v.push_front(1i); /// assert!(!v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } /// Creates a draining iterator that clears the `RingBuf` and iterates over @@ -514,7 +515,7 @@ impl RingBuf { /// ``` #[inline] #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn drain<'a>(&'a mut self) -> Drain<'a, T> { + pub fn drain(&mut self) -> Drain { Drain { inner: self, } @@ -532,7 +533,7 @@ impl RingBuf { /// v.clear(); /// assert!(v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] #[inline] pub fn clear(&mut self) { self.drain(); @@ -643,7 +644,7 @@ impl RingBuf { /// assert_eq!(d.pop_front(), Some(2i)); /// assert_eq!(d.pop_front(), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop_front(&mut self) -> Option { if self.is_empty() { None @@ -666,7 +667,7 @@ impl RingBuf { /// d.push_front(2i); /// assert_eq!(d.front(), Some(&2i)); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push_front(&mut self, t: T) { if self.is_full() { self.reserve(1); @@ -696,7 +697,7 @@ impl RingBuf { /// buf.push_back(3); /// assert_eq!(3, *buf.back().unwrap()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn push_back(&mut self, t: T) { if self.is_full() { self.reserve(1); @@ -728,7 +729,7 @@ impl RingBuf { /// buf.push_back(3); /// assert_eq!(buf.pop_back(), Some(3)); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn pop_back(&mut self) -> Option { if self.is_empty() { None @@ -966,7 +967,7 @@ impl RingBuf { /// buf.remove(2); /// assert_eq!(Some(&15), buf.get(2)); /// ``` - #[unstable = "matches collection reform specification; waiting on panic semantics"] + #[stable] pub fn remove(&mut self, i: uint) -> Option { if self.is_empty() || self.len() <= i { return None; @@ -1129,6 +1130,7 @@ fn count(tail: uint, head: uint, size: uint) -> uint { } /// `RingBuf` iterator. +#[stable] pub struct Iter<'a, T:'a> { ring: &'a [T], tail: uint, @@ -1146,6 +1148,7 @@ impl<'a, T> Clone for Iter<'a, T> { } } +#[stable] impl<'a, T> Iterator<&'a T> for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { @@ -1164,6 +1167,7 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> { } } +#[stable] impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { @@ -1175,8 +1179,10 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { } } +#[stable] impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} +#[stable] impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { @@ -1199,6 +1205,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { // with returning the mutable reference. I couldn't find a way to // make the lifetime checker happy so, but there should be a way. /// `RingBuf` mutable iterator. +#[stable] pub struct IterMut<'a, T:'a> { ptr: *mut T, tail: uint, @@ -1207,6 +1214,7 @@ pub struct IterMut<'a, T:'a> { marker: marker::ContravariantLifetime<'a>, } +#[stable] impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { @@ -1228,6 +1236,7 @@ impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { } } +#[stable] impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { @@ -1242,13 +1251,16 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { } } +#[stable] impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} -// A by-value RingBuf iterator +/// A by-value RingBuf iterator +#[stable] pub struct IntoIter { inner: RingBuf, } +#[stable] impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { @@ -1262,6 +1274,7 @@ impl Iterator for IntoIter { } } +#[stable] impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { @@ -1269,14 +1282,17 @@ impl DoubleEndedIterator for IntoIter { } } +#[stable] impl ExactSizeIterator for IntoIter {} /// A draining RingBuf iterator +#[unstable = "matches collection reform specification, waiting for dust to settle"] pub struct Drain<'a, T: 'a> { inner: &'a mut RingBuf, } #[unsafe_destructor] +#[stable] impl<'a, T: 'a> Drop for Drain<'a, T> { fn drop(&mut self) { for _ in *self {} @@ -1285,6 +1301,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> { } } +#[stable] impl<'a, T: 'a> Iterator for Drain<'a, T> { #[inline] fn next(&mut self) -> Option { @@ -1298,6 +1315,7 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> { } } +#[stable] impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { #[inline] fn next_back(&mut self) -> Option { @@ -1305,6 +1323,7 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { } } +#[stable] impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {} #[stable] @@ -1333,6 +1352,7 @@ impl Ord for RingBuf { } } +#[stable] impl> Hash for RingBuf { fn hash(&self, state: &mut S) { self.len().hash(state); @@ -1342,6 +1362,7 @@ impl> Hash for RingBuf { } } +#[stable] impl Index for RingBuf { #[inline] fn index<'a>(&'a self, i: &uint) -> &'a A { @@ -1349,6 +1370,7 @@ impl Index for RingBuf { } } +#[stable] impl IndexMut for RingBuf { #[inline] fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A { @@ -1356,6 +1378,7 @@ impl IndexMut for RingBuf { } } +#[stable] impl FromIterator for RingBuf { fn from_iter>(iterator: T) -> RingBuf { let (lower, _) = iterator.size_hint(); @@ -1365,6 +1388,7 @@ impl FromIterator for RingBuf { } } +#[stable] impl Extend for RingBuf { fn extend>(&mut self, mut iterator: T) { for elt in iterator { @@ -1373,6 +1397,7 @@ impl Extend for RingBuf { } } +#[stable] impl fmt::Show for RingBuf { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "[")); diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 3a7168094ff..7c30912cf91 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -105,7 +105,7 @@ impl VecMap { /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::new(); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> VecMap { VecMap { v: vec![] } } /// Creates an empty `VecMap` with space for at least `capacity` @@ -117,7 +117,7 @@ impl VecMap { /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::with_capacity(10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(capacity: uint) -> VecMap { VecMap { v: Vec::with_capacity(capacity) } } @@ -133,7 +133,7 @@ impl VecMap { /// assert!(map.capacity() >= 10); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.v.capacity() } @@ -152,7 +152,7 @@ impl VecMap { /// map.reserve_len(10); /// assert!(map.capacity() >= 10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_len(&mut self, len: uint) { let cur_len = self.v.len(); if len >= cur_len { @@ -176,7 +176,7 @@ impl VecMap { /// map.reserve_len_exact(10); /// assert!(map.capacity() >= 10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve_len_exact(&mut self, len: uint) { let cur_len = self.v.len(); if len >= cur_len { @@ -186,7 +186,7 @@ impl VecMap { /// Returns an iterator visiting all keys in ascending order by the keys. /// The iterator's element type is `uint`. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn keys<'r>(&'r self) -> Keys<'r, V> { fn first((a, _): (A, B)) -> A { a } let first: fn((uint, &'r V)) -> uint = first; // coerce to fn pointer @@ -196,7 +196,7 @@ impl VecMap { /// Returns an iterator visiting all values in ascending order by the keys. /// The iterator's element type is `&'r V`. - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn values<'r>(&'r self) -> Values<'r, V> { fn second((_, b): (A, B)) -> B { b } let second: fn((uint, &'r V)) -> &'r V = second; // coerce to fn pointer @@ -222,7 +222,7 @@ impl VecMap { /// println!("{}: {}", key, value); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter<'r>(&'r self) -> Iter<'r, V> { Iter { front: 0, @@ -253,7 +253,7 @@ impl VecMap { /// assert_eq!(value, &"x"); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter_mut<'r>(&'r mut self) -> IterMut<'r, V> { IterMut { front: 0, @@ -281,7 +281,7 @@ impl VecMap { /// /// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(&mut self) -> IntoIter { fn filter((i, v): (uint, Option)) -> Option<(uint, A)> { v.map(|v| (i, v)) @@ -304,7 +304,7 @@ impl VecMap { /// a.insert(1, "a"); /// assert_eq!(a.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.v.iter().filter(|elt| elt.is_some()).count() } @@ -321,7 +321,7 @@ impl VecMap { /// a.insert(1, "a"); /// assert!(!a.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.v.iter().all(|elt| elt.is_none()) } @@ -338,7 +338,7 @@ impl VecMap { /// a.clear(); /// assert!(a.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { self.v.clear() } /// Deprecated: Renamed to `get`. @@ -359,7 +359,7 @@ impl VecMap { /// assert_eq!(map.get(&1), Some(&"a")); /// assert_eq!(map.get(&2), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get(&self, key: &uint) -> Option<&V> { if *key < self.v.len() { match self.v[*key] { @@ -384,7 +384,7 @@ impl VecMap { /// assert_eq!(map.contains_key(&2), false); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains_key(&self, key: &uint) -> bool { self.get(key).is_some() } @@ -410,7 +410,7 @@ impl VecMap { /// } /// assert_eq!(map[1], "b"); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get_mut(&mut self, key: &uint) -> Option<&mut V> { if *key < self.v.len() { match *(&mut self.v[*key]) { @@ -444,7 +444,7 @@ impl VecMap { /// assert_eq!(map.insert(37, "c"), Some("b")); /// assert_eq!(map[37], "c"); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, key: uint, value: V) -> Option { let len = self.v.len(); if len <= key { @@ -472,7 +472,7 @@ impl VecMap { /// assert_eq!(map.remove(&1), Some("a")); /// assert_eq!(map.remove(&1), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, key: &uint) -> Option { if *key >= self.v.len() { return None; @@ -482,50 +482,15 @@ impl VecMap { } impl VecMap { - /// Updates a value in the map. If the key already exists in the map, - /// modifies the value with `ff` taking `oldval, newval`. - /// Otherwise, sets the value to `newval`. - /// Returns `true` if the key did not already exist in the map. - /// - /// # Examples - /// - /// ``` - /// use std::collections::VecMap; - /// - /// let mut map = VecMap::new(); - /// - /// // Key does not exist, will do a simple insert - /// assert!(map.update(1, vec![1i, 2], |mut old, new| { old.extend(new.into_iter()); old })); - /// assert_eq!(map[1], vec![1i, 2]); - /// - /// // Key exists, update the value - /// assert!(!map.update(1, vec![3i, 4], |mut old, new| { old.extend(new.into_iter()); old })); - /// assert_eq!(map[1], vec![1i, 2, 3, 4]); - /// ``` + /// Deprecated: Use the entry API when available; shouldn't matter anyway, access is cheap. + #[deprecated = "Use the entry API when available; shouldn't matter anyway, access is cheap"] + #[allow(deprecated)] pub fn update(&mut self, key: uint, newval: V, ff: F) -> bool where F: FnOnce(V, V) -> V { self.update_with_key(key, newval, move |_k, v, v1| ff(v,v1)) } - /// Updates a value in the map. If the key already exists in the map, - /// modifies the value with `ff` taking `key, oldval, newval`. - /// Otherwise, sets the value to `newval`. - /// Returns `true` if the key did not already exist in the map. - /// - /// # Examples - /// - /// ``` - /// use std::collections::VecMap; - /// - /// let mut map = VecMap::new(); - /// - /// // Key does not exist, will do a simple insert - /// assert!(map.update_with_key(7, 10, |key, old, new| (old + new) % key)); - /// assert_eq!(map[7], 10); - /// - /// // Key exists, update the value - /// assert!(!map.update_with_key(7, 20, |key, old, new| (old + new) % key)); - /// assert_eq!(map[7], 2); - /// ``` + /// Deprecated: Use the entry API when available; shouldn't matter anyway, access is cheap. + #[deprecated = "Use the entry API when available; shouldn't matter anyway, access is cheap"] pub fn update_with_key(&mut self, key: uint, val: V, ff: F) -> bool where F: FnOnce(uint, V, V) -> V { @@ -537,7 +502,6 @@ impl VecMap { } } - #[stable] impl PartialEq for VecMap { fn eq(&self, other: &VecMap) -> bool { @@ -564,6 +528,7 @@ impl Ord for VecMap { } } +#[stable] impl fmt::Show for VecMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -577,6 +542,7 @@ impl fmt::Show for VecMap { } } +#[stable] impl FromIterator<(uint, V)> for VecMap { fn from_iter>(iter: Iter) -> VecMap { let mut map = VecMap::new(); @@ -585,6 +551,7 @@ impl FromIterator<(uint, V)> for VecMap { } } +#[stable] impl Extend<(uint, V)> for VecMap { fn extend>(&mut self, mut iter: Iter) { for (k, v) in iter { @@ -593,6 +560,7 @@ impl Extend<(uint, V)> for VecMap { } } +#[stable] impl Index for VecMap { #[inline] fn index<'a>(&'a self, i: &uint) -> &'a V { @@ -600,6 +568,7 @@ impl Index for VecMap { } } +#[stable] impl IndexMut for VecMap { #[inline] fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V { @@ -609,6 +578,7 @@ impl IndexMut for VecMap { macro_rules! iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { + #[stable] impl<'a, V> Iterator<$elem> for $name<'a, V> { #[inline] fn next(&mut self) -> Option<$elem> { @@ -641,6 +611,7 @@ macro_rules! iterator { macro_rules! double_ended_iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { + #[stable] impl<'a, V> DoubleEndedIterator<$elem> for $name<'a, V> { #[inline] fn next_back(&mut self) -> Option<$elem> { @@ -666,6 +637,7 @@ macro_rules! double_ended_iterator { } /// An iterator over the key-value pairs of a map. +#[stable] pub struct Iter<'a, V:'a> { front: uint, back: uint, @@ -688,6 +660,7 @@ double_ended_iterator! { impl Iter -> (uint, &'a V), as_ref } /// An iterator over the key-value pairs of a map, with the /// values being mutable. +#[stable] pub struct IterMut<'a, V:'a> { front: uint, back: uint, @@ -698,6 +671,7 @@ iterator! { impl IterMut -> (uint, &'a mut V), as_mut } double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut } /// An iterator over the keys of a map. +#[stable] pub struct Keys<'a, V: 'a> { iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint> } @@ -712,6 +686,7 @@ impl<'a, V> Clone for Keys<'a, V> { } /// An iterator over the values of a map. +#[stable] pub struct Values<'a, V: 'a> { iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V> } @@ -726,6 +701,7 @@ impl<'a, V> Clone for Values<'a, V> { } /// A consuming iterator over the key-value pairs of a map. +#[stable] pub struct IntoIter { iter: FilterMap< (uint, Option), @@ -734,28 +710,32 @@ pub struct IntoIter { fn((uint, Option)) -> Option<(uint, V)>> } +#[stable] impl<'a, V> Iterator for Keys<'a, V> { fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, V> DoubleEndedIterator for Keys<'a, V> { fn next_back(&mut self) -> Option { self.iter.next_back() } } - +#[stable] impl<'a, V> Iterator<&'a V> for Values<'a, V> { fn next(&mut self) -> Option<(&'a V)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, V> DoubleEndedIterator<&'a V> for Values<'a, V> { fn next_back(&mut self) -> Option<(&'a V)> { self.iter.next_back() } } - +#[stable] impl Iterator<(uint, V)> for IntoIter { fn next(&mut self) -> Option<(uint, V)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl DoubleEndedIterator<(uint, V)> for IntoIter { fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() } } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 3bfe2009f8b..f6063df5434 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -296,6 +296,7 @@ fn test_resize_policy() { /// } /// ``` #[deriving(Clone)] +#[stable] pub struct HashMap { // All hashes are keyed on these values, to prevent hash collision attacks. hasher: H, @@ -508,7 +509,7 @@ impl HashMap { /// let mut map: HashMap<&str, int> = HashMap::new(); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> HashMap { let hasher = RandomSipHasher::new(); HashMap::with_hasher(hasher) @@ -523,7 +524,7 @@ impl HashMap { /// let mut map: HashMap<&str, int> = HashMap::with_capacity(10); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(capacity: uint) -> HashMap { let hasher = RandomSipHasher::new(); HashMap::with_capacity_and_hasher(capacity, hasher) @@ -546,6 +547,7 @@ impl, V, S, H: Hasher> HashMap { /// map.insert(1i, 2u); /// ``` #[inline] + #[unstable = "hasher stuff is unclear"] pub fn with_hasher(hasher: H) -> HashMap { HashMap { hasher: hasher, @@ -573,6 +575,7 @@ impl, V, S, H: Hasher> HashMap { /// map.insert(1i, 2u); /// ``` #[inline] + #[unstable = "hasher stuff is unclear"] pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashMap { let resize_policy = DefaultResizePolicy::new(); let min_cap = max(INITIAL_CAPACITY, resize_policy.min_capacity(capacity)); @@ -595,7 +598,7 @@ impl, V, S, H: Hasher> HashMap { /// assert!(map.capacity() >= 100); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.resize_policy.usable_capacity(self.table.capacity()) } @@ -615,7 +618,7 @@ impl, V, S, H: Hasher> HashMap { /// let mut map: HashMap<&str, int> = HashMap::new(); /// map.reserve(10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve(&mut self, additional: uint) { let new_size = self.len().checked_add(additional).expect("capacity overflow"); let min_cap = self.resize_policy.min_capacity(new_size); @@ -727,7 +730,7 @@ impl, V, S, H: Hasher> HashMap { /// map.shrink_to_fit(); /// assert!(map.capacity() >= 2); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn shrink_to_fit(&mut self) { let min_capacity = self.resize_policy.min_capacity(self.len()); let min_capacity = max(min_capacity.next_power_of_two(), INITIAL_CAPACITY); @@ -845,7 +848,7 @@ impl, V, S, H: Hasher> HashMap { /// println!("{}", key); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } let first: fn((&'a K,&'a V)) -> &'a K = first; // coerce to fn ptr @@ -870,7 +873,7 @@ impl, V, S, H: Hasher> HashMap { /// println!("{}", key); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } let second: fn((&'a K,&'a V)) -> &'a V = second; // coerce to fn ptr @@ -895,7 +898,7 @@ impl, V, S, H: Hasher> HashMap { /// println!("key: {} val: {}", key, val); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter(&self) -> Iter { Iter { inner: self.table.iter() } } @@ -923,7 +926,7 @@ impl, V, S, H: Hasher> HashMap { /// println!("key: {} val: {}", key, val); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn iter_mut(&mut self) -> IterMut { IterMut { inner: self.table.iter_mut() } } @@ -945,7 +948,7 @@ impl, V, S, H: Hasher> HashMap { /// // Not possible with .iter() /// let vec: Vec<(&str, int)> = map.into_iter().collect(); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } let last_two: fn((SafeHash, K, V)) -> (K, V) = last_two; @@ -976,7 +979,7 @@ impl, V, S, H: Hasher> HashMap { /// a.insert(1u, "a"); /// assert_eq!(a.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.table.size() } /// Return true if the map contains no elements. @@ -992,7 +995,7 @@ impl, V, S, H: Hasher> HashMap { /// assert!(!a.is_empty()); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.len() == 0 } /// Clears the map, returning all key-value pairs as an iterator. Keeps the @@ -1038,7 +1041,7 @@ impl, V, S, H: Hasher> HashMap { /// a.clear(); /// assert!(a.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] #[inline] pub fn clear(&mut self) { self.drain(); @@ -1066,7 +1069,7 @@ impl, V, S, H: Hasher> HashMap { /// assert_eq!(map.get(&1), Some(&"a")); /// assert_eq!(map.get(&2), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get(&self, k: &Q) -> Option<&V> where Q: Hash + Eq + BorrowFrom { @@ -1089,7 +1092,7 @@ impl, V, S, H: Hasher> HashMap { /// assert_eq!(map.contains_key(&1), true); /// assert_eq!(map.contains_key(&2), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains_key(&self, k: &Q) -> bool where Q: Hash + Eq + BorrowFrom { @@ -1121,7 +1124,7 @@ impl, V, S, H: Hasher> HashMap { /// } /// assert_eq!(map[1], "b"); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> where Q: Hash + Eq + BorrowFrom { @@ -1150,7 +1153,7 @@ impl, V, S, H: Hasher> HashMap { /// assert_eq!(map.insert(37, "c"), Some("b")); /// assert_eq!(map[37], "c"); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, k: K, v: V) -> Option { let hash = self.make_hash(&k); self.reserve(1); @@ -1185,7 +1188,7 @@ impl, V, S, H: Hasher> HashMap { /// assert_eq!(map.remove(&1), Some("a")); /// assert_eq!(map.remove(&1), None); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, k: &Q) -> Option where Q: Hash + Eq + BorrowFrom { @@ -1275,6 +1278,7 @@ impl, V: PartialEq, S, H: Hasher> PartialEq for HashMap, V: Eq, S, H: Hasher> Eq for HashMap {} +#[stable] impl + Show, V: Show, S, H: Hasher> Show for HashMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -1296,6 +1300,7 @@ impl, V, S, H: Hasher + Default> Default for HashMap } } +#[stable] impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap where Q: BorrowFrom + Hash + Eq { @@ -1305,6 +1310,7 @@ impl + Eq, Sized? Q, V, S, H: Hasher> Index for HashMap + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap where Q: BorrowFrom + Hash + Eq { @@ -1315,6 +1321,7 @@ impl + Eq, Sized? Q, V, S, H: Hasher> IndexMut for HashMap { inner: table::Iter<'a, K, V> } @@ -1329,11 +1336,13 @@ impl<'a, K, V> Clone for Iter<'a, K, V> { } /// HashMap mutable values iterator +#[stable] pub struct IterMut<'a, K: 'a, V: 'a> { inner: table::IterMut<'a, K, V> } /// HashMap move iterator +#[stable] pub struct IntoIter { inner: iter::Map< (SafeHash, K, V), @@ -1344,6 +1353,7 @@ pub struct IntoIter { } /// HashMap keys iterator +#[stable] pub struct Keys<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> } @@ -1358,6 +1368,7 @@ impl<'a, K, V> Clone for Keys<'a, K, V> { } /// HashMap values iterator +#[stable] pub struct Values<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> } @@ -1372,6 +1383,7 @@ impl<'a, K, V> Clone for Values<'a, K, V> { } /// HashMap drain iterator +#[unstable = "matches collection reform specification, waiting for dust to settle"] pub struct Drain<'a, K: 'a, V: 'a> { inner: iter::Map< (SafeHash, K, V), @@ -1410,31 +1422,37 @@ enum VacantEntryState { NoElem(EmptyBucket), } +#[stable] impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { #[inline] fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { #[inline] fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl Iterator<(K, V)> for IntoIter { #[inline] fn next(&mut self) -> Option<(K, V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { #[inline] fn next(&mut self) -> Option<(&'a K)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K, V> Iterator<&'a V> for Values<'a, K, V> { #[inline] fn next(&mut self) -> Option<(&'a V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } +#[stable] impl<'a, K: 'a, V: 'a> Iterator<(K, V)> for Drain<'a, K, V> { #[inline] fn next(&mut self) -> Option<(K, V)> { @@ -1491,6 +1509,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> { } } +#[stable] impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for HashMap { fn from_iter>(iter: T) -> HashMap { let lower = iter.size_hint().0; @@ -1500,6 +1519,7 @@ impl, V, S, H: Hasher + Default> FromIterator<(K, V)> for Has } } +#[stable] impl, V, S, H: Hasher + Default> Extend<(K, V)> for HashMap { fn extend>(&mut self, mut iter: T) { for (k, v) in iter { diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 93f6895f688..74fb63a7a9e 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -90,6 +90,7 @@ use super::map::{mod, HashMap, Keys, INITIAL_CAPACITY}; /// } /// ``` #[deriving(Clone)] +#[stable] pub struct HashSet { map: HashMap } @@ -104,7 +105,7 @@ impl HashSet { /// let mut set: HashSet = HashSet::new(); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn new() -> HashSet { HashSet::with_capacity(INITIAL_CAPACITY) } @@ -119,7 +120,7 @@ impl HashSet { /// let mut set: HashSet = HashSet::with_capacity(10); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn with_capacity(capacity: uint) -> HashSet { HashSet { map: HashMap::with_capacity(capacity) } } @@ -142,6 +143,7 @@ impl, S, H: Hasher> HashSet { /// set.insert(2u); /// ``` #[inline] + #[unstable = "hasher stuff is unclear"] pub fn with_hasher(hasher: H) -> HashSet { HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } @@ -165,6 +167,7 @@ impl, S, H: Hasher> HashSet { /// set.insert(1i); /// ``` #[inline] + #[unstable = "hasher stuff is unclear"] pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet { HashSet { map: HashMap::with_capacity_and_hasher(capacity, hasher) } } @@ -179,7 +182,7 @@ impl, S, H: Hasher> HashSet { /// assert!(set.capacity() >= 100); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn capacity(&self) -> uint { self.map.capacity() } @@ -199,7 +202,7 @@ impl, S, H: Hasher> HashSet { /// let mut set: HashSet = HashSet::new(); /// set.reserve(10); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn reserve(&mut self, additional: uint) { self.map.reserve(additional) } @@ -220,7 +223,7 @@ impl, S, H: Hasher> HashSet { /// set.shrink_to_fit(); /// assert!(set.capacity() >= 2); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn shrink_to_fit(&mut self) { self.map.shrink_to_fit() } @@ -248,8 +251,8 @@ impl, S, H: Hasher> HashSet { /// println!("{}", x); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Iter<'a, T> { + #[stable] + pub fn iter(&self) -> Iter { Iter { iter: self.map.keys() } } @@ -273,7 +276,7 @@ impl, S, H: Hasher> HashSet { /// println!("{}", x); /// } /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn into_iter(self) -> IntoIter { fn first((a, _): (A, B)) -> A { a } let first: fn((T, ())) -> T = first; @@ -303,7 +306,7 @@ impl, S, H: Hasher> HashSet { /// let diff: HashSet = b.difference(&a).map(|&x| x).collect(); /// assert_eq!(diff, [4i].iter().map(|&x| x).collect()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn difference<'a>(&'a self, other: &'a HashSet) -> Difference<'a, T, H> { Difference { iter: self.iter(), @@ -331,7 +334,7 @@ impl, S, H: Hasher> HashSet { /// assert_eq!(diff1, diff2); /// assert_eq!(diff1, [1i, 4].iter().map(|&x| x).collect()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet) -> SymmetricDifference<'a, T, H> { SymmetricDifference { iter: self.difference(other).chain(other.difference(self)) } @@ -354,7 +357,7 @@ impl, S, H: Hasher> HashSet { /// let diff: HashSet = a.intersection(&b).map(|&x| x).collect(); /// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn intersection<'a>(&'a self, other: &'a HashSet) -> Intersection<'a, T, H> { Intersection { iter: self.iter(), @@ -379,7 +382,7 @@ impl, S, H: Hasher> HashSet { /// let diff: HashSet = a.union(&b).map(|&x| x).collect(); /// assert_eq!(diff, [1i, 2, 3, 4].iter().map(|&x| x).collect()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn union<'a>(&'a self, other: &'a HashSet) -> Union<'a, T, H> { Union { iter: self.iter().chain(other.difference(self)) } } @@ -396,7 +399,7 @@ impl, S, H: Hasher> HashSet { /// v.insert(1u); /// assert_eq!(v.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn len(&self) -> uint { self.map.len() } /// Returns true if the set contains no elements @@ -411,7 +414,7 @@ impl, S, H: Hasher> HashSet { /// v.insert(1u); /// assert!(!v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_empty(&self) -> bool { self.map.len() == 0 } /// Clears the set, returning all elements in an iterator. @@ -436,7 +439,7 @@ impl, S, H: Hasher> HashSet { /// v.clear(); /// assert!(v.is_empty()); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn clear(&mut self) { self.map.clear() } /// Returns `true` if the set contains a value. @@ -454,7 +457,7 @@ impl, S, H: Hasher> HashSet { /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn contains(&self, value: &Q) -> bool where Q: BorrowFrom + Hash + Eq { @@ -478,7 +481,7 @@ impl, S, H: Hasher> HashSet { /// b.insert(1); /// assert_eq!(a.is_disjoint(&b), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_disjoint(&self, other: &HashSet) -> bool { self.iter().all(|v| !other.contains(v)) } @@ -499,7 +502,7 @@ impl, S, H: Hasher> HashSet { /// set.insert(4); /// assert_eq!(set.is_subset(&sup), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_subset(&self, other: &HashSet) -> bool { self.iter().all(|v| other.contains(v)) } @@ -524,7 +527,7 @@ impl, S, H: Hasher> HashSet { /// assert_eq!(set.is_superset(&sub), true); /// ``` #[inline] - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn is_superset(&self, other: &HashSet) -> bool { other.is_subset(self) } @@ -543,7 +546,7 @@ impl, S, H: Hasher> HashSet { /// assert_eq!(set.insert(2), false); /// assert_eq!(set.len(), 1); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()).is_none() } /// Removes a value from the set. Returns `true` if the value was @@ -564,7 +567,7 @@ impl, S, H: Hasher> HashSet { /// assert_eq!(set.remove(&2), true); /// assert_eq!(set.remove(&2), false); /// ``` - #[unstable = "matches collection reform specification, waiting for dust to settle"] + #[stable] pub fn remove(&mut self, value: &Q) -> bool where Q: BorrowFrom + Hash + Eq { @@ -584,6 +587,7 @@ impl, S, H: Hasher> PartialEq for HashSet { #[stable] impl, S, H: Hasher> Eq for HashSet {} +#[stable] impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -597,6 +601,7 @@ impl + fmt::Show, S, H: Hasher> fmt::Show for HashSet { } } +#[stable] impl, S, H: Hasher + Default> FromIterator for HashSet { fn from_iter>(iter: I) -> HashSet { let lower = iter.size_hint().0; @@ -606,6 +611,7 @@ impl, S, H: Hasher + Default> FromIterator for HashSet, S, H: Hasher + Default> Extend for HashSet { fn extend>(&mut self, mut iter: I) { for k in iter { @@ -622,7 +628,7 @@ impl, S, H: Hasher + Default> Default for HashSet { } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> BitOr<&'b HashSet, HashSet> for &'a HashSet { /// Returns the union of `self` and `rhs` as a new `HashSet`. @@ -650,7 +656,7 @@ BitOr<&'b HashSet, HashSet> for &'a HashSet { } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> BitAnd<&'b HashSet, HashSet> for &'a HashSet { /// Returns the intersection of `self` and `rhs` as a new `HashSet`. @@ -678,7 +684,7 @@ BitAnd<&'b HashSet, HashSet> for &'a HashSet { } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> BitXor<&'b HashSet, HashSet> for &'a HashSet { /// Returns the symmetric difference of `self` and `rhs` as a new `HashSet`. @@ -706,7 +712,7 @@ BitXor<&'b HashSet, HashSet> for &'a HashSet { } } -#[unstable = "matches collection reform specification, waiting for dust to settle"] +#[stable] impl<'a, 'b, T: Eq + Hash + Clone, S, H: Hasher + Default> Sub<&'b HashSet, HashSet> for &'a HashSet { /// Returns the difference of `self` and `rhs` as a new `HashSet`. @@ -735,21 +741,25 @@ Sub<&'b HashSet, HashSet> for &'a HashSet { } /// HashSet iterator +#[stable] pub struct Iter<'a, K: 'a> { iter: Keys<'a, K, ()> } /// HashSet move iterator +#[stable] pub struct IntoIter { iter: Map<(K, ()), K, map::IntoIter, fn((K, ())) -> K> } /// HashSet drain iterator +#[stable] pub struct Drain<'a, K: 'a> { iter: Map<(K, ()), K, map::Drain<'a, K, ()>, fn((K, ())) -> K>, } /// Intersection iterator +#[stable] pub struct Intersection<'a, T: 'a, H: 'a> { // iterator of the first set iter: Iter<'a, T>, @@ -758,6 +768,7 @@ pub struct Intersection<'a, T: 'a, H: 'a> { } /// Difference iterator +#[stable] pub struct Difference<'a, T: 'a, H: 'a> { // iterator of the first set iter: Iter<'a, T>, @@ -766,30 +777,36 @@ pub struct Difference<'a, T: 'a, H: 'a> { } /// Symmetric difference iterator. +#[stable] pub struct SymmetricDifference<'a, T: 'a, H: 'a> { iter: Chain, Difference<'a, T, H>> } /// Set union iterator. +#[stable] pub struct Union<'a, T: 'a, H: 'a> { iter: Chain, Difference<'a, T, H>> } +#[stable] impl<'a, K> Iterator<&'a K> for Iter<'a, K> { fn next(&mut self) -> Option<&'a K> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl Iterator for IntoIter { fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, K: 'a> Iterator for Drain<'a, K> { fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, T, S, H> Iterator<&'a T> for Intersection<'a, T, H> where T: Eq + Hash, H: Hasher { @@ -810,6 +827,7 @@ impl<'a, T, S, H> Iterator<&'a T> for Intersection<'a, T, H> } } +#[stable] impl<'a, T, S, H> Iterator<&'a T> for Difference<'a, T, H> where T: Eq + Hash, H: Hasher { @@ -830,6 +848,7 @@ impl<'a, T, S, H> Iterator<&'a T> for Difference<'a, T, H> } } +#[stable] impl<'a, T, S, H> Iterator<&'a T> for SymmetricDifference<'a, T, H> where T: Eq + Hash, H: Hasher { @@ -837,6 +856,7 @@ impl<'a, T, S, H> Iterator<&'a T> for SymmetricDifference<'a, T, H> fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } +#[stable] impl<'a, T, S, H> Iterator<&'a T> for Union<'a, T, H> where T: Eq + Hash, H: Hasher {