Skip to content

Commit 201513e

Browse files
committed
De-export std::{fun_treemap, list, map}. Part of #3583.
1 parent 092de78 commit 201513e

File tree

4 files changed

+30
-47
lines changed

4 files changed

+30
-47
lines changed

src/libstd/fun_treemap.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@ use core::cmp::{Eq, Ord};
1515
use option::{Some, None};
1616
use option = option;
1717

18-
export Treemap;
19-
export init;
20-
export insert;
21-
export find;
22-
export traverse;
23-
24-
type Treemap<K, V> = @TreeNode<K, V>;
18+
pub type Treemap<K, V> = @TreeNode<K, V>;
2519

2620
enum TreeNode<K, V> {
2721
Empty,
2822
Node(@K, @V, @TreeNode<K, V>, @TreeNode<K, V>)
2923
}
3024

3125
/// Create a treemap
32-
fn init<K, V>() -> Treemap<K, V> { @Empty }
26+
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
3327

3428
/// Insert a value into the map
35-
fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K, +v: V)
29+
pub fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K, +v: V)
3630
-> Treemap<K, V> {
3731
@match m {
3832
@Empty => Node(@k, @v, @Empty, @Empty),
@@ -47,7 +41,7 @@ fn insert<K: Copy Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K, +v: V)
4741
}
4842

4943
/// Find a value based on the key
50-
fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
44+
pub fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
5145
match *m {
5246
Empty => None,
5347
Node(@ref kk, @copy v, left, right) => {
@@ -59,7 +53,7 @@ fn find<K: Eq Ord, V: Copy>(m: Treemap<K, V>, +k: K) -> Option<V> {
5953
}
6054

6155
/// Visit all pairs in the map in order.
62-
fn traverse<K, V: Copy>(m: Treemap<K, V>, f: fn((&K), (&V))) {
56+
pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: fn((&K), (&V))) {
6357
match *m {
6458
Empty => (),
6559
/*

src/libstd/list.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use core::option;
66
use option::*;
77
use option::{Some, None};
88

9-
enum List<T> {
9+
pub enum List<T> {
1010
Cons(T, @List<T>),
1111
Nil,
1212
}
1313

1414
/// Cregate a list from a vector
15-
fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
15+
pub fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
1616
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
1717
}
1818

@@ -29,7 +29,7 @@ fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
2929
* * z - The initial value
3030
* * f - The function to apply
3131
*/
32-
fn foldl<T: Copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
32+
pub fn foldl<T: Copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
3333
let mut accum: T = z;
3434
do iter(ls) |elt| { accum = f(&accum, elt);}
3535
accum
@@ -42,7 +42,7 @@ fn foldl<T: Copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
4242
* When function `f` returns true then an option containing the element
4343
* is returned. If `f` matches no elements then none is returned.
4444
*/
45-
fn find<T: Copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
45+
pub fn find<T: Copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
4646
let mut ls = ls;
4747
loop {
4848
ls = match *ls {
@@ -56,43 +56,43 @@ fn find<T: Copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
5656
}
5757

5858
/// Returns true if a list contains an element with the given value
59-
fn has<T: Copy Eq>(ls: @List<T>, +elt: T) -> bool {
59+
pub fn has<T: Copy Eq>(ls: @List<T>, +elt: T) -> bool {
6060
for each(ls) |e| {
6161
if *e == elt { return true; }
6262
}
6363
return false;
6464
}
6565

6666
/// Returns true if the list is empty
67-
pure fn is_empty<T: Copy>(ls: @List<T>) -> bool {
67+
pub pure fn is_empty<T: Copy>(ls: @List<T>) -> bool {
6868
match *ls {
6969
Nil => true,
7070
_ => false
7171
}
7272
}
7373

7474
/// Returns true if the list is not empty
75-
pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
75+
pub pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
7676
return !is_empty(ls);
7777
}
7878

7979
/// Returns the length of a list
80-
fn len<T>(ls: @List<T>) -> uint {
80+
pub fn len<T>(ls: @List<T>) -> uint {
8181
let mut count = 0u;
8282
iter(ls, |_e| count += 1u);
8383
count
8484
}
8585

8686
/// Returns all but the first element of a list
87-
pure fn tail<T: Copy>(ls: @List<T>) -> @List<T> {
87+
pub pure fn tail<T: Copy>(ls: @List<T>) -> @List<T> {
8888
match *ls {
8989
Cons(_, tl) => return tl,
9090
Nil => fail ~"list empty"
9191
}
9292
}
9393

9494
/// Returns the first element of a list
95-
pure fn head<T: Copy>(ls: @List<T>) -> T {
95+
pub pure fn head<T: Copy>(ls: @List<T>) -> T {
9696
match *ls {
9797
Cons(copy hd, _) => hd,
9898
// makes me sad
@@ -101,7 +101,7 @@ pure fn head<T: Copy>(ls: @List<T>) -> T {
101101
}
102102

103103
/// Appends one list to another
104-
pure fn append<T: Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
104+
pub pure fn append<T: Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
105105
match *l {
106106
Nil => return m,
107107
Cons(copy x, xs) => {
@@ -120,7 +120,7 @@ pure fn push<T: Copy>(ll: &mut @list<T>, +vv: T) {
120120
*/
121121

122122
/// Iterate over a list
123-
fn iter<T>(l: @List<T>, f: fn((&T))) {
123+
pub fn iter<T>(l: @List<T>, f: fn((&T))) {
124124
let mut cur = l;
125125
loop {
126126
cur = match *cur {
@@ -134,7 +134,7 @@ fn iter<T>(l: @List<T>, f: fn((&T))) {
134134
}
135135

136136
/// Iterate over a list
137-
fn each<T>(l: @List<T>, f: fn((&T)) -> bool) {
137+
pub fn each<T>(l: @List<T>, f: fn((&T)) -> bool) {
138138
let mut cur = l;
139139
loop {
140140
cur = match *cur {

src/libstd/map.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ use core::cmp::Eq;
1111
use hash::Hash;
1212
use to_bytes::IterBytes;
1313

14-
export HashMap, hashfn, eqfn, Set, Map, chained, set_add;
15-
export hash_from_vec;
16-
export vec_from_set;
17-
1814
/// A convenience type to treat a hashmap as a set
19-
type Set<K:Eq IterBytes Hash> = HashMap<K, ()>;
15+
pub type Set<K:Eq IterBytes Hash> = HashMap<K, ()>;
2016

21-
type HashMap<K:Eq IterBytes Hash, V> = chained::T<K, V>;
17+
pub type HashMap<K:Eq IterBytes Hash, V> = chained::T<K, V>;
2218

23-
trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
19+
pub trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
2420
/// Return the number of elements in the map
2521
pure fn size() -> uint;
2622

@@ -82,10 +78,9 @@ trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
8278
}
8379

8480
mod util {
85-
#[legacy_exports];
86-
type Rational = {num: int, den: int}; // : int::positive(*.den);
81+
pub type Rational = {num: int, den: int}; // : int::positive(*.den);
8782

88-
pure fn rational_leq(x: Rational, y: Rational) -> bool {
83+
pub pure fn rational_leq(x: Rational, y: Rational) -> bool {
8984
// NB: Uses the fact that rationals have positive denominators WLOG:
9085

9186
x.num * y.den <= y.num * x.den
@@ -95,9 +90,7 @@ mod util {
9590

9691
// FIXME (#2344): package this up and export it as a datatype usable for
9792
// external code that doesn't want to pay the cost of a box.
98-
mod chained {
99-
#[legacy_exports];
100-
export T, mk, HashMap;
93+
pub mod chained {
10194

10295
const initial_capacity: uint = 32u; // 2^5
10396

@@ -113,7 +106,7 @@ mod chained {
113106
mut chains: ~[mut Option<@Entry<K,V>>]
114107
}
115108

116-
type T<K:Eq IterBytes Hash, V> = @HashMap_<K, V>;
109+
pub type T<K:Eq IterBytes Hash, V> = @HashMap_<K, V>;
117110

118111
enum SearchResult<K, V> {
119112
NotFound,
@@ -366,7 +359,7 @@ mod chained {
366359
vec::to_mut(vec::from_elem(nchains, None))
367360
}
368361

369-
fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
362+
pub fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
370363
let slf: T<K, V> = @HashMap_ {count: 0u,
371364
chains: chains(initial_capacity)};
372365
slf
@@ -378,18 +371,18 @@ Function: hashmap
378371
379372
Construct a hashmap.
380373
*/
381-
fn HashMap<K:Eq IterBytes Hash Const, V: Copy>()
374+
pub fn HashMap<K:Eq IterBytes Hash Const, V: Copy>()
382375
-> HashMap<K, V> {
383376
chained::mk()
384377
}
385378

386379
/// Convenience function for adding keys to a hashmap with nil type keys
387-
fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, +key: K) -> bool {
380+
pub fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, +key: K) -> bool {
388381
set.insert(key, ())
389382
}
390383

391384
/// Convert a set into a vector.
392-
fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
385+
pub fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
393386
do vec::build_sized(s.size()) |push| {
394387
for s.each_key() |k| {
395388
push(k);
@@ -398,7 +391,7 @@ fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
398391
}
399392

400393
/// Construct a hashmap from a vector
401-
fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
394+
pub fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
402395
items: &[(K, V)]) -> HashMap<K, V> {
403396
let map = HashMap();
404397
for vec::each(items) |item| {
@@ -517,7 +510,6 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
517510

518511
#[cfg(test)]
519512
mod tests {
520-
#[legacy_exports];
521513

522514
#[test]
523515
fn test_simple() {

src/libstd/std.rc

-3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ mod comm;
7777

7878
mod bitv;
7979
mod deque;
80-
#[legacy_exports]
8180
mod fun_treemap;
82-
#[legacy_exports]
8381
mod list;
84-
#[legacy_exports]
8582
mod map;
8683
mod rope;
8784
mod smallintmap;

0 commit comments

Comments
 (0)