Questions tagged [equality]

Equality is a relationship between two or more items or variables or objects that exists if (1) the items are the same item, variable, or object or (2) the items are different items, variables or objects but they have the same value. This tag should generally be used with programming language specific tags as well as other contextual tags such as database system. The post should include as much context about the equality test as is possible.

This tag is typically used for questions concerning how to determine if two objects or variables are either the same object or different objects with the same value. Questions almost always require a programming language tag and other tags for context.

Programming languages represent variables, objects, or other storage containers using different underlying mechanisms for the storage of the values of variables and objects. A test for equality is to compare some characteristic of two variables or objects to determine if the characteristic is the same.

This characteristic is typically either (1) the storage identifier such as a reference handle, memory address, etc. when checking if the two are the same object or (2) the characteristic is the value of the objects retrieved using a storage identifier when checking if the value of the two are the same value.

Different programming languages and different operating environments have differences in how equality is tested and what operators are used to express a test for equality. In some cases various conversions from underlying storage representations may be involved in testing for equality.

See What is the difference between equality and equivalence? as well as Equivalence relation and natural ordering on a class in Java

2095 questions
1
vote
4 answers

Compare a Queue and a Stack's content

Suppose we have in c++, using STL Stack and Queue Stack: [1 2 3 4 5] <=> Queue: => [5 4 3 2 1] => What is the most elegant way to recursively check that the data entries are the same in terms of content and order? Say the stack and…
herpderp
  • 33
  • 1
  • 5
1
vote
1 answer

Implementing == operator in C# on explicit-interface implementation

I have defined a struct Coords that explicitly implements three interfaces, each defined like this: public partial struct Coords { int ICoordsUser.X { get { return VectorUser.X; } } int ICoordsUser.Y …
Pieter Geerkens
  • 11,775
  • 2
  • 32
  • 52
1
vote
1 answer

optimized solution for equivalence class

suppose there are many testcase specified by capital letter, the letters in one bracket mean these are equal testcases. And I want the smallest set X of letters. But there is not transitive relation for the equal testcases. That is, (A,B)…
林子洋
  • 13
  • 3
1
vote
3 answers

DDD Value Object equality, == vs .Equals()

So I have a value object, (arbitrarily say money), and I want to implement equality for it. I am aware of the intended/default behavior for == and .Equals() (reference and data equality). In this case though, I want to be able to compare two…
1
vote
2 answers

Twig equality if..else in symfony 2 gives both results

I'm using Symfony2 with Twig and when trying to determine the class that should be a div Twig says that all 4 classes are active even beeing in an if..else clause. Redirect has only 1 value. I checked the syntax and I think it's correct so maybe I'm…
viscat
  • 335
  • 1
  • 5
  • 8
1
vote
4 answers

Switch between equality rules

I have a class and different equivalence rules on it (different implementation of equals and hashCode). The data is generated in one process first, where one equivalence rule is applied, and then fed to the second process, where the other…
Kane
  • 1,314
  • 2
  • 9
  • 14
1
vote
1 answer

Why does the root object implement equality?

In many object oriented languages such as Java, the .NET family, Python, Ruby, and I'm sure a host of others, the root object class from which all other classes inherit defines an equality checking method. However, in my experience, many of the…
jpmc26
  • 28,463
  • 14
  • 94
  • 146
1
vote
4 answers

Comparing Similar Columns for Equality

I have a (simplified) table that is structured like so: Table: ItemData PK | ItemID | StoreFK | Retail 1 | 100101 | 1 | 4.99 4 | 100101 | 2 | 4.99 7 | 100101 | 3 | 0.99 2 | 100102 | 1 | 6.99 5 | 100102 | 2 |…
recursion.ninja
  • 5,377
  • 7
  • 46
  • 78
1
vote
2 answers

Having problems comparing two custom class objects

Possible Duplicate: What is “Best Practice” For Comparing Two Instances of a Reference Type? I have this custom Class for my application. There are two instances (A and B) of this class, which I'm trying to compare. However, I'm having problems;…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
1
vote
1 answer

php sha1 not equal java sha1

Possible Duplicate: Java’s MessageDigest SHA1-algorithm returns different result than SHA1-function of php what I use: java: public String sha1(String s) { try { // Create MD5 Hash MessageDigest digest =…
Gergely Fehérvári
  • 7,811
  • 6
  • 47
  • 74
1
vote
5 answers

Why does integer.equals(string) give false when both contain the same value, but does not throw type mismatch exception?

I have code where I get a string as input, and I compare it with an integer. I saw that integer variable also has an Equals function that accepts a string parameter. I have used it directly thinking it will typecast it. It did not give any compile…
Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101
1
vote
6 answers

PHP noob : is it possible to test equality on an undefined variable without warning?

Sorry if it's an irritating question (i come from a ruby background and i am new to PHP). I find it kind of weird that you can't do: if($defined_array['undefined_index'] == 'a string') { do_something(); } without getting slammed in the face…
m_x
  • 12,357
  • 7
  • 46
  • 60
1
vote
2 answers

What value does System.Drawing.Color -state have?

System.Drawing.Color has a private field int state which makes equality a bit more tricky than one would expect from a struct. Anyone know what on earth it's for? Who, what and why sets and reads it?
Lars-Erik
  • 301
  • 3
  • 17
1
vote
1 answer

Strange inequality - WC_BUTTONW not equal to L"Button"?

I have a Button control wrapper class, which allows you to pass an existing handle to it, provided it is of the WC_BUTTON class. I use GetClassName() to determine this. But I have a problem, the comments in the code should help describe it: //…
Brandon Miller
  • 2,247
  • 8
  • 36
  • 54
1
vote
2 answers

Why do my Time objects never get evaluated as equal in Ruby?

@dfa = Time.new @type_me = gets @i = 0 def type pause_duration = 2 start_time = Time.new until Time.new == start_time + pause_duration puts "#{start_time + pause_duration} || #{Time.new}" end print @type_me[@i] @i += 1 …
cyclingLinguist
  • 334
  • 1
  • 5
  • 16