diff options
| author | Graydon Hoare <[email protected]> | 2010-08-24 09:59:02 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-24 09:59:02 -0700 |
| commit | 47501f16596d2eaac9ce1a27b43b386b8496c66f (patch) | |
| tree | ad7841880efbd68e14a109942b01224525bc9c07 /src/lib/_str.rs | |
| parent | Make error reporting slightly more regular. (diff) | |
| download | rust-47501f16596d2eaac9ce1a27b43b386b8496c66f.tar.xz rust-47501f16596d2eaac9ce1a27b43b386b8496c66f.zip | |
Make _str.eq suitable for map.hashmap; add _str.hash that does simple djb-hash.
Diffstat (limited to 'src/lib/_str.rs')
| -rw-r--r-- | src/lib/_str.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lib/_str.rs b/src/lib/_str.rs index a29e1daa..751d79cf 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -11,7 +11,7 @@ native "rust" mod rustrt { fn refcount[T](str s) -> uint; } -fn eq(str a, str b) -> bool { +fn eq(&str a, &str b) -> bool { let uint i = byte_len(a); if (byte_len(b) != i) { ret false; @@ -27,6 +27,17 @@ fn eq(str a, str b) -> bool { ret true; } +fn hash(&str s) -> uint { + // djb hash. + // FIXME: replace with murmur. + let uint u = 5381u; + for (u8 c in s) { + u *= 33u; + u += (c as uint); + } + ret u; +} + fn is_utf8(vec[u8] v) -> bool { fail; // FIXME } |