Skip to content

Commit d444d0c

Browse files
committed
collections: Split the collections feature
This commit also deprecates the `as_string` and `as_slice` free functions in the `string` and `vec` modules.
1 parent c44f539 commit d444d0c

File tree

30 files changed

+197
-155
lines changed

30 files changed

+197
-155
lines changed

src/libcollections/binary_heap.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
//! A priority queue implemented with a binary heap.
1212
//!
13-
//! Insertion and popping the largest element have `O(log n)` time complexity. Checking the largest
14-
//! element is `O(1)`. Converting a vector to a binary heap can be done in-place, and has `O(n)`
15-
//! complexity. A binary heap can also be converted to a sorted vector in-place, allowing it to
16-
//! be used for an `O(n log n)` in-place heapsort.
13+
//! Insertion and popping the largest element have `O(log n)` time complexity.
14+
//! Checking the largest element is `O(1)`. Converting a vector to a binary heap
15+
//! can be done in-place, and has `O(n)` complexity. A binary heap can also be
16+
//! converted to a sorted vector in-place, allowing it to be used for an `O(n
17+
//! log n)` in-place heapsort.
1718
//!
1819
//! # Examples
1920
//!
@@ -539,8 +540,9 @@ impl<T: Ord> BinaryHeap<T> {
539540
///
540541
/// The elements are removed in arbitrary order.
541542
#[inline]
542-
#[unstable(feature = "collections",
543-
reason = "matches collection reform specification, waiting for dust to settle")]
543+
#[unstable(feature = "drain",
544+
reason = "matches collection reform specification, \
545+
waiting for dust to settle")]
544546
pub fn drain(&mut self) -> Drain<T> {
545547
Drain { iter: self.data.drain(..) }
546548
}
@@ -678,7 +680,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
678680
impl<T> ExactSizeIterator for IntoIter<T> {}
679681

680682
/// An iterator that drains a `BinaryHeap`.
681-
#[unstable(feature = "collections", reason = "recent addition")]
683+
#[unstable(feature = "drain", reason = "recent addition")]
682684
pub struct Drain<'a, T: 'a> {
683685
iter: vec::Drain<'a, T>,
684686
}

src/libcollections/bit.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ const FALSE: &'static bool = &false;
156156
/// println!("{:?}", bv);
157157
/// println!("total bits set to true: {}", bv.iter().filter(|x| *x).count());
158158
/// ```
159-
#[unstable(feature = "collections",
160-
reason = "RFC 509")]
159+
#[unstable(feature = "bitvec", reason = "RFC 509")]
161160
pub struct BitVec {
162161
/// Internal representation of the bit vector
163162
storage: Vec<u32>,
@@ -181,14 +180,16 @@ impl Index<usize> for BitVec {
181180

182181
/// Computes how many blocks are needed to store that many bits
183182
fn blocks_for_bits(bits: usize) -> usize {
184-
// If we want 17 bits, dividing by 32 will produce 0. So we add 1 to make sure we
185-
// reserve enough. But if we want exactly a multiple of 32, this will actually allocate
186-
// one too many. So we need to check if that's the case. We can do that by computing if
187-
// bitwise AND by `32 - 1` is 0. But LLVM should be able to optimize the semantically
188-
// superior modulo operator on a power of two to this.
183+
// If we want 17 bits, dividing by 32 will produce 0. So we add 1 to make
184+
// sure we reserve enough. But if we want exactly a multiple of 32, this
185+
// will actually allocate one too many. So we need to check if that's the
186+
// case. We can do that by computing if bitwise AND by `32 - 1` is 0. But
187+
// LLVM should be able to optimize the semantically superior modulo operator
188+
// on a power of two to this.
189189
//
190190
// Note that we can technically avoid this branch with the expression
191-
// `(nbits + u32::BITS - 1) / 32::BITS`, but if nbits is almost usize::MAX this will overflow.
191+
// `(nbits + u32::BITS - 1) / 32::BITS`, but if nbits is almost usize::MAX
192+
// this will overflow.
192193
if bits % u32::BITS == 0 {
193194
bits / u32::BITS
194195
} else {
@@ -202,6 +203,7 @@ fn mask_for_bits(bits: usize) -> u32 {
202203
!0 >> (u32::BITS - bits % u32::BITS) % u32::BITS
203204
}
204205

206+
#[unstable(feature = "bitvec", reason = "RFC 509")]
205207
impl BitVec {
206208
/// Applies the given operation to the blocks of self and other, and sets
207209
/// self to be the result. This relies on the caller not to corrupt the
@@ -407,8 +409,6 @@ impl BitVec {
407409
/// assert_eq!(bv[3], true);
408410
/// ```
409411
#[inline]
410-
#[unstable(feature = "collections",
411-
reason = "panic semantics are likely to change in the future")]
412412
pub fn set(&mut self, i: usize, x: bool) {
413413
assert!(i < self.nbits);
414414
let w = i / u32::BITS;
@@ -608,7 +608,7 @@ impl BitVec {
608608
/// # Examples
609609
///
610610
/// ```
611-
/// # #![feature(collections, bit_vec_append_split_off)]
611+
/// # #![feature(bitvec, append)]
612612
/// use std::collections::BitVec;
613613
///
614614
/// let mut a = BitVec::from_bytes(&[0b10000000]);
@@ -621,7 +621,7 @@ impl BitVec {
621621
/// assert!(a.eq_vec(&[true, false, false, false, false, false, false, false,
622622
/// false, true, true, false, false, false, false, true]));
623623
/// ```
624-
#[unstable(feature = "bit_vec_append_split_off",
624+
#[unstable(feature = "append",
625625
reason = "recently added as part of collections reform 2")]
626626
pub fn append(&mut self, other: &mut Self) {
627627
let b = self.len() % u32::BITS;
@@ -651,7 +651,7 @@ impl BitVec {
651651
/// # Examples
652652
///
653653
/// ```
654-
/// # #![feature(collections, bit_vec_append_split_off)]
654+
/// # #![feature(bitvec, split_off)]
655655
/// use std::collections::BitVec;
656656
/// let mut a = BitVec::new();
657657
/// a.push(true);
@@ -666,7 +666,7 @@ impl BitVec {
666666
/// assert!(a.eq_vec(&[true, false]));
667667
/// assert!(b.eq_vec(&[false, true]));
668668
/// ```
669-
#[unstable(feature = "bit_vec_append_split_off",
669+
#[unstable(feature = "split_off",
670670
reason = "recently added as part of collections reform 2")]
671671
pub fn split_off(&mut self, at: usize) -> Self {
672672
assert!(at <= self.len(), "`at` out of bounds");
@@ -1254,8 +1254,7 @@ impl<'a> IntoIterator for &'a BitVec {
12541254
/// assert!(bv[3]);
12551255
/// ```
12561256
#[derive(Clone)]
1257-
#[unstable(feature = "collections",
1258-
reason = "RFC 509")]
1257+
#[unstable(feature = "bitset", reason = "RFC 509")]
12591258
pub struct BitSet {
12601259
bit_vec: BitVec,
12611260
}
@@ -1322,6 +1321,7 @@ impl cmp::PartialEq for BitSet {
13221321
#[stable(feature = "rust1", since = "1.0.0")]
13231322
impl cmp::Eq for BitSet {}
13241323

1324+
#[unstable(feature = "bitset", reason = "RFC 509")]
13251325
impl BitSet {
13261326
/// Creates a new empty `BitSet`.
13271327
///
@@ -1808,7 +1808,7 @@ impl BitSet {
18081808
/// # Examples
18091809
///
18101810
/// ```
1811-
/// # #![feature(collections, bit_set_append_split_off)]
1811+
/// # #![feature(collections, append)]
18121812
/// use std::collections::{BitVec, BitSet};
18131813
///
18141814
/// let mut a = BitSet::new();
@@ -1826,7 +1826,7 @@ impl BitSet {
18261826
/// assert_eq!(b.len(), 0);
18271827
/// assert_eq!(a, BitSet::from_bit_vec(BitVec::from_bytes(&[0b01110010])));
18281828
/// ```
1829-
#[unstable(feature = "bit_set_append_split_off",
1829+
#[unstable(feature = "append",
18301830
reason = "recently added as part of collections reform 2")]
18311831
pub fn append(&mut self, other: &mut Self) {
18321832
self.union_with(other);
@@ -1839,7 +1839,7 @@ impl BitSet {
18391839
/// # Examples
18401840
///
18411841
/// ```
1842-
/// # #![feature(collections, bit_set_append_split_off)]
1842+
/// # #![feature(bitset, split_off)]
18431843
/// use std::collections::{BitSet, BitVec};
18441844
/// let mut a = BitSet::new();
18451845
/// a.insert(2);
@@ -1854,7 +1854,7 @@ impl BitSet {
18541854
/// assert_eq!(a, BitSet::from_bit_vec(BitVec::from_bytes(&[0b01100000])));
18551855
/// assert_eq!(b, BitSet::from_bit_vec(BitVec::from_bytes(&[0b00010010])));
18561856
/// ```
1857-
#[unstable(feature = "bit_set_append_split_off",
1857+
#[unstable(feature = "split_off",
18581858
reason = "recently added as part of collections reform 2")]
18591859
pub fn split_off(&mut self, at: usize) -> Self {
18601860
let mut other = BitSet::new();

src/libcollections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
15201520
/// }
15211521
/// assert_eq!(Some((&5, &"b")), map.range(Included(&4), Unbounded).next());
15221522
/// ```
1523-
#[unstable(feature = "collections",
1523+
#[unstable(feature = "btree_range",
15241524
reason = "matches collection reform specification, waiting for dust to settle")]
15251525
pub fn range<'a>(&'a self, min: Bound<&K>, max: Bound<&K>) -> Range<'a, K, V> {
15261526
range_impl!(&self.root, min, max, as_slices_internal, iter, Range, edges, [])
@@ -1548,7 +1548,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
15481548
/// println!("{} => {}", name, balance);
15491549
/// }
15501550
/// ```
1551-
#[unstable(feature = "collections",
1551+
#[unstable(feature = "btree_range",
15521552
reason = "matches collection reform specification, waiting for dust to settle")]
15531553
pub fn range_mut<'a>(&'a mut self, min: Bound<&K>, max: Bound<&K>) -> RangeMut<'a, K, V> {
15541554
range_impl!(&mut self.root, min, max, as_slices_internal_mut, iter_mut, RangeMut,

src/libcollections/btree/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<T: Ord> BTreeSet<T> {
102102
/// Makes a new BTreeSet with the given B.
103103
///
104104
/// B cannot be less than 2.
105-
#[unstable(feature = "collections",
105+
#[unstable(feature = "btree_b",
106106
reason = "probably want this to be on the type, eventually")]
107107
pub fn with_b(b: usize) -> BTreeSet<T> {
108108
BTreeSet { map: BTreeMap::with_b(b) }
@@ -154,7 +154,7 @@ impl<T: Ord> BTreeSet<T> {
154154
/// }
155155
/// assert_eq!(Some(&5), set.range(Included(&4), Unbounded).next());
156156
/// ```
157-
#[unstable(feature = "collections",
157+
#[unstable(feature = "btree_range",
158158
reason = "matches collection reform specification, waiting for dust to settle")]
159159
pub fn range<'a>(&'a self, min: Bound<&T>, max: Bound<&T>) -> Range<'a, T> {
160160
fn first<A, B>((a, _): (A, B)) -> A { a }

src/libcollections/enum_set.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@
1313
//! This module defines a container which uses an efficient bit mask
1414
//! representation to hold C-like enum variants.
1515
16+
#![unstable(feature = "enumset",
17+
reason = "matches collection reform specification, \
18+
waiting for dust to settle")]
19+
1620
use core::prelude::*;
1721
use core::marker;
1822
use core::fmt;
1923
use core::iter::{FromIterator};
2024
use core::ops::{Sub, BitOr, BitAnd, BitXor};
2125

22-
// FIXME(contentions): implement union family of methods? (general design may be wrong here)
26+
// FIXME(contentions): implement union family of methods? (general design may be
27+
// wrong here)
2328

24-
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
2529
/// A specialized set implementation to use enum types.
2630
///
27-
/// It is a logic error for an item to be modified in such a way that the transformation of the
28-
/// item to or from a `usize`, as determined by the `CLike` trait, changes while the item is in the
29-
/// set. This is normally only possible through `Cell`, `RefCell`, global state, I/O, or unsafe
30-
/// code.
31+
/// It is a logic error for an item to be modified in such a way that the
32+
/// transformation of the item to or from a `usize`, as determined by the
33+
/// `CLike` trait, changes while the item is in the set. This is normally only
34+
/// possible through `Cell`, `RefCell`, global state, I/O, or unsafe code.
35+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
3136
pub struct EnumSet<E> {
3237
// We must maintain the invariant that no bits are set
3338
// for which no variant exists
@@ -93,22 +98,16 @@ fn bit<E:CLike>(e: &E) -> usize {
9398

9499
impl<E:CLike> EnumSet<E> {
95100
/// Returns an empty `EnumSet`.
96-
#[unstable(feature = "collections",
97-
reason = "matches collection reform specification, waiting for dust to settle")]
98101
pub fn new() -> EnumSet<E> {
99102
EnumSet {bits: 0, marker: marker::PhantomData}
100103
}
101104

102105
/// Returns the number of elements in the given `EnumSet`.
103-
#[unstable(feature = "collections",
104-
reason = "matches collection reform specification, waiting for dust to settle")]
105106
pub fn len(&self) -> usize {
106107
self.bits.count_ones() as usize
107108
}
108109

109110
/// Returns true if the `EnumSet` is empty.
110-
#[unstable(feature = "collections",
111-
reason = "matches collection reform specification, waiting for dust to settle")]
112111
pub fn is_empty(&self) -> bool {
113112
self.bits == 0
114113
}
@@ -118,22 +117,16 @@ impl<E:CLike> EnumSet<E> {
118117
}
119118

120119
/// Returns `false` if the `EnumSet` contains any enum of the given `EnumSet`.
121-
#[unstable(feature = "collections",
122-
reason = "matches collection reform specification, waiting for dust to settle")]
123120
pub fn is_disjoint(&self, other: &EnumSet<E>) -> bool {
124121
(self.bits & other.bits) == 0
125122
}
126123

127124
/// Returns `true` if a given `EnumSet` is included in this `EnumSet`.
128-
#[unstable(feature = "collections",
129-
reason = "matches collection reform specification, waiting for dust to settle")]
130125
pub fn is_superset(&self, other: &EnumSet<E>) -> bool {
131126
(self.bits & other.bits) == other.bits
132127
}
133128

134129
/// Returns `true` if this `EnumSet` is included in the given `EnumSet`.
135-
#[unstable(feature = "collections",
136-
reason = "matches collection reform specification, waiting for dust to settle")]
137130
pub fn is_subset(&self, other: &EnumSet<E>) -> bool {
138131
other.is_superset(self)
139132
}
@@ -151,33 +144,25 @@ impl<E:CLike> EnumSet<E> {
151144
}
152145

153146
/// Adds an enum to the `EnumSet`, and returns `true` if it wasn't there before
154-
#[unstable(feature = "collections",
155-
reason = "matches collection reform specification, waiting for dust to settle")]
156147
pub fn insert(&mut self, e: E) -> bool {
157148
let result = !self.contains(&e);
158149
self.bits |= bit(&e);
159150
result
160151
}
161152

162153
/// Removes an enum from the EnumSet
163-
#[unstable(feature = "collections",
164-
reason = "matches collection reform specification, waiting for dust to settle")]
165154
pub fn remove(&mut self, e: &E) -> bool {
166155
let result = self.contains(e);
167156
self.bits &= !bit(e);
168157
result
169158
}
170159

171160
/// Returns `true` if an `EnumSet` contains a given enum.
172-
#[unstable(feature = "collections",
173-
reason = "matches collection reform specification, waiting for dust to settle")]
174161
pub fn contains(&self, e: &E) -> bool {
175162
(self.bits & bit(e)) != 0
176163
}
177164

178165
/// Returns an iterator over an `EnumSet`.
179-
#[unstable(feature = "collections",
180-
reason = "matches collection reform specification, waiting for dust to settle")]
181166
pub fn iter(&self) -> Iter<E> {
182167
Iter::new(self.bits)
183168
}

src/libcollections/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010

1111
//! Collection types.
1212
//!
13-
//! See [std::collections](../std/collections) for a detailed discussion of collections in Rust.
13+
//! See [std::collections](../std/collections) for a detailed discussion of
14+
//! collections in Rust.
1415
1516
// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
1617
#![cfg_attr(stage0, feature(custom_attribute))]
1718
#![crate_name = "collections"]
18-
#![unstable(feature = "collections")]
1919
#![staged_api]
2020
#![crate_type = "rlib"]
21+
#![unstable(feature = "collections",
22+
reason = "library is unlikely to be stabilized with the current \
23+
layout and name, use std::collections instead")]
2124
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2225
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
2326
html_root_url = "http://doc.rust-lang.org/nightly/",
@@ -107,14 +110,12 @@ pub mod vec;
107110
pub mod vec_deque;
108111
pub mod vec_map;
109112

110-
#[unstable(feature = "collections",
111-
reason = "RFC 509")]
113+
#[unstable(feature = "bitvec", reason = "RFC 509")]
112114
pub mod bit_vec {
113115
pub use bit::{BitVec, Iter};
114116
}
115117

116-
#[unstable(feature = "collections",
117-
reason = "RFC 509")]
118+
#[unstable(feature = "bitset", reason = "RFC 509")]
118119
pub mod bit_set {
119120
pub use bit::{BitSet, Union, Intersection, Difference, SymmetricDifference};
120121
pub use bit::SetIter as Iter;
@@ -133,6 +134,7 @@ pub mod btree_set {
133134

134135
// FIXME(#14344) this shouldn't be necessary
135136
#[doc(hidden)]
137+
#[unstable(feature = "issue_14344_fixme")]
136138
pub fn fixme_14344_be_sure_to_link_to_collections() {}
137139

138140
#[cfg(not(test))]
@@ -141,6 +143,7 @@ mod std {
141143
}
142144

143145
/// An endpoint of a range of keys.
146+
#[unstable(feature = "collections_bound")]
144147
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
145148
pub enum Bound<T> {
146149
/// An inclusive bound.

src/libcollections/linked_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'a, A> IterMut<'a, A> {
801801
/// }
802802
/// ```
803803
#[inline]
804-
#[unstable(feature = "collections",
804+
#[unstable(feature = "linked_list_extras",
805805
reason = "this is probably better handled by a cursor type -- we'll see")]
806806
pub fn insert_next(&mut self, elt: A) {
807807
self.insert_next_node(box Node::new(elt))
@@ -824,7 +824,7 @@ impl<'a, A> IterMut<'a, A> {
824824
/// assert_eq!(it.next().unwrap(), &2);
825825
/// ```
826826
#[inline]
827-
#[unstable(feature = "collections",
827+
#[unstable(feature = "linked_list_extras",
828828
reason = "this is probably better handled by a cursor type -- we'll see")]
829829
pub fn peek_next(&mut self) -> Option<&mut A> {
830830
if self.nelem == 0 {

0 commit comments

Comments
 (0)