Jump to page: 1 2
Thread overview
[Issue 1429] New: Equality for associative arrays doesn't work
Aug 18, 2007
d-bugmail
Aug 25, 2007
d-bugmail
Oct 11, 2007
d-bugmail
Oct 11, 2007
d-bugmail
Oct 11, 2007
d-bugmail
Jun 21, 2009
Christian Kamm
Aug 25, 2009
Stewart Gordon
Feb 19, 2010
Alexey Ivanov
May 10, 2010
Don
August 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1429

           Summary: Equality for associative arrays doesn't work
           Product: D
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X
            Status: NEW
          Keywords: spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: josh@besquared.net


Sample code below along with a basic equals implementation to show they are equal in content.

import std.stdio;

bool equals(T, U)(T[U] container, T[U] other) {
        T[U] tmp = container;
        foreach(U key, T value; other) {
                if(!(key in container && value == container[key])) {
                        return false;
                }
        }
        return true;
}

void main() {
        int[char[]] a = ["hello"[]:1, "test"[]:2];
        int[char[]] b = ["hello"[]:1, "test"[]:2];

        writefln( a == a ); //=> true
        writefln( a == b ); //=> false
        writefln( a.equals(b) ); //=> true

        writefln( ["hello"[]:1, "test"[]:2] == ["hello"[]:1, "test"[]:2] );
//=> false
        writefln( ["hello"[]:1, "test"[]:2].equals(["hello"[]:1, "test"[]:2])
); //=> true

        writefln( a is a ); //=> obviously true
        writefln( a is b ); //=> obviously false just checking
}

looks like equality is linked with identity. Is this a bug?


-- 

August 18, 2007
<d-bugmail@puremagic.com> wrote in message news:bug-1429-3@http.d.puremagic.com/issues/...
>
> looks like equality is linked with identity. Is this a bug?
>

Either that or it's just plain undefined.  If you consider an AA reference as a simple pointer, then 'is' and '==' meaning the same thing make complete sense.  (This is probably what the compiler does.)


August 25, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1429


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Keywords|                            |wrong-code




------- Comment #1 from smjg@iname.com  2007-08-24 19:27 -------
BTW there's a bug in your equals implementation: it ignores keys that are in container but not in other.  The easiest way to fix ti is to add this at the beginning of the function:

    if (container.length != other.length) return false;

What is tmp for?  Your code doesn't use it at all.


-- 

October 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1429





------- Comment #2 from smjg@iname.com  2007-10-11 15:14 -------
Since when has DMD for Mac OS X existed?


-- 

October 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1429





------- Comment #3 from fvbommel@wxs.nl  2007-10-11 15:42 -------
(In reply to comment #2)
> Since when has DMD for Mac OS X existed?

I'd guess since about the time Wine started supporting Intel Macs :P (Theoretically, I haven't heard of anyone running such a setup)


-- 

October 11, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1429





------- Comment #4 from fvbommel@wxs.nl  2007-10-11 15:44 -------
(In reply to comment #3)
> (In reply to comment #2)
> > Since when has DMD for Mac OS X existed?
> 
> I'd guess since about the time Wine started supporting Intel Macs :P (Theoretically, I haven't heard of anyone running such a setup)

Alternatively, this is a bug in the frontend that was reported from a Mac, and the submitter forgot to set the OS box to 'All'.


-- 

June 21, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1429


Christian Kamm <kamm-removethis@incasoftware.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kamm-removethis@incasoftwar
                   |                            |e.de




--- Comment #5 from Christian Kamm <kamm-removethis@incasoftware.de>  2009-06-21 10:16:23 PDT ---
Fixed in LDC by http://www.dsource.org/projects/ldc/changeset/1512 . The spec could be fixed by adding

"Two associative arrays are equal if they have the same keys and the values of each key compare equal."

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1429





--- Comment #6 from Stewart Gordon <smjg@iname.com>  2009-08-25 10:55:25 PDT ---
(In reply to comment #5)
> Fixed in LDC by http://www.dsource.org/projects/ldc/changeset/1512 . The spec could be fixed by adding
> 
> "Two associative arrays are equal if they have the same keys and the values of each key compare equal."

Shouldn't it care about the value _associated with_ each key, rather than just the value _of_ each key?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1429


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #7 from bearophile_hugs@eml.cc 2010-02-19 02:24:03 PST ---
Probably fixed here: http://dsource.org/projects/dmd/changeset/389

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1429


Alexey Ivanov <aifgi90@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aifgi90@gmail.com


--- Comment #8 from Alexey Ivanov <aifgi90@gmail.com> 2010-02-19 07:15:14 PST ---
http://dsource.org/projects/dmd/changeset/389 and http://dsource.org/projects/druntime/changeset/246

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2