www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1429] New: Equality for associative arrays doesn't work

reply d-bugmail puremagic.com writes:
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?


-- 
Aug 18 2007
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<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.)
Aug 18 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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.


-- 
Aug 24 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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?


-- 
Oct 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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) --
Oct 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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'. --
Oct 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Jun 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Aug 25 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Feb 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Feb 19 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1429


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #9 from Don <clugdbug yahoo.com.au> 2010-05-10 14:41:12 PDT ---
Fixed DMD1.057 and DMD2.041.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10 2010