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
2 answers

Comparing expressions in Haskell

-- | A very simple data type for expressions. data Expr = Const Int | Add Expr Expr deriving Show -- | 'Expression' is an instance of 'Num'. You will get warnings because -- many required methods are not implemented. instance Num Expr where …
fuuman
  • 469
  • 2
  • 7
  • 19
1
vote
1 answer

Dual IP stack address equality comparison

I am trying to prevent redundant WebSocket connections in a browser by only permitting IPv4 and IPv6 addresses received from potentially malicious sources by modifying and using this regex to validate and then testing for equality before…
user1382306
1
vote
4 answers

NHibernate Equality: How do I ensure only one row is persisted from many "equal" .NET objects?

How can I get the following test to pass with NHibernate? I thought it was enough to simply override Equals and GetHashCode in the entity class for this to work the way I want it to. Obviously for "Point" objects, which are quite trivial, it's silly…
snicker
  • 6,080
  • 6
  • 43
  • 49
1
vote
3 answers

Haskell Ord instance paradox on Eq

I want to be able to order Polynomes with comparing first by lenght (degree), second by coefficient. Polynomes are list of doubles with [1,2,3] = 3x²+2x+1 . But if there is a zero as last element it should be dropped, so I wrote a function doing…
Krismu
  • 503
  • 4
  • 14
1
vote
1 answer

How can I efficiently perform == using binary operations?

I am interested in finding a Boolean/arithmetic function that will return -1 if two values match, and 0 if they do not match, in other words the == operation. I know this can be done with a logical NOT, for example: ! (A-B) which will be -1 (=…
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
1
vote
1 answer

Do I need heterogeneous equality?

Brief background: I'm implementing contexts and renamings using de Bruijn indices, and then extending those notions with an "undefined" name, written ε. The undefined name induces a partial order on names in Γ, and also on renamings between Γ and…
Roly
  • 2,126
  • 2
  • 20
  • 34
1
vote
3 answers

LINQ Distinct counting duplicates even when the hash codes are the same?

I am grouping log records by a RegEx pattern. After grouping them I'd like to get a Distinct count of the records for each group. For this example, Distinct is defined as the same visit key and the same year, month, day, hour, and minute. It's just…
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
1
vote
1 answer

How to force HashMap to use identity (hash code)? or suggest workaround

Earlier I have coded HashMap to store some objects, which was expecting to use identity while storing them. I.e. objects were treated "same" if Object.equals() was saying this. Later I coded hashCode() and equals() methods for classes of these…
Dims
  • 47,675
  • 117
  • 331
  • 600
1
vote
2 answers

how compare row by row matlab

I have a situation like this I have data M size (x by 2) where data were in already in classify group by C = unique(M(:) , 'rows'); %result will be in g-by-2 now I want to assign the data group M accord to C by creating a R matrix size…
someone
  • 365
  • 1
  • 5
  • 14
1
vote
4 answers

Testing for Type Equality without RTTI

Say B and C are derived from A. I want to be able to test whether any two instances of classes derived from A are instances of the same class, that is, whether A* foo and A* bar both point to B instances, without using RTTI. My current solution is…
Jon Purdy
  • 53,300
  • 8
  • 96
  • 166
1
vote
2 answers

Compare occurrences between 2 dataframes in R

I would like to compare to a string frequence between two dataframes in R. My first dataframe (X): List1 Engl001 Engl002 Engl003 My second dataframe (Y): List1 ram Engl001 noi2 Engl001 oui5 Engl003 ki4 My expected output: List1 …
user3091668
  • 2,230
  • 6
  • 25
  • 42
1
vote
2 answers

Is there an exact string compare in T-SQL?

I have searched many answers, but I have not found a solution for the following simple task: I have a lengthy TextString and want to look for an exact match to the string ' Text ' within it. TextString LIKE '% Text %' gives all occurrences of…
alrts
  • 338
  • 5
  • 12
1
vote
1 answer

Assert.Equal anonymous objects across assemblies fails

My Assert.Equal() for an anonymous object is returning false, however very carefully inspecting the properties by hand in the debugger everything seems fine. It doesn't complain about the properties per say, only the following (which if you compare…
Alex KeySmith
  • 16,657
  • 11
  • 74
  • 152
1
vote
2 answers

Equality without using operator

I was asked if it was possible to compare two (say) lists without invoking operators, to determine if they were the same (or rather, contained the same elements). I first entertained using x in y before I realised that it would not care for…
Arashi
  • 85
  • 1
  • 5
1
vote
2 answers

error: invalid operands to binary == (have 'struct demo' and 'struct demo')

Code 1: struct demo { int a; }d[2]; int main() { d[0].a=5; d[1]=d[0]; return 0; } This code works fine Code 2: struct demo { int a; }d[2]; int main() { d[0].a=5; d[1]=d[0]; if(d[0]==d[1]) { …
kevin gomes
  • 1,775
  • 5
  • 22
  • 30