Added a method to convert sets to vectors.
This commit is contained in:
parent
aec0b51d9c
commit
3c48759a56
1 changed files with 13 additions and 0 deletions
|
@ -5,6 +5,7 @@ export hashmap, hashfn, eqfn, set, map, chained, hashmap, str_hash;
|
||||||
export bytes_hash, int_hash, uint_hash, set_add;
|
export bytes_hash, int_hash, uint_hash, set_add;
|
||||||
export hash_from_vec, hash_from_strs, hash_from_bytes;
|
export hash_from_vec, hash_from_strs, hash_from_bytes;
|
||||||
export hash_from_ints, hash_from_uints;
|
export hash_from_ints, hash_from_uints;
|
||||||
|
export vec_from_set;
|
||||||
|
|
||||||
#[doc = "
|
#[doc = "
|
||||||
A function that returns a hash of a value
|
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, ()); }
|
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"]
|
#[doc = "Construct a hashmap from a vector"]
|
||||||
fn hash_from_vec<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>,
|
fn hash_from_vec<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>,
|
||||||
items: [(K, V)]) -> hashmap<K, V> {
|
items: [(K, V)]) -> hashmap<K, V> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue