containers icon indicating copy to clipboard operation
containers copied to clipboard

feature request: hashset.insert(range!T inputs), i.e. add multiple elements in one call

Open mw66 opened this issue 3 years ago • 2 comments

currently, hashset can only insert one element at a time:

https://github.com/dlang-community/containers/blob/fc1625a5a0c253272b80addfb4107928495fd647/src/containers/hashset.d#L150

HashSet!string set;
set.insert("foo");
set.insert("bar");

Can we add another method, so we can insert multiple elements all at once? e.g.

set.insert(["foo", "bar", "foo"]);

Thanks.

mw66 avatar Jan 06 '21 18:01 mw66

If insert is changed to have the prototype: bool insert(scope T[] values...) it will work as is and won't require changing.

However the return type is a bit tricky. There no way to know which values failed.

rikkimax avatar Mar 05 '21 17:03 rikkimax

In case of HashSet, I think this wouldn't be any more efficient than inserting them one by one.

I would suggest using each.

Maybe more useful would be to have a constructor which accepts a range, similar to assocArray.

CyberShadow avatar Sep 18 '21 11:09 CyberShadow