Testing map equality

rlbond86

Member
Is there a simple way to test if two maps are equal? The following command doesn't seem to work how I expected:

Code:
> ash int[int] a; int[int] b; b[1]=1; print(a==b);

true
Returned: void

I'm dealing with a multidimensional map, and short of checking every dimension recursively I can't really figure out a way of doing this. :confused:

EDIT:

Ok, so far the shortest thing I've come up with is

Code:
boolean isEqual(string[int][int][int] m1, string[int][int][int] m2)
{
    foreach a,b,c,d in m1
        if (m2[a][b][c] != d)
            return false;
    foreach a,b,c,d in m2
        if (m1[a][b][c] != d)
            return false;
    return true;
}

I'd be interested if anyone knows a better way :p
 
Last edited:

Fluxxdog

Active member
Code:
boolean isEqual(string[int][int][int] m1, string[int][int][int] m2)
{
    if(m1.count()!=m2.count()) return false;
    foreach a,b,c,d in m1
        if (m2[a][b][c] != d)
            return false;
    foreach a,b,c,d in m2
        if (m1[a][b][c] != d)
            return false;
    return true;
}
If they're not the same size, they're already not equal. This can speed up the process considerably.
 
Top