Make _str.eq suitable for map.hashmap; add _str.hash that does simple djb-hash.
This commit is contained in:
parent
10316fbfa5
commit
47501f1659
1 changed files with 12 additions and 1 deletions
|
@ -11,7 +11,7 @@ native "rust" mod rustrt {
|
||||||
fn refcount[T](str s) -> uint;
|
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);
|
let uint i = byte_len(a);
|
||||||
if (byte_len(b) != i) {
|
if (byte_len(b) != i) {
|
||||||
ret false;
|
ret false;
|
||||||
|
@ -27,6 +27,17 @@ fn eq(str a, str b) -> bool {
|
||||||
ret true;
|
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 {
|
fn is_utf8(vec[u8] v) -> bool {
|
||||||
fail; // FIXME
|
fail; // FIXME
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue