diff options
| author | Eric Holk <eric.holk@gmail.com> | 2012-05-16 15:45:06 -0700 |
|---|---|---|
| committer | Eric Holk <eric.holk@gmail.com> | 2012-05-17 12:00:50 -0700 |
| commit | 3c48759a56a16c7f30f98232f9035cc0219f8f30 (patch) | |
| tree | 0cb01d5dc083e847140c3025415e2fb59bafde61 /src/libstd/map.rs | |
| parent | aec0b51d9cca576b38023c4f8a11f28452ea8d55 (diff) | |
Added a method to convert sets to vectors.
Diffstat (limited to 'src/libstd/map.rs')
| -rw-r--r-- | src/libstd/map.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstd/map.rs b/src/libstd/map.rs index f797ffeff76..a72e87475b2 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -5,6 +5,7 @@ export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash; export bytes_hash, int_hash, uint_hash, set_add; export hash_from_vec, hash_from_strs, hash_from_bytes; export hash_from_ints, hash_from_uints; +export vec_from_set; #[doc = " A function that returns a hash of a value @@ -331,6 +332,18 @@ Convenience function for adding keys to a hashmap with nil type keys "] fn set_add<K: copy>(set: set<K>, key: K) -> bool { ret set.insert(key, ()); } +#[doc = " +Convert a set into a vector. +"] +fn vec_from_set<T: copy>(s: set<T>) -> [T] { + let mut v = []; + s.each_key() {|k| + v += [k]; + true + }; + v +} + #[doc = "Construct a hashmap from a vector"] fn hash_from_vec<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>, items: [(K, V)]) -> hashmap<K, V> { |
