[Issue 6718] New: "nWayUnion" => "nWayMerge", plus true nWayUnion
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 22 14:44:51 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6718
Summary: "nWayUnion" => "nWayMerge", plus true nWayUnion
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-09-22 14:44:22 PDT ---
This is a bug report plus an optional enhancement request.
In std.algorithm there is a section of set functions that work on ordered
iterables, like nWayUnion:
http://www.d-programming-language.org/phobos/std_algorithm.html#nWayUnion
This is an example of nWayUnion usage:
import std.algorithm;
void main() {
auto data = [[1, 2, 3], [1, 3, 5]];
auto expected = [1, 1, 2, 3, 3, 5];
assert(equal(nWayUnion(data), expected));
}
But this is not a set operation, and the result is not a set. A set never
contains repeated items (a certain definition of "duplication" is possible only
if you define your own equality relation).
So in my opinion a nWayUnion function has to return:
auto data = [[1, 2, 3], [1, 3, 5]];
auto expected = [1, 2, 3, 5];
assert(equal(nWayUnion(data), expected));
While the current nWayUnion function has to be renamed "nWayMerge".
auto data = [[1, 2, 3], [1, 3, 5]];
auto expected = [1, 1, 2, 3, 3, 5];
assert(equal(nWayMerge(data), expected));
In my opinion both nWayUnion and nWayMerge are very useful operations useful in
various situations, but they are different things. In my opinion confusing the
two leads to bugs in programs that use arrays to represent sets (I have just
hit a but caused by this).
nWayUnion is probably uniq(nWayMerge). If you don't want to add the "nWayUnion"
function, then I suggest to just rename "nWayUnion" => "nWayMerge" (and put it
outside the documentation section about set functions) to avoid some mistakes.
Names are important, and classifications too.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list