Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mw66 opened this issue Jan 6, 2021 · 2 comments

Comments

@mw66
Copy link

mw66 commented Jan 6, 2021

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

bool insert(T value)

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 mw66 changed the title feature request: hashset.insert(range!T inputs) feature request: hashset.insert(range!T inputs), i.e. add multiple elements in one call Jan 6, 2021
@rikkimax
Copy link

rikkimax commented Mar 5, 2021

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.

@CyberShadow
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants