about summary refs log tree commit diff
path: root/src/lib/smallintmap.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-10-26 16:24:31 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-26 18:32:34 -0700
commit4d669036f3264403f1663b14997a1e30db7b7e73 (patch)
tree1d232920316333cbf8ccb287cf29f9756b60a3be /src/lib/smallintmap.rs
parent1b75e5c315f00e6a10b1eca0a2f501107fd8063e (diff)
downloadrust-4d669036f3264403f1663b14997a1e30db7b7e73.tar.gz
rust-4d669036f3264403f1663b14997a1e30db7b7e73.zip
Add more std documentation
Diffstat (limited to 'src/lib/smallintmap.rs')
-rw-r--r--src/lib/smallintmap.rs44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/lib/smallintmap.rs b/src/lib/smallintmap.rs
index b70c03ad1d5..f9e59820294 100644
--- a/src/lib/smallintmap.rs
+++ b/src/lib/smallintmap.rs
@@ -1,27 +1,58 @@
+/*
+Module: smallintmap
 
-
-/// A simple map based on a vector for small integer keys. Space requirements
-/// are O(highest integer key).
+A simple map based on a vector for small integer keys. Space requirements
+are O(highest integer key).
+*/
 import option::{some, none};
 
 // FIXME: Should not be @; there's a bug somewhere in rustc that requires this
 // to be.
+/*
+Type: smallintmap
+*/
 type smallintmap<T> = @{mutable v: [mutable option::t<T>]};
 
+/*
+Function: mk
+
+Create a smallintmap
+*/
 fn mk<T>() -> smallintmap<T> {
     let v: [mutable option::t<T>] = [mutable];
     ret @{mutable v: v};
 }
 
+/*
+Function: insert
+
+Add a value to the map. If the map already contains a value for
+the specified key then the original value is replaced.
+*/
 fn insert<T>(m: smallintmap<T>, key: uint, val: T) {
     vec::grow_set::<option::t<T>>(m.v, key, none::<T>, some::<T>(val));
 }
 
+/*
+Function: find
+
+Get the value for the specified key. If the key does not exist
+in the map then returns none.
+*/
 fn find<T>(m: smallintmap<T>, key: uint) -> option::t<T> {
     if key < vec::len::<option::t<T>>(m.v) { ret m.v[key]; }
     ret none::<T>;
 }
 
+/*
+Method: get
+
+Get the value for the specified key
+
+Failure:
+
+If the key does not exist in the map
+*/
 fn get<T>(m: smallintmap<T>, key: uint) -> T {
     alt find::<T>(m, key) {
       none::<T>. { log_err "smallintmap::get(): key not present"; fail; }
@@ -29,10 +60,17 @@ fn get<T>(m: smallintmap<T>, key: uint) -> T {
     }
 }
 
+/*
+Method: contains_key
+
+Returns true if the map contains a value for the specified key
+*/
 fn contains_key<T>(m: smallintmap<T>, key: uint) -> bool {
     ret !option::is_none(find::<T>(m, key));
 }
 
+// FIXME: Are these really useful?
+
 fn truncate<T>(m: smallintmap<T>, len: uint) {
     m.v = vec::slice_mut::<option::t<T>>(m.v, 0u, len);
 }