diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index c7cbb5a1c299e..dc69c5993c1af 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -131,12 +131,12 @@ pub enum Entry<'a, K:'a, V:'a> { /// A vacant Entry. pub struct VacantEntry<'a, K:'a, V:'a> { key: K, - stack: stack::SearchStack<'a, K, V, node::Edge, node::Leaf>, + stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>, } /// An occupied Entry. pub struct OccupiedEntry<'a, K:'a, V:'a> { - stack: stack::SearchStack<'a, K, V, node::KV, node::LeafOrInternal>, + stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>, } impl BTreeMap { @@ -496,7 +496,8 @@ mod stack { use core::kinds::marker; use core::mem; use super::BTreeMap; - use super::super::node::{mod, Node, Fit, Split, KV, Edge, Internal, Leaf, LeafOrInternal}; + use super::super::node::{mod, Node, Fit, Split, Internal, Leaf}; + use super::super::node::handle; use vec::Vec; /// A generic mutable reference, identical to `&mut` except for the fact that its lifetime @@ -520,7 +521,7 @@ mod stack { } } - type StackItem = node::Handle<*mut Node, Edge, Internal>; + type StackItem = node::Handle<*mut Node, handle::Edge, handle::Internal>; type Stack = Vec>; /// A `PartialSearchStack` handles the construction of a search stack. @@ -595,7 +596,9 @@ mod stack { /// Pushes the requested child of the stack's current top on top of the stack. If the child /// exists, then a new PartialSearchStack is yielded. Otherwise, a VacantSearchStack is /// yielded. - pub fn push(mut self, mut edge: node::Handle>, Edge, Internal>) + pub fn push(mut self, mut edge: node::Handle>, + handle::Edge, + handle::Internal>) -> PartialSearchStack<'a, K, V> { self.stack.push(edge.as_raw()); PartialSearchStack { @@ -617,7 +620,7 @@ mod stack { } } - impl<'a, K, V, NodeType> SearchStack<'a, K, V, KV, NodeType> { + impl<'a, K, V, NodeType> SearchStack<'a, K, V, handle::KV, NodeType> { /// Gets a reference to the value the stack points to. pub fn peek(&self) -> &V { unsafe { self.top.from_raw().into_kv().1 } @@ -640,7 +643,7 @@ mod stack { } } - impl<'a, K, V> SearchStack<'a, K, V, KV, Leaf> { + impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::Leaf> { /// Removes the key and value in the top element of the stack, then handles underflows as /// described in BTree's pop function. fn remove_leaf(mut self) -> V { @@ -686,7 +689,7 @@ mod stack { } } - impl<'a, K, V> SearchStack<'a, K, V, KV, LeafOrInternal> { + impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::LeafOrInternal> { /// Removes the key and value in the top element of the stack, then handles underflows as /// described in BTree's pop function. pub fn remove(self) -> V { @@ -703,7 +706,7 @@ mod stack { /// leaves the tree in an inconsistent state that must be repaired by the caller by /// removing the entry in question. Specifically the key-value pair and its successor will /// become swapped. - fn into_leaf(mut self) -> SearchStack<'a, K, V, KV, Leaf> { + fn into_leaf(mut self) -> SearchStack<'a, K, V, handle::KV, handle::Leaf> { unsafe { let mut top_raw = self.top; let mut top = top_raw.from_raw_mut(); @@ -757,7 +760,7 @@ mod stack { } } - impl<'a, K, V> SearchStack<'a, K, V, Edge, Leaf> { + impl<'a, K, V> SearchStack<'a, K, V, handle::Edge, handle::Leaf> { /// Inserts the key and value into the top element in the stack, and if that node has to /// split recursively inserts the split contents into the next element stack until /// splits stop. diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 9698b06c7fa0f..1666f42d82bb5 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -34,9 +34,9 @@ pub enum InsertionResult { /// Represents the result of a search for a key in a single node pub enum SearchResult { /// The element was found at the given index - Found(Handle), + Found(Handle), /// The element wasn't found, but if it's anywhere, it must be beyond this edge - GoDown(Handle), + GoDown(Handle), } /// A B-Tree Node. We keep keys/edges/values separate to optimize searching for keys. @@ -494,12 +494,16 @@ pub struct Handle { index: uint } -pub enum KV {} -pub enum Edge {} +pub mod handle { + // Handle types. + pub enum KV {} + pub enum Edge {} -pub enum LeafOrInternal {} -pub enum Leaf {} -pub enum Internal {} + // Handle node types. + pub enum LeafOrInternal {} + pub enum Leaf {} + pub enum Internal {} +} impl Node { /// Searches for the given key in the node. If it finds an exact match, @@ -625,7 +629,7 @@ impl Handle<*mut Node, Type, NodeType> { } } -impl<'a, K: 'a, V: 'a> Handle<&'a Node, Edge, Internal> { +impl<'a, K: 'a, V: 'a> Handle<&'a Node, handle::Edge, handle::Internal> { /// Turns the handle into a reference to the edge it points at. This is necessary because the /// returned pointer has a larger lifetime than what would be returned by `edge` or `edge_mut`, /// making it more suitable for moving down a chain of nodes. @@ -636,7 +640,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a Node, Edge, Internal> { } } -impl<'a, K: 'a, V: 'a> Handle<&'a mut Node, Edge, Internal> { +impl<'a, K: 'a, V: 'a> Handle<&'a mut Node, handle::Edge, handle::Internal> { /// Turns the handle into a mutable reference to the edge it points at. This is necessary /// because the returned pointer has a larger lifetime than what would be returned by /// `edge_mut`, making it more suitable for moving down a chain of nodes. @@ -647,7 +651,7 @@ impl<'a, K: 'a, V: 'a> Handle<&'a mut Node, Edge, Internal> { } } -impl>> Handle { +impl>> Handle { // This doesn't exist because there are no uses for it, // but is fine to add, analagous to edge_mut. // @@ -657,11 +661,11 @@ impl>> Handle { } pub enum ForceResult { - Leaf(Handle), - Internal(Handle) + Leaf(Handle), + Internal(Handle) } -impl>, Type> Handle { +impl>, Type> Handle { /// Figure out whether this handle is pointing to something in a leaf node or to something in /// an internal node, clarifying the type according to the result. pub fn force(self) -> ForceResult { @@ -679,7 +683,7 @@ impl>, Type> Handle>> Handle { +impl>> Handle { /// Tries to insert this key-value pair at the given index in this leaf node /// If the node is full, we have to split it. /// @@ -711,7 +715,7 @@ impl>> Handle { } } -impl>> Handle { +impl>> Handle { /// Returns a mutable reference to the edge pointed-to by this handle. This should not be /// confused with `node`, which references the parent node of what is returned here. pub fn edge_mut(&mut self) -> &mut Node { @@ -794,11 +798,11 @@ impl>> Handle { } } -impl>, NodeType> Handle { +impl>, NodeType> Handle { /// Gets the handle pointing to the key/value pair just to the left of the pointed-to edge. /// This is unsafe because the handle might point to the first edge in the node, which has no /// pair to its left. - unsafe fn left_kv<'a>(&'a mut self) -> Handle<&'a mut Node, KV, NodeType> { + unsafe fn left_kv<'a>(&'a mut self) -> Handle<&'a mut Node, handle::KV, NodeType> { Handle { node: &mut *self.node, index: self.index - 1 @@ -808,7 +812,7 @@ impl>, NodeType> Handle(&'a mut self) -> Handle<&'a mut Node, KV, NodeType> { + unsafe fn right_kv<'a>(&'a mut self) -> Handle<&'a mut Node, handle::KV, NodeType> { Handle { node: &mut *self.node, index: self.index @@ -816,7 +820,7 @@ impl>, NodeType> Handle Handle<&'a Node, KV, NodeType> { +impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node, handle::KV, NodeType> { /// Turns the handle into references to the key and value it points at. This is necessary /// because the returned pointers have larger lifetimes than what would be returned by `key` /// or `val`. @@ -831,7 +835,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a Node, KV, NodeType> { } } -impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node, KV, NodeType> { +impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node, handle::KV, NodeType> { /// Turns the handle into mutable references to the key and value it points at. This is /// necessary because the returned pointers have larger lifetimes than what would be returned /// by `key_mut` or `val_mut`. @@ -848,7 +852,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node, KV, NodeType> { /// Convert this handle into one pointing at the edge immediately to the left of the key/value /// pair pointed-to by this handle. This is useful because it returns a reference with larger /// lifetime than `left_edge`. - pub fn into_left_edge(self) -> Handle<&'a mut Node, Edge, NodeType> { + pub fn into_left_edge(self) -> Handle<&'a mut Node, handle::Edge, NodeType> { Handle { node: &mut *self.node, index: self.index @@ -856,7 +860,8 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<&'a mut Node, KV, NodeType> { } } -impl<'a, K: 'a, V: 'a, NodeRef: Deref> + 'a, NodeType> Handle { +impl<'a, K: 'a, V: 'a, NodeRef: Deref> + 'a, NodeType> Handle { // These are fine to include, but are currently unneeded. // // /// Returns a reference to the key pointed-to by this handle. This doesn't return a @@ -874,7 +879,8 @@ impl<'a, K: 'a, V: 'a, NodeRef: Deref> + 'a, NodeType> Handle> + 'a, NodeType> Handle { +impl<'a, K: 'a, V: 'a, NodeRef: DerefMut> + 'a, NodeType> Handle { /// Returns a mutable reference to the key pointed-to by this handle. This doesn't return a /// reference with a lifetime as large as `into_kv_mut`, but it also does not consume the /// handle. @@ -890,10 +896,10 @@ impl<'a, K: 'a, V: 'a, NodeRef: DerefMut> + 'a, NodeType> Handle>, NodeType> Handle { +impl>, NodeType> Handle { /// Gets the handle pointing to the edge immediately to the left of the key/value pair pointed /// to by this handle. - pub fn left_edge<'a>(&'a mut self) -> Handle<&'a mut Node, Edge, NodeType> { + pub fn left_edge<'a>(&'a mut self) -> Handle<&'a mut Node, handle::Edge, NodeType> { Handle { node: &mut *self.node, index: self.index @@ -902,7 +908,7 @@ impl>, NodeType> Handle(&'a mut self) -> Handle<&'a mut Node, Edge, NodeType> { + pub fn right_edge<'a>(&'a mut self) -> Handle<&'a mut Node, handle::Edge, NodeType> { Handle { node: &mut *self.node, index: self.index + 1 @@ -910,7 +916,7 @@ impl>, NodeType> Handle>> Handle { +impl>> Handle { /// Removes the key/value pair at the handle's location. /// /// # Panics (in debug build) @@ -921,7 +927,7 @@ impl>> Handle { } } -impl>> Handle { +impl>> Handle { /// Steal! Stealing is roughly analogous to a binary tree rotation. /// In this case, we're "rotating" right. unsafe fn steal_rightward(&mut self) { @@ -1004,7 +1010,8 @@ impl Node { /// # Panics (in debug build) /// /// Panics if the given index is out of bounds. - pub fn kv_handle(&mut self, index: uint) -> Handle<&mut Node, KV, LeafOrInternal> { + pub fn kv_handle(&mut self, index: uint) -> Handle<&mut Node, handle::KV, + handle::LeafOrInternal> { // Necessary for correctness, but in a private module debug_assert!(index < self.len(), "kv_handle index out of bounds"); Handle { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 9ac5f04efe5f2..dc8313386b998 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -51,18 +51,21 @@ #![doc(primitive = "str")] -use core::prelude::*; - pub use self::MaybeOwned::*; use self::RecompositionState::*; use self::DecompositionType::*; use core::borrow::{BorrowFrom, Cow, ToOwned}; +use core::clone::Clone; use core::default::Default; use core::fmt; use core::hash; -use core::cmp; -use core::iter::AdditiveIterator; +use core::char::Char; +use core::cmp::{mod, Eq, Equiv, Ord, Ordering, PartialEq, PartialOrd}; +use core::iter::{range, AdditiveIterator, Iterator, IteratorExt}; +use core::kinds::Sized; +use core::option::Option::{mod, Some, None}; +use core::slice::{AsSlice, SliceExt}; use ring_buf::RingBuf; use string::String; diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 8fe3642e702d4..f1c8e8950a22e 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -67,18 +67,18 @@ //! } //! ``` -use string::String; -use hash; +use core::prelude::*; +use libc; + use fmt; +use hash; use kinds::marker; use mem; -use core::prelude::*; - use ptr; -use raw::Slice; -use slice; +use slice::{mod, ImmutableIntSlice}; use str; -use libc; +use string::String; + /// The representation of a C String. /// @@ -210,7 +210,7 @@ impl CString { #[inline] pub fn as_bytes<'a>(&'a self) -> &'a [u8] { unsafe { - mem::transmute(Slice { data: self.buf, len: self.len() + 1 }) + slice::from_raw_buf(&self.buf, self.len() + 1).as_unsigned() } } @@ -219,7 +219,7 @@ impl CString { #[inline] pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] { unsafe { - mem::transmute(Slice { data: self.buf, len: self.len() }) + slice::from_raw_buf(&self.buf, self.len()).as_unsigned() } }