jonhoo / hashbag

An unordered multiset/bag implementation backed by HashMap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to turn a (T, usize) collection into a HashBag?

myarcana opened this issue · comments

let mut bag = HashBag::new();
bag.insert("a");
bag.insert("b");
bag.insert("b");

let bag_as_vec = bag.set_iter().collect::<Vec<(&&str, usize)>>();

Is there a way to turn bag_as_vec back into a HashBag?

And how about for collections or iterators in general with types like Vec<T, usize> (that didn't come from HashBag::SetIter) ?

HashBag implements Extend<(T, usize)>, so you should be able to just:

let mut bag = HashBag::new();
bag.extend(bag_as_vec);