about summary refs log tree commit diff
path: root/src/libstd/map.rs
diff options
context:
space:
mode:
authorSimon BD <simon@server>2012-10-03 21:47:09 -0500
committerSimon BD <simon@server>2012-10-03 21:47:09 -0500
commitefcd2385ea2389f270ff8ac8bc256636f647b130 (patch)
tree7e142ef709bc907a34ab1cb252eef6dcc0e83b91 /src/libstd/map.rs
parent44f8a4401ab37a45ba49db56611d77807bcbce35 (diff)
parent3ccf6f5932d8223fd6c5cbf7c6ac429ca9e8912a (diff)
downloadrust-efcd2385ea2389f270ff8ac8bc256636f647b130.tar.gz
rust-efcd2385ea2389f270ff8ac8bc256636f647b130.zip
Merge remote-tracking branch 'original/incoming' into incoming
Conflicts:
	src/libstd/json.rs
	src/libstd/sort.rs
Diffstat (limited to 'src/libstd/map.rs')
-rw-r--r--src/libstd/map.rs87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/libstd/map.rs b/src/libstd/map.rs
index 9bdf6e15ee5..cc42c562376 100644
--- a/src/libstd/map.rs
+++ b/src/libstd/map.rs
@@ -1,7 +1,6 @@
 //! A map type
 
-#[forbid(deprecated_mode)];
-#[forbid(deprecated_pattern)];
+// tjc: forbid deprecated modes again after snap
 
 use io::WriterUtil;
 use to_str::ToStr;
@@ -12,16 +11,12 @@ use core::cmp::Eq;
 use hash::Hash;
 use to_bytes::IterBytes;
 
-export HashMap, hashfn, eqfn, Set, Map, chained, set_add;
-export hash_from_vec;
-export vec_from_set;
-
 /// A convenience type to treat a hashmap as a set
-type Set<K:Eq IterBytes Hash> = HashMap<K, ()>;
+pub type Set<K:Eq IterBytes Hash> = HashMap<K, ()>;
 
-type HashMap<K:Eq IterBytes Hash, V> = chained::T<K, V>;
+pub type HashMap<K:Eq IterBytes Hash, V> = chained::T<K, V>;
 
-trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
+pub trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
     /// Return the number of elements in the map
     pure fn size() -> uint;
 
@@ -33,10 +28,10 @@ trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
      *
      * Returns true if the key did not already exist in the map
      */
-    fn insert(+v: K, +v: V) -> bool;
+    fn insert(v: K, +v: V) -> bool;
 
     /// Returns true if the map contains a value for the specified key
-    fn contains_key(+key: K) -> bool;
+    fn contains_key(key: K) -> bool;
 
     /// Returns true if the map contains a value for the specified
     /// key, taking the key by reference.
@@ -46,31 +41,31 @@ trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
      * Get the value for the specified key. Fails if the key does not exist in
      * the map.
      */
-    fn get(+key: K) -> V;
+    fn get(key: K) -> V;
 
     /**
      * Get the value for the specified key. If the key does not exist in
      * the map then returns none.
      */
-    pure fn find(+key: K) -> Option<V>;
+    pure fn find(key: K) -> Option<V>;
 
     /**
      * Remove and return a value from the map. Returns true if the
      * key was present in the map, otherwise false.
      */
-    fn remove(+key: K) -> bool;
+    fn remove(key: K) -> bool;
 
     /// Clear the map, removing all key/value pairs.
     fn clear();
 
     /// Iterate over all the key/value pairs in the map by value
-    pure fn each(fn(+key: K, +value: V) -> bool);
+    pure fn each(fn(key: K, +value: V) -> bool);
 
     /// Iterate over all the keys in the map by value
-    pure fn each_key(fn(+key: K) -> bool);
+    pure fn each_key(fn(key: K) -> bool);
 
     /// Iterate over all the values in the map by value
-    pure fn each_value(fn(+value: V) -> bool);
+    pure fn each_value(fn(value: V) -> bool);
 
     /// Iterate over all the key/value pairs in the map by reference
     pure fn each_ref(fn(key: &K, value: &V) -> bool);
@@ -83,10 +78,9 @@ trait Map<K:Eq IterBytes Hash Copy, V: Copy> {
 }
 
 mod util {
-    #[legacy_exports];
-    type Rational = {num: int, den: int}; // : int::positive(*.den);
+    pub type Rational = {num: int, den: int}; // : int::positive(*.den);
 
-    pure fn rational_leq(x: Rational, y: Rational) -> bool {
+    pub pure fn rational_leq(x: Rational, y: Rational) -> bool {
         // NB: Uses the fact that rationals have positive denominators WLOG:
 
         x.num * y.den <= y.num * x.den
@@ -96,9 +90,7 @@ mod util {
 
 // FIXME (#2344): package this up and export it as a datatype usable for
 // external code that doesn't want to pay the cost of a box.
-mod chained {
-    #[legacy_exports];
-    export T, mk, HashMap;
+pub mod chained {
 
     const initial_capacity: uint = 32u; // 2^5
 
@@ -114,7 +106,7 @@ mod chained {
         mut chains: ~[mut Option<@Entry<K,V>>]
     }
 
-    type T<K:Eq IterBytes Hash, V> = @HashMap_<K, V>;
+    pub type T<K:Eq IterBytes Hash, V> = @HashMap_<K, V>;
 
     enum SearchResult<K, V> {
         NotFound,
@@ -209,7 +201,7 @@ mod chained {
     impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V>: Map<K, V> {
         pure fn size() -> uint { self.count }
 
-        fn contains_key(+k: K) -> bool {
+        fn contains_key(k: K) -> bool {
             self.contains_key_ref(&k)
         }
 
@@ -221,7 +213,7 @@ mod chained {
             }
         }
 
-        fn insert(+k: K, +v: V) -> bool {
+        fn insert(k: K, +v: V) -> bool {
             let hash = k.hash_keyed(0,0) as uint;
             match self.search_tbl(&k, hash) {
               NotFound => {
@@ -263,7 +255,7 @@ mod chained {
             }
         }
 
-        pure fn find(+k: K) -> Option<V> {
+        pure fn find(k: K) -> Option<V> {
             unsafe {
                 match self.search_tbl(&k, k.hash_keyed(0,0) as uint) {
                   NotFound => None,
@@ -273,7 +265,7 @@ mod chained {
             }
         }
 
-        fn get(+k: K) -> V {
+        fn get(k: K) -> V {
             let opt_v = self.find(k);
             if opt_v.is_none() {
                 fail fmt!("Key not found in table: %?", k);
@@ -281,7 +273,7 @@ mod chained {
             option::unwrap(move opt_v)
         }
 
-        fn remove(+k: K) -> bool {
+        fn remove(k: K) -> bool {
             match self.search_tbl(&k, k.hash_keyed(0,0) as uint) {
               NotFound => false,
               FoundFirst(idx, entry) => {
@@ -302,15 +294,15 @@ mod chained {
             self.chains = chains(initial_capacity);
         }
 
-        pure fn each(blk: fn(+key: K, +value: V) -> bool) {
+        pure fn each(blk: fn(key: K, +value: V) -> bool) {
             self.each_ref(|k, v| blk(*k, *v))
         }
 
-        pure fn each_key(blk: fn(+key: K) -> bool) {
+        pure fn each_key(blk: fn(key: K) -> bool) {
             self.each_key_ref(|p| blk(*p))
         }
 
-        pure fn each_value(blk: fn(+value: V) -> bool) {
+        pure fn each_value(blk: fn(value: V) -> bool) {
             self.each_value_ref(|p| blk(*p))
         }
 
@@ -356,7 +348,7 @@ mod chained {
     }
 
     impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V>: ops::Index<K, V> {
-        pure fn index(&&k: K) -> V {
+        pure fn index(+k: K) -> V {
             unsafe {
                 self.get(k)
             }
@@ -367,7 +359,7 @@ mod chained {
         vec::to_mut(vec::from_elem(nchains, None))
     }
 
-    fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
+    pub fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
         let slf: T<K, V> = @HashMap_ {count: 0u,
                                       chains: chains(initial_capacity)};
         slf
@@ -379,18 +371,18 @@ Function: hashmap
 
 Construct a hashmap.
 */
-fn HashMap<K:Eq IterBytes Hash Const, V: Copy>()
+pub fn HashMap<K:Eq IterBytes Hash Const, V: Copy>()
         -> HashMap<K, V> {
     chained::mk()
 }
 
 /// Convenience function for adding keys to a hashmap with nil type keys
-fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, +key: K) -> bool {
+pub fn set_add<K:Eq IterBytes Hash Const Copy>(set: Set<K>, key: K) -> bool {
     set.insert(key, ())
 }
 
 /// Convert a set into a vector.
-fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
+pub fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
     do vec::build_sized(s.size()) |push| {
         for s.each_key() |k| {
             push(k);
@@ -399,12 +391,12 @@ fn vec_from_set<T:Eq IterBytes Hash Copy>(s: Set<T>) -> ~[T] {
 }
 
 /// Construct a hashmap from a vector
-fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
+pub fn hash_from_vec<K: Eq IterBytes Hash Const Copy, V: Copy>(
     items: &[(K, V)]) -> HashMap<K, V> {
     let map = HashMap();
     for vec::each(items) |item| {
         match *item {
-            (key, value) => {
+            (copy key, copy value) => {
                 map.insert(key, value);
             }
         }
@@ -423,13 +415,13 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    fn insert(+key: K, +value: V) -> bool {
+    fn insert(key: K, value: V) -> bool {
         do self.borrow_mut |p| {
             p.insert(key, value)
         }
     }
 
-    fn contains_key(+key: K) -> bool {
+    fn contains_key(key: K) -> bool {
         do self.borrow_const |p| {
             p.contains_key(&key)
         }
@@ -441,13 +433,13 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    fn get(+key: K) -> V {
+    fn get(key: K) -> V {
         do self.borrow_const |p| {
             p.get(&key)
         }
     }
 
-    pure fn find(+key: K) -> Option<V> {
+    pure fn find(key: K) -> Option<V> {
         unsafe {
             do self.borrow_const |p| {
                 p.find(&key)
@@ -455,7 +447,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    fn remove(+key: K) -> bool {
+    fn remove(key: K) -> bool {
         do self.borrow_mut |p| {
             p.remove(&key)
         }
@@ -467,7 +459,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    pure fn each(op: fn(+key: K, +value: V) -> bool) {
+    pure fn each(op: fn(key: K, +value: V) -> bool) {
         unsafe {
             do self.borrow_imm |p| {
                 p.each(|k, v| op(*k, *v))
@@ -475,7 +467,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    pure fn each_key(op: fn(+key: K) -> bool) {
+    pure fn each_key(op: fn(key: K) -> bool) {
         unsafe {
             do self.borrow_imm |p| {
                 p.each_key(|k| op(*k))
@@ -483,7 +475,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
         }
     }
 
-    pure fn each_value(op: fn(+value: V) -> bool) {
+    pure fn each_value(op: fn(value: V) -> bool) {
         unsafe {
             do self.borrow_imm |p| {
                 p.each_value(|v| op(*v))
@@ -518,7 +510,6 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
 
 #[cfg(test)]
 mod tests {
-    #[legacy_exports];
 
     #[test]
     fn test_simple() {