Skip to content

Commit 3c48759

Browse files
committed
Added a method to convert sets to vectors.
1 parent aec0b51 commit 3c48759

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libstd/map.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
55
export bytes_hash, int_hash, uint_hash, set_add;
66
export hash_from_vec, hash_from_strs, hash_from_bytes;
77
export hash_from_ints, hash_from_uints;
8+
export vec_from_set;
89

910
#[doc = "
1011
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
331332
"]
332333
fn set_add<K: copy>(set: set<K>, key: K) -> bool { ret set.insert(key, ()); }
333334

335+
#[doc = "
336+
Convert a set into a vector.
337+
"]
338+
fn vec_from_set<T: copy>(s: set<T>) -> [T] {
339+
let mut v = [];
340+
s.each_key() {|k|
341+
v += [k];
342+
true
343+
};
344+
v
345+
}
346+
334347
#[doc = "Construct a hashmap from a vector"]
335348
fn hash_from_vec<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>,
336349
items: [(K, V)]) -> hashmap<K, V> {

0 commit comments

Comments
 (0)