diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-10-01 14:01:42 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-10-01 14:09:09 -0700 |
| commit | 8cc61c816a0f08535f6300af4a5eaf30b8094c57 (patch) | |
| tree | 45db7a4ab712de5c6ae06771b09c7c047169a197 /src/libstd | |
| parent | 9ff95e29b3ae9e3de405680ddb6557da72cc25f7 (diff) | |
De-export std::{rope,smallintmap}. Part of #3583.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rope.rs | 139 | ||||
| -rw-r--r-- | src/libstd/smallintmap.rs | 14 | ||||
| -rw-r--r-- | src/libstd/std.rc | 2 |
3 files changed, 74 insertions, 81 deletions
diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 3f10fdb2b1d..47539b2dab6 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -26,14 +26,14 @@ #[forbid(deprecated_mode)]; /// The type of ropes. -type Rope = node::Root; +pub type Rope = node::Root; /* Section: Creating a rope */ /// Create an empty rope -fn empty() -> Rope { +pub fn empty() -> Rope { return node::Empty; } @@ -54,7 +54,7 @@ fn empty() -> Rope { * * this operation does not copy the string; * * the function runs in linear time. */ -fn of_str(str: @~str) -> Rope { +pub fn of_str(str: @~str) -> Rope { return of_substr(str, 0u, str::len(*str)); } @@ -80,7 +80,7 @@ fn of_str(str: @~str) -> Rope { * * this function does _not_ check the validity of the substring; * * this function fails if `byte_offset` or `byte_len` do not match `str`. */ -fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> Rope { +pub fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> Rope { if byte_len == 0u { return node::Empty; } if byte_offset + byte_len > str::len(*str) { fail; } return node::Content(node::of_substr(str, byte_offset, byte_len)); @@ -97,7 +97,7 @@ Section: Adding things to a rope * * * this function executes in near-constant time */ -fn append_char(rope: Rope, char: char) -> Rope { +pub fn append_char(rope: Rope, char: char) -> Rope { return append_str(rope, @str::from_chars(~[char])); } @@ -108,7 +108,7 @@ fn append_char(rope: Rope, char: char) -> Rope { * * * this function executes in near-linear time */ -fn append_str(rope: Rope, str: @~str) -> Rope { +pub fn append_str(rope: Rope, str: @~str) -> Rope { return append_rope(rope, of_str(str)) } @@ -118,7 +118,7 @@ fn append_str(rope: Rope, str: @~str) -> Rope { * # Performance note * * this function executes in near-constant time */ -fn prepend_char(rope: Rope, char: char) -> Rope { +pub fn prepend_char(rope: Rope, char: char) -> Rope { return prepend_str(rope, @str::from_chars(~[char])); } @@ -128,12 +128,12 @@ fn prepend_char(rope: Rope, char: char) -> Rope { * # Performance note * * this function executes in near-linear time */ -fn prepend_str(rope: Rope, str: @~str) -> Rope { +pub fn prepend_str(rope: Rope, str: @~str) -> Rope { return append_rope(of_str(str), rope) } /// Concatenate two ropes -fn append_rope(left: Rope, right: Rope) -> Rope { +pub fn append_rope(left: Rope, right: Rope) -> Rope { match (left) { node::Empty => return right, node::Content(left_content) => { @@ -154,7 +154,7 @@ fn append_rope(left: Rope, right: Rope) -> Rope { * rope remains balanced. However, this function does not take any further * measure to ensure that the result is balanced. */ -fn concat(v: ~[Rope]) -> Rope { +pub fn concat(v: ~[Rope]) -> Rope { //Copy `v` into a mut vector let mut len = vec::len(v); if len == 0u { return node::Empty; } @@ -197,7 +197,7 @@ Section: Keeping ropes healthy * If you perform numerous rope concatenations, it is generally a good idea * to rebalance your rope at some point, before using it for other purposes. */ -fn bal(rope:Rope) -> Rope { +pub fn bal(rope:Rope) -> Rope { match (rope) { node::Empty => return rope, node::Content(x) => match (node::bal(x)) { @@ -225,7 +225,7 @@ Section: Transforming ropes * * this function fails if char_offset/char_len do not represent * valid positions in rope */ -fn sub_chars(rope: Rope, char_offset: uint, char_len: uint) -> Rope { +pub fn sub_chars(rope: Rope, char_offset: uint, char_len: uint) -> Rope { if char_len == 0u { return node::Empty; } match (rope) { node::Empty => fail, @@ -250,7 +250,7 @@ fn sub_chars(rope: Rope, char_offset: uint, char_len: uint) -> Rope { * * this function fails if byte_offset/byte_len do not represent * valid positions in rope */ -fn sub_bytes(rope: Rope, byte_offset: uint, byte_len: uint) -> Rope { +pub fn sub_bytes(rope: Rope, byte_offset: uint, byte_len: uint) -> Rope { if byte_len == 0u { return node::Empty; } match (rope) { node::Empty => fail, @@ -276,7 +276,7 @@ Section: Comparing ropes * A negative value if `left < right`, 0 if eq(left, right) or a positive * value if `left > right` */ -fn cmp(left: Rope, right: Rope) -> int { +pub fn cmp(left: Rope, right: Rope) -> int { match ((left, right)) { (node::Empty, node::Empty) => return 0, (node::Empty, _) => return -1, @@ -291,7 +291,7 @@ fn cmp(left: Rope, right: Rope) -> int { * Returns `true` if both ropes have the same content (regardless of * their structure), `false` otherwise */ -fn eq(left: Rope, right: Rope) -> bool { +pub fn eq(left: Rope, right: Rope) -> bool { return cmp(left, right) == 0; } @@ -306,7 +306,7 @@ fn eq(left: Rope, right: Rope) -> bool { * `true` if `left <= right` in lexicographical order (regardless of their * structure), `false` otherwise */ -fn le(left: Rope, right: Rope) -> bool { +pub fn le(left: Rope, right: Rope) -> bool { return cmp(left, right) <= 0; } @@ -321,7 +321,7 @@ fn le(left: Rope, right: Rope) -> bool { * `true` if `left < right` in lexicographical order (regardless of their * structure), `false` otherwise */ -fn lt(left: Rope, right: Rope) -> bool { +pub fn lt(left: Rope, right: Rope) -> bool { return cmp(left, right) < 0; } @@ -336,7 +336,7 @@ fn lt(left: Rope, right: Rope) -> bool { * `true` if `left >= right` in lexicographical order (regardless of their * structure), `false` otherwise */ -fn ge(left: Rope, right: Rope) -> bool { +pub fn ge(left: Rope, right: Rope) -> bool { return cmp(left, right) >= 0; } @@ -351,7 +351,7 @@ fn ge(left: Rope, right: Rope) -> bool { * `true` if `left > right` in lexicographical order (regardless of their * structure), `false` otherwise */ -fn gt(left: Rope, right: Rope) -> bool { +pub fn gt(left: Rope, right: Rope) -> bool { return cmp(left, right) > 0; } @@ -379,7 +379,7 @@ Section: Iterating * `true` If execution proceeded correctly, `false` if it was interrupted, * that is if `it` returned `false` at any point. */ -fn loop_chars(rope: Rope, it: fn(char) -> bool) -> bool { +pub fn loop_chars(rope: Rope, it: fn(char) -> bool) -> bool { match (rope) { node::Empty => return true, node::Content(x) => return node::loop_chars(x, it) @@ -393,7 +393,7 @@ fn loop_chars(rope: Rope, it: fn(char) -> bool) -> bool { * * rope - A rope to traverse. It may be empty * * it - A block to execute with each consecutive character of the rope. */ -fn iter_chars(rope: Rope, it: fn(char)) { +pub fn iter_chars(rope: Rope, it: fn(char)) { do loop_chars(rope) |x| { it(x); true @@ -422,17 +422,15 @@ fn iter_chars(rope: Rope, it: fn(char)) { * `true` If execution proceeded correctly, `false` if it was interrupted, * that is if `it` returned `false` at any point. */ -fn loop_leaves(rope: Rope, it: fn(node::Leaf) -> bool) -> bool{ +pub fn loop_leaves(rope: Rope, it: fn(node::Leaf) -> bool) -> bool{ match (rope) { node::Empty => return true, node::Content(x) => return node::loop_leaves(x, it) } } -mod iterator { - #[legacy_exports]; - mod leaf { - #[legacy_exports]; +pub mod iterator { + pub mod leaf { fn start(rope: Rope) -> node::leaf_iterator::T { match (rope) { node::Empty => return node::leaf_iterator::empty(), @@ -443,8 +441,7 @@ mod iterator { return node::leaf_iterator::next(it); } } - mod char { - #[legacy_exports]; + pub mod char { fn start(rope: Rope) -> node::char_iterator::T { match (rope) { node::Empty => return node::char_iterator::empty(), @@ -472,7 +469,7 @@ mod iterator { * * Constant time. */ -fn height(rope: Rope) -> uint { +pub fn height(rope: Rope) -> uint { match (rope) { node::Empty => return 0u, node::Content(x) => return node::height(x) @@ -488,7 +485,7 @@ fn height(rope: Rope) -> uint { * * Constant time. */ -pure fn char_len(rope: Rope) -> uint { +pub pure fn char_len(rope: Rope) -> uint { match (rope) { node::Empty => return 0u, node::Content(x) => return node::char_len(x) @@ -502,7 +499,7 @@ pure fn char_len(rope: Rope) -> uint { * * Constant time. */ -pure fn byte_len(rope: Rope) -> uint { +pub pure fn byte_len(rope: Rope) -> uint { match (rope) { node::Empty => return 0u, node::Content(x) => return node::byte_len(x) @@ -525,7 +522,7 @@ pure fn byte_len(rope: Rope) -> uint { * This function executes in a time proportional to the height of the * rope + the (bounded) length of the largest leaf. */ -fn char_at(rope: Rope, pos: uint) -> char { +pub fn char_at(rope: Rope, pos: uint) -> char { match (rope) { node::Empty => fail, node::Content(x) => return node::char_at(x, pos) @@ -537,10 +534,9 @@ fn char_at(rope: Rope, pos: uint) -> char { Section: Implementation */ mod node { - #[legacy_exports]; /// Implementation of type `rope` - enum Root { + pub enum Root { /// An empty rope Empty, /// A non-empty rope @@ -564,7 +560,7 @@ mod node { * string can be shared between several ropes, e.g. for indexing * purposes. */ - type Leaf = { + pub type Leaf = { byte_offset: uint, byte_len: uint, char_len: uint, @@ -588,7 +584,7 @@ mod node { * * Used for rebalancing and to allocate stacks for traversals. */ - type Concat = { + pub type Concat = { //FIXME (#2744): Perhaps a `vec` instead of `left`/`right` left: @Node, right: @Node, @@ -597,7 +593,7 @@ mod node { height: uint }; - enum Node { + pub enum Node { /// A leaf consisting in a `str` Leaf(Leaf), /// The concatenation of two ropes @@ -609,14 +605,14 @@ mod node { * * This is not a strict value */ - const hint_max_leaf_char_len: uint = 256u; + pub const hint_max_leaf_char_len: uint = 256u; /** * The maximal height that _should_ be permitted in a tree. * * This is not a strict value */ - const hint_max_node_height: uint = 16u; + pub const hint_max_node_height: uint = 16u; /** * Adopt a string as a node. @@ -628,7 +624,7 @@ mod node { * Performance note: The complexity of this function is linear in * the length of `str`. */ - fn of_str(str: @~str) -> @Node { + pub fn of_str(str: @~str) -> @Node { return of_substr(str, 0u, str::len(*str)); } @@ -649,7 +645,7 @@ mod node { * Behavior is undefined if `byte_start` or `byte_len` do not represent * valid positions in `str` */ - fn of_substr(str: @~str, byte_start: uint, byte_len: uint) -> @Node { + pub fn of_substr(str: @~str, byte_start: uint, byte_len: uint) -> @Node { return of_substr_unsafer(str, byte_start, byte_len, str::count_chars(*str, byte_start, byte_len)); } @@ -675,8 +671,8 @@ mod node { * * Behavior is undefined if `char_len` does not accurately represent the * number of chars between byte_start and byte_start+byte_len */ - fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint, - char_len: uint) -> @Node { + pub fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint, + char_len: uint) -> @Node { assert(byte_start + byte_len <= str::len(*str)); let candidate = @Leaf({ byte_offset: byte_start, @@ -733,7 +729,7 @@ mod node { } } - pure fn byte_len(node: @Node) -> uint { + pub pure fn byte_len(node: @Node) -> uint { //FIXME (#2744): Could we do this without the pattern-matching? match (*node) { Leaf(y) => return y.byte_len, @@ -741,7 +737,7 @@ mod node { } } - pure fn char_len(node: @Node) -> uint { + pub pure fn char_len(node: @Node) -> uint { match (*node) { Leaf(y) => return y.char_len, Concat(ref y) => return y.char_len @@ -756,7 +752,7 @@ mod node { * * forest - The forest. This vector is progressively rewritten during * execution and should be discarded as meaningless afterwards. */ - fn tree_from_forest_destructive(forest: &[mut @Node]) -> @Node { + pub fn tree_from_forest_destructive(forest: &[mut @Node]) -> @Node { let mut i; let mut len = vec::len(forest); while len > 1u { @@ -800,7 +796,7 @@ mod node { return forest[0]; } - fn serialize_node(node: @Node) -> ~str unsafe { + pub fn serialize_node(node: @Node) -> ~str unsafe { let mut buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8)); let mut offset = 0u;//Current position in the buffer let it = leaf_iterator::start(node); @@ -831,7 +827,7 @@ mod node { * * This function executes in linear time. */ - fn flatten(node: @Node) -> @Node unsafe { + pub fn flatten(node: @Node) -> @Node unsafe { match (*node) { Leaf(_) => return node, Concat(ref x) => { @@ -860,7 +856,7 @@ mod node { * * `option::some(x)` otherwise, in which case `x` has the same contents * as `node` bot lower height and/or fragmentation. */ - fn bal(node: @Node) -> Option<@Node> { + pub fn bal(node: @Node) -> Option<@Node> { if height(node) < hint_max_node_height { return option::None; } //1. Gather all leaves as a forest let mut forest = ~[]; @@ -896,7 +892,8 @@ mod node { * This function fails if `byte_offset` or `byte_len` do not represent * valid positions in `node`. */ - fn sub_bytes(node: @Node, byte_offset: uint, byte_len: uint) -> @Node { + pub fn sub_bytes(node: @Node, byte_offset: uint, + byte_len: uint) -> @Node { let mut node = node; let mut byte_offset = byte_offset; loop { @@ -957,7 +954,8 @@ mod node { * This function fails if `char_offset` or `char_len` do not represent * valid positions in `node`. */ - fn sub_chars(node: @Node, char_offset: uint, char_len: uint) -> @Node { + pub fn sub_chars(node: @Node, char_offset: uint, + char_len: uint) -> @Node { let mut node = node; let mut char_offset = char_offset; loop { @@ -1002,7 +1000,7 @@ mod node { }; } - fn concat2(left: @Node, right: @Node) -> @Node { + pub fn concat2(left: @Node, right: @Node) -> @Node { return @Concat({left : left, right : right, char_len: char_len(left) + char_len(right), @@ -1011,14 +1009,14 @@ mod node { }) } - fn height(node: @Node) -> uint { + pub fn height(node: @Node) -> uint { match (*node) { Leaf(_) => return 0u, Concat(ref x) => return x.height } } - fn cmp(a: @Node, b: @Node) -> int { + pub fn cmp(a: @Node, b: @Node) -> int { let ita = char_iterator::start(a); let itb = char_iterator::start(b); let mut result = 0; @@ -1039,7 +1037,7 @@ mod node { return result; } - fn loop_chars(node: @Node, it: fn(char) -> bool) -> bool { + pub fn loop_chars(node: @Node, it: fn(char) -> bool) -> bool { return loop_leaves(node,|leaf| { str::all_between(*leaf.content, leaf.byte_offset, @@ -1061,7 +1059,7 @@ mod node { * `true` If execution proceeded correctly, `false` if it was interrupted, * that is if `it` returned `false` at any point. */ - fn loop_leaves(node: @Node, it: fn(Leaf) -> bool) -> bool{ + pub fn loop_leaves(node: @Node, it: fn(Leaf) -> bool) -> bool{ let mut current = node; loop { match (*current) { @@ -1092,7 +1090,7 @@ mod node { * proportional to the height of the rope + the (bounded) * length of the largest leaf. */ - fn char_at(node: @Node, pos: uint) -> char { + pub fn char_at(node: @Node, pos: uint) -> char { let mut node = node; let mut pos = pos; loop { @@ -1107,19 +1105,18 @@ mod node { }; } - mod leaf_iterator { - #[legacy_exports]; - type T = { + pub mod leaf_iterator { + pub type T = { stack: ~[mut @Node], mut stackpos: int }; - fn empty() -> T { + pub fn empty() -> T { let stack : ~[mut @Node] = ~[mut]; return {stack: move stack, mut stackpos: -1} } - fn start(node: @Node) -> T { + pub fn start(node: @Node) -> T { let stack = vec::to_mut(vec::from_elem(height(node)+1u, node)); return { stack: move stack, @@ -1127,7 +1124,7 @@ mod node { } } - fn next(it: &T) -> Option<Leaf> { + pub fn next(it: &T) -> Option<Leaf> { if it.stackpos < 0 { return option::None; } loop { let current = it.stack[it.stackpos]; @@ -1145,15 +1142,14 @@ mod node { } } - mod char_iterator { - #[legacy_exports]; - type T = { + pub mod char_iterator { + pub type T = { leaf_iterator: leaf_iterator::T, mut leaf: Option<Leaf>, mut leaf_byte_pos: uint }; - fn start(node: @Node) -> T { + pub fn start(node: @Node) -> T { return { leaf_iterator: leaf_iterator::start(node), mut leaf: option::None, @@ -1161,7 +1157,7 @@ mod node { } } - fn empty() -> T { + pub fn empty() -> T { return { leaf_iterator: leaf_iterator::empty(), mut leaf: option::None, @@ -1169,7 +1165,7 @@ mod node { } } - fn next(it: &T) -> Option<char> { + pub fn next(it: &T) -> Option<char> { loop { match (get_current_or_next_leaf(it)) { option::None => return option::None, @@ -1184,7 +1180,7 @@ mod node { }; } - fn get_current_or_next_leaf(it: &T) -> Option<Leaf> { + pub fn get_current_or_next_leaf(it: &T) -> Option<Leaf> { match ((*it).leaf) { option::Some(_) => return (*it).leaf, option::None => { @@ -1201,7 +1197,7 @@ mod node { } } - fn get_next_char_in_leaf(it: &T) -> Option<char> { + pub fn get_next_char_in_leaf(it: &T) -> Option<char> { match copy (*it).leaf { option::None => return option::None, option::Some(aleaf) => { @@ -1224,7 +1220,6 @@ mod node { #[cfg(test)] mod tests { - #[legacy_exports]; //Utility function, used for sanity check fn rope_to_string(r: Rope) -> ~str { diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 1100485e7f1..2e7f47e0af0 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -13,12 +13,12 @@ use map::Map; // requires this to be. type SmallIntMap_<T: Copy> = {v: DVec<Option<T>>}; -enum SmallIntMap<T:Copy> { +pub enum SmallIntMap<T:Copy> { SmallIntMap_(@SmallIntMap_<T>) } /// Create a smallintmap -fn mk<T: Copy>() -> SmallIntMap<T> { +pub fn mk<T: Copy>() -> SmallIntMap<T> { let v = DVec(); return SmallIntMap_(@{v: move v}); } @@ -28,7 +28,7 @@ fn mk<T: Copy>() -> SmallIntMap<T> { * the specified key then the original value is replaced. */ #[inline(always)] -fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, +val: T) { +pub fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, +val: T) { //io::println(fmt!("%?", key)); self.v.grow_set_elt(key, &None, Some(val)); } @@ -37,7 +37,7 @@ fn insert<T: Copy>(self: SmallIntMap<T>, key: uint, +val: T) { * Get the value for the specified key. If the key does not exist * in the map then returns none */ -pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> { +pub pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> { if key < self.v.len() { return self.v.get_elt(key); } return None::<T>; } @@ -49,7 +49,7 @@ pure fn find<T: Copy>(self: SmallIntMap<T>, key: uint) -> Option<T> { * * If the key does not exist in the map */ -pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T { +pub pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T { match find(self, key) { None => { error!("smallintmap::get(): key not present"); @@ -60,7 +60,7 @@ pure fn get<T: Copy>(self: SmallIntMap<T>, key: uint) -> T { } /// Returns true if the map contains a value for the specified key -fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool { +pub fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool { return !find(self, key).is_none(); } @@ -139,6 +139,6 @@ impl<V: Copy> SmallIntMap<V>: ops::Index<uint, V> { } /// Cast the given smallintmap to a map::map -fn as_map<V: Copy>(s: SmallIntMap<V>) -> map::Map<uint, V> { +pub fn as_map<V: Copy>(s: SmallIntMap<V>) -> map::Map<uint, V> { s as map::Map::<uint, V> } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 5b181d2e4c0..a38d9772b5c 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -87,9 +87,7 @@ mod fun_treemap; mod list; #[legacy_exports] mod map; -#[legacy_exports] mod rope; -#[legacy_exports] mod smallintmap; mod sort; mod treemap; |
