[Issue 9842] std.algorithm.hashGroup / hashGroupBy

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 5 02:01:42 PST 2014


https://issues.dlang.org/show_bug.cgi?id=9842

--- Comment #2 from bearophile_hugs at eml.cc ---
(In reply to hsteoh from comment #1)
> Isn't this just the same as data.hashSort.group? For hash sort to work, the
> key must map to an integral value and must be bounded by known min/max
> values.

The output and working is different. The hashGroupBy doesn't return a range of
pairs as the function "group".

If you write:

auto names = ["Sam", "Samuel", "Samu", "Ravi", "Ratna", "Barsha"];
auto grps = names.hashGroupBy!(n => n.length);

Now grps is:

assert(grps == [3:["Sam"], 4:["Samu", "Ravi"], 5:["Ratna"], 6:["Samuel",
"Barsha"]]);

The keys can be anything, not just integers in an interval.

--


More information about the Digitalmars-d-bugs mailing list