equality

Two .net objects that are equal don't say they are

I have a the following code: object val1 = 1; object val2 = 1; bool result1 = (val1 == val2);//Equals false bool result2 = val1.Equals(val2); //Equals true What's up with that? is the only way to fix this to go with .Equals() method? ...

Why is this variable being changed?

tokens_raw = {"foo": "bar"} tokens_raw_old = { } while not tokens_raw == tokens_raw_old: tokens_raw_old = tokens_raw # while loop that modifies tokens_raw goes here; # tokens_raw_old is never referenced print tokens_raw_old == tokens_raw This outputs True after the first time for some reason. tokens_raw_old has the same...

Struggling to get '==' operator overloading to work (C++).

Okay, not sure what I'm doing here, other than it's not right. Trying to overload the '==' method of a class, and it's just... not working. At least, I get a false back from my main, and the cout in the implementation of '==' doesnt output. These are my three files: // TestClass.h #ifndef TESTCLASS_H #define TESTCLASS_H class TestCla...

Transitivity relationship: What is x.equals(z) when x.equals(y) is false and y.equals(z) is true

Assuming equals() is transitive; I understand that if x and y, have a bilateral agreement of being equal, then one of them, say y, does not enter into an agreement with a third class z on its own. But if we have a situation where x.equals(y) = false (still transitive) then what should this bilateral agreement with z be? ...

Java: Test for duplicate Objects in a Collection

Given a List of MyClass objects (and a custom Comparitor myComparitor if needed), what good options are there for checking if the List contains two "equal" objects? Edit: if there are duplicates, return a reference to one or more of the duplicates. Overriding MyClass.equals(MyClass) in this case is not an option. My initial thought is...

Equality with CoreData string attribute not working

Hello, I can't see why this isn't working. I have two entities, let's call them Employees and Departments. And Departments has a String attribute called division. This works perfectly: NSLog(@"Division: %@",employee.department.division); The console shows, let's say, "Worldwide Seafood". But if I attempt a comparison with the exac...

What problem does IStructuralEquatable and IStructuralComparable solve?

I've noticed these two interfaces, and several associated classes, have been added in .NET 4. They seem a bit superfluous to me; I've read several blogs about them, but I still can't figure out what problem they solve that was tricky before .NET 4. What use are IStructuralEquatable and IStructuralComparable? ...

HashSet equality c#

I have a HashSet with it's own EqualityComparer, but I am wondering if a simple count of both sets is used before checking each element? I thought I would be able to answer this for myself in Reflector but I couldn't find any override of Equals in there. Cheers, Berryl EDIT ========== As Hans noted, it it the comparison of two sets ...

Is there an API method that compares contents of a Seq irrespective of order?

Assuming: val l1 = List(1,2,3) val l2 = List(2,3,1) I want a method that confirms that l1 is equal to l2 (as in same contents but different order). Is there an API method on List/Seq to do this? l1.sameElements(l2) does not work as it verifies order as well. I've come up with the following: l1.foldLeft(l1.size == l2.size)(_ && l...

How do I check if two variables reference the same object in Python?

x and y are two variables. I can check if they're equal using x == y. But how can I check if they have the same identity? Example: x = [1, 2, 3] y = [1, 2, 3] Now x == y is True because x and y are equal. However, x and y aren't the same object. I'm looking for something like sameObject(x,y) which in that case is supposed to be False...

When is the `==` operator not equivalent to the `is` operator? (Python)

I noticed I can use the == operator to compare all the native data types (integers, strings, booleans, floating point numbers etc) and also lists, tuples, sets and dictionaries which contain native data types. In these cases the == operator checks if two objects are equal. But in some other cases (trying to compare instances of classes I...

Checking For Equal Instances of 2 Different (Included Example)

I use the == in the code below and prints out "Equals!", why? Can someone explain why these two different strings a and b are equal? public class test { public static void main() { String a = "boy"; String b = "boy"; if(a == b) { System.out.println("Equals!"); } else ...

Floating point comparison in VB6

What's the best way to test two Singles for equality in VB6? I want to test two Single values for equality to 7 significant figures. This MSDN article recommends using something like If Abs(a - b) <= Abs(a / 10 ^ 7) Then valuesEqual = True End If However, that can fail for certain values, e.g. Public Sub Main() Dim a As S...

Why doesn't the Array Equality Function Work as Expected?

In Programming in Scala the authors write that Scala's == function compares value equality instead of reference equality. This works as expected on lists: scala> List(1,2) == List(1,2) res0: Boolean = true It doesn't however work on arrays: scala> Array(1,2) == Array(1,2) res1: Boolean = false In Programming Scala the authors reco...

Does Java guarantee that Object.getClass() == Object.getClass()?

I really do mean identity-equality here. For example, will the following always print true. System.out.println("foo".getClass() == "fum".getClass()); Thanks in advance, ~Mack ...

Should you use 'isEqual' or '==' ?

Hey. I saw a couple of questions here on SO, with ansers including the function isEqual: instead of the standard ==. So far, I have only learned to use the ==, so I'm wondering what's better to use, what are the pros and cons of each? When should you use them? Thank you. ...

checking two object instances to see if they are the same

hi there i need to compare two objects but compare a number of their properties in one hit. this is not for sorting, but instead to confirm whether anything has changed; as one is the old saved instance, and the second is a newly imported instance of the same thing i assume this is best served by writing a custom comparer. just am a bi...

Testing for equality between dictionaries in c#

Assuming dictionary keys and values have their equals and hash methods implemented correctly, what is the most succinct and efficient way to test for equality of two dictionaries? In this context two dictionaries are said to be equal if they contain the same set of keys (order not important), and for every such key, they agree on the va...

Checking for equality in lists in SML

Hi there, i want to write a function that checks for equality of lists in SML for instance : [1,2,3]=[1,2,3]; val it = true : bool So instead of writing down the whole thing, i want to make a function that takes two predefined lists, and compare them, so that if list01 = [1,2,3] and list09 = [1,2,3] then fun equal (list01,list09); will ...

Ruby Set class: equality of sets.

According to the Ruby Set class's documentation, "== Returns true if two sets are equal. The equality of each couple of elements is defined according to Object#eql?. The essence of this can be demonstrated using Date objects, where sets containing different Date objects but with the same date compare to equal: require 'set' d1 = Date.t...