From c1fad0775844a9413484fd2eaa10adcfdfbc2883 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 14 Aug 2012 16:45:00 -0700 Subject: [PATCH] Add a map::str_slice_map constructor to libstd. --- src/libcore/str.rs | 1 + src/libstd/map.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 8584d4f1524a..5c02571ef978 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -54,6 +54,7 @@ export // Comparing strings eq, + eq_slice, le, hash, diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 071ef5952e00..699cf7a66e95 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -389,6 +389,12 @@ fn hashmap(+hasher: hashfn, +eqer: eqfn) chained::mk(hasher, eqer) } +/// Construct a hashmap for string-slice keys +fn str_slice_hash() -> 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() -> hashmap<~str, V> { return hashmap(str::hash, str::eq);