Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finishing touches

  • Loading branch information...
commit 5da471f17a3c5123bb0b5e2985593589b472fbd7 1 parent 93bf6e4
Paul Woolcock authored
Showing with 9 additions and 29 deletions.
  1. +2 −2 levenshtein.rc
  2. +7 −27 levenshtein.rs
4 levenshtein.rc
View
@@ -1,9 +1,9 @@
#[link(name="levenshtein",
vers="0.1",
+ url="https://github.com/pwoolcoc/rust-levenshtein.git",
uuid="580f87d6-067c-4a96-9dce-cf5b8ff86f58")];
#[crate_type = "lib"];
-extern mod std;
-export levenshtein;
+pub mod levenshtein;
34 levenshtein.rs
View
@@ -1,12 +1,12 @@
-use std::map::hashmap;
-use std::time;
+extern mod std;
+use std::map::HashMap;
use option::{Some,None};
export edit_distance;
export edit_distance_str;
fn minimum(args: ~[uint]) -> uint {
- vec::foldl(uint::max_value, args, |a, b| {uint::min(a, b)})
+ vec::foldl(uint::max_value, args, |a, b| uint::min(a, *b))
}
fn tail(s: ~str) -> ~str {
@@ -21,15 +21,15 @@ fn head(s: ~str) -> ~str {
}
}
-fn edit_distance(s: ~[u8], t: ~[u8]) -> uint {
+pub fn edit_distance(s: ~[u8], t: ~[u8]) -> uint {
edit_distance_str(str::from_bytes(s), str::from_bytes(t))
}
-fn edit_distance_str(s: ~str, t: ~str) -> uint {
- _edit_distance_str(s, t, hashmap())
+pub fn edit_distance_str(s: ~str, t: ~str) -> uint {
+ _edit_distance_str(s, t, HashMap())
}
-fn _edit_distance_str(s: ~str, t: ~str, table: hashmap<~str, uint>) -> uint {
+fn _edit_distance_str(s: ~str, t: ~str, table: HashMap<~str, uint>) -> uint {
match table.find(s + t) {
Some(value) => { value }
None => {
@@ -59,14 +59,6 @@ fn _edit_distance_str(s: ~str, t: ~str, table: hashmap<~str, uint>) -> uint {
}
-fn time_me (blk: fn() -> ()) -> float {
- let before = time::precise_time_s();
- blk();
- let after = time::precise_time_s();
- after - before
-}
-
-
#[test]
fn test_distance() {
let s = ~"kitten";
@@ -74,15 +66,3 @@ fn test_distance() {
assert edit_distance_str(s, t) == 3;
}
-#[test]
-fn test_timing() {
- let s = ~"kitten";
- let t = ~"sitting";
- let runtime = time_me(|| {
- for iter::repeat(10) {
- assert edit_distance_str(s,t) == 3;
- }
- });
- io::println(fmt!("total time: %f", runtime));
-}
-
Please sign in to comment.
Something went wrong with that request. Please try again.