diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-10-27 17:03:38 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-10-27 17:03:38 -0700 |
| commit | 506ae934f808c2cf664f289dc29f7e90d253a454 (patch) | |
| tree | 9a5814dd9efe391b420d8dbeb1752f8105fdffce | |
| parent | 2b85817af8bc4bdfbb155f15367c3ebee09eb743 (diff) | |
Reorder std::vec so the documentation renders better
Put all types first, then predicates, then functions
| -rw-r--r-- | src/lib/vec.rs | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 3763a13a37a..fd6e594e1ad 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -20,6 +20,41 @@ native "c-stack-cdecl" mod rustrt { } /* +Type: init_op + +A function used to initialize the elements of a vector. +*/ +type init_op<T> = block(uint) -> T; + + +/* +Predicate: is_empty + +Returns true if a vector contains no elements. +*/ +pure fn is_empty<T>(v: [mutable? T]) -> bool { + // FIXME: This would be easier if we could just call len + for t: T in v { ret false; } + ret true; +} + +/* +Predicate: is_not_empty + +Returns true if a vector contains some elements. +*/ +pure fn is_not_empty<T>(v: [mutable? T]) -> bool { ret !is_empty(v); } + +/* +Predicate: same_length + +Returns true if two vectors have the same length +*/ +pure fn same_length<T, U>(xs: [T], ys: [U]) -> bool { + vec::len(xs) == vec::len(ys) +} + +/* Function: reserve Reserves capacity for `n` elements in the given vector. @@ -44,13 +79,6 @@ Returns the length of a vector pure fn len<T>(v: [mutable? T]) -> uint { unchecked { rusti::vec_len(v) } } /* -Type: init_op - -A function used to initialize the elements of a vector. -*/ -type init_op<T> = block(uint) -> T; - -/* Function: init_fn Creates and initializes an immutable vector. @@ -141,24 +169,6 @@ fn from_mut<T>(v: [mutable T]) -> [T] { ret vres; } -/* -Predicate: is_empty - -Returns true if a vector contains no elements. -*/ -pure fn is_empty<T>(v: [mutable? T]) -> bool { - // FIXME: This would be easier if we could just call len - for t: T in v { ret false; } - ret true; -} - -/* -Predicate: is_not_empty - -Returns true if a vector contains some elements. -*/ -pure fn is_not_empty<T>(v: [mutable? T]) -> bool { ret !is_empty(v); } - // Accessors /* @@ -519,15 +529,6 @@ fn position_pred<T>(f: block(T) -> bool, v: [T]) -> option::t<uint> { ret none; } -/* -Predicate: same_length - -Returns true if two vectors have the same length -*/ -pure fn same_length<T, U>(xs: [T], ys: [U]) -> bool { - vec::len(xs) == vec::len(ys) -} - // FIXME: if issue #586 gets implemented, could have a postcondition // saying the two result lists have the same length -- or, could // return a nominal record with a constraint saying that, instead of |
