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

Helper function on SetHashes #35

Closed
lizmat opened this issue Jun 1, 2019 · 7 comments
Closed

Helper function on SetHashes #35

lizmat opened this issue Jun 1, 2019 · 7 comments
Assignees
Labels
language Changes to the Raku Programming Language

Comments

@lizmat
Copy link
Collaborator

lizmat commented Jun 1, 2019

See rakudo/rakudo#2942

Perhaps similar helper functions could be useful on BagHashes (and MixHashes?) as well. But probably should then be called .add and .subtract

@AlexDaniel AlexDaniel added the language Changes to the Raku Programming Language label Jun 1, 2019
@AlexDaniel
Copy link
Member

AlexDaniel commented Jun 1, 2019

%sethash{$_} = True for @to-be-added;
%sethash.set(@to-be-added);

I don't think we should be adding stuff purely for speed reasons when other ways of doing the same thing are not ironed out in terms of performance.

For example, I can see other ways of doing the same thing. Like:

%sethash{@to-be-added} X= True;

Which is currently much slower, but there has to be a way to make it as fast as the proposed .set() method, right?

Also, it seems that good performance is already achievable with something like this:

%sethash ,= SetHash.new(@to-be-added);

Although I'm not sure if it is fully identical to the proposed .set method, and if it is as fast?

Edit: more stuff

@lizmat
Copy link
Collaborator Author

lizmat commented Jun 1, 2019

my @a = ^10; my %s is SetHash; %s ,= SetHash.new(@a); dd %s.elems   # 2

That should have been 10. You get a SetHash with itself, and the new SetHash. Which, incidentally, infiniloops on .gist or .perl :-(

@lizmat
Copy link
Collaborator Author

lizmat commented Jun 1, 2019

Some benchmarks / readability comparison:

$ 6 'my @a = ^100000; { my %s is SetHash; %s{$_} = True for @a; say now - ENTER now }'
0.5418981

$ 6 'my @a = ^100000; { my %s is SetHash; %s{@a} = True xx *; say now - ENTER now }'
0.5311904

$ 6 'my @a = ^100000; { my %s is SetHash; %s.set(@a); say now - ENTER now }'
0.11501774

@vrurg
Copy link
Contributor

vrurg commented Nov 27, 2019

@lizmat what is the current status of this? Is it still planned?

@lizmat
Copy link
Collaborator Author

lizmat commented Nov 27, 2019

I guess either it is up to @jnthn to decide, or we need to take a vote on it?

The conflicts should be easy to resolve.

@vrurg
Copy link
Contributor

vrurg commented Nov 27, 2019

That's a question. We can't rely upon Jonathan on each end every case. As it was said, he is a scarce resource. But we probably need a collective decision making procedure. I'd try to think out something on this.

@jnthn
Copy link
Contributor

jnthn commented Nov 28, 2019

We can't rely upon Jonathan on each end every case

No, but language design things probably are one of the things I can most usefully opine on. Design by what can win a vote isn't going to produce much consistency.

Some questions:

  1. Were push and append considered? For example, we have Hash.push and Hash.append, which seem to be in this very space, but not on SetHash etc.
  2. I wonder if we're missing a "single argument rule" style thing here, so that ∪= could potentially do the job.

@lizmat lizmat closed this as completed May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

4 participants