Add a map::str_slice_map constructor to libstd.

This commit is contained in:
Graydon Hoare 2012-08-14 16:45:00 -07:00
parent 958df4b003
commit c1fad07758
2 changed files with 7 additions and 0 deletions

View File

@ -54,6 +54,7 @@ export
// Comparing strings
eq,
eq_slice,
le,
hash,

View File

@ -389,6 +389,12 @@ fn hashmap<K: const, V: copy>(+hasher: hashfn<K>, +eqer: eqfn<K>)
chained::mk(hasher, eqer)
}
/// Construct a hashmap for string-slice keys
fn str_slice_hash<V: copy>() -> hashmap<&str, V> {
return hashmap(|s| hash::hash_str(*s) as uint,
|a,b| str::eq_slice(*a, *b));
}
/// Construct a hashmap for string keys
fn str_hash<V: copy>() -> hashmap<~str, V> {
return hashmap(str::hash, str::eq);