Added a method to convert sets to vectors.
This commit is contained in:
parent
aec0b51d9c
commit
3c48759a56
@ -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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user