about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-07-12 17:00:25 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-07-12 17:00:44 -0700
commit032c4deefee8afcb55fb4ce0e82090776d297b50 (patch)
tree8c7c563e8af1164e2a01f77708e48b95aab6f2b5 /src/lib
parentb97318bb80121388909cc9c55ff7465664c4845d (diff)
downloadrust-032c4deefee8afcb55fb4ce0e82090776d297b50.tar.gz
rust-032c4deefee8afcb55fb4ce0e82090776d297b50.zip
stdlib: Implement ivec::count
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ivec.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/lib/ivec.rs b/src/lib/ivec.rs
index 6e32901a437..6101163d32d 100644
--- a/src/lib/ivec.rs
+++ b/src/lib/ivec.rs
@@ -208,6 +208,12 @@ fn member[T](&T x, &T[] v) -> bool {
     ret false;
 }
 
+fn count[T](&T x, &T[mutable?] v) -> uint {
+    auto cnt = 0u;
+    for (T elt in v) { if (x == elt) { cnt += 1u; } }
+    ret cnt;
+}
+
 fn find[T](fn(&T) -> bool  f, &T[] v) -> option::t[T] {
     for (T elt in v) { if (f(elt)) { ret some[T](elt); } }
     ret none[T];