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
0
votes
1 answer

Is it possible to override the equality function of React's useState, useMemo, useEffect hooks?

Assume I have this code: const [obj, setObj] = useState({ value: 0 }); // somewhere else setState({value: 0}); // somewhere else const value = useMemo(() => obj.value, [ obj ]); // somewhere else useEffect(() => { console.log(obj.value) }, […
entropyfeverone
  • 1,052
  • 2
  • 8
  • 20
0
votes
2 answers

What is the canonical way to compare memory ranges in the CPU and in the GPU

I have to contiguous ranges (pointer + size), one in the GPU and one in the CPU and I want to compare if they are equal. What the canonical way to compare these ranges for equality? my_cpu_type cpu; // cpu.data() returns double* my_gpu_type gpu; …
alfC
  • 14,261
  • 4
  • 67
  • 118
0
votes
0 answers

Guava Objects.equal

I'm using Guava Objects.equal method. According to Guava API this Objects.equal method returns true if a and b are both null. I am not sure if I want this behavior on null fields for business key fields. So I think null!=null on fields…
aug70co
  • 3,965
  • 5
  • 30
  • 44
0
votes
1 answer

My set of custom objects accepts duplicates (Kotlin)

I have a quick question about Sets and custom objects in Kotlin. I have a simple 3D Point class and I would like to have a set of these. class Point3D(val x: Int, val y: Int, val z: Int){ override fun equals(other: Any?): Boolean { if…
0
votes
1 answer

Unable to check whether a boolean is true?

I am trying to check whether a boolean variable (boolVariable) is True (T) using the following code: (defvar boolVariable T) (if (= boolVariable T) (print 'TRUE) ) However, I get the following error: =: T is not a number This seems…
Adam Lee
  • 436
  • 1
  • 14
  • 49
0
votes
1 answer

Equality comparisons with useSelector

What is the best practice for performing equality checks with the react-redux useSelector hook? Should you always use something like deepEqual from react-fast-compare when you are expecting a reference data type back to prevent unnecessary…
DanB-Web
  • 33
  • 1
  • 6
0
votes
4 answers

c# object equality for database persistance

I want to learn how others cope with the following scenario. This is not homework or an assignment of any kind. The example classes have been created to better illustrate my question however it does reflect a real life scenario which we would like…
Jasper
0
votes
0 answers

Comparing decimal values of two variables of different types do not detect equality in all cases

I recently detected the hard way that in the comparison in Visual Studio C# double a = 0.4; float b = 0.4f; if (a < b) break; a turns out to be smaller than b, so the comparison is true and the program branches out. This came to me as a surprise. I…
alrts
  • 338
  • 5
  • 12
0
votes
1 answer

How to control the equality of mutiple tuples?

Imports System Class RGB Public Shared ReadOnly Dim Red As New RGB(255, 0, 0) Public Shared ReadOnly Dim Green As New RGB(0, 255, 0) Public Shared ReadOnly Dim Blue As New RGB(0, 0, 255) Private R, G, B As Byte Sub New(ByVal R As Byte,…
0
votes
0 answers

The meaning of err == nil != foo

I've stumbled upon a usage as err == nil != c.Ok. I couldn't make out what it exactly checks for and find documentation as to it on the internet. It was used in the following snippet as such: if err := validateMountPath(c.Path); err == nil != c.Ok…
ibrahim koz
  • 537
  • 4
  • 15
0
votes
1 answer

How to compare between elements of two arrays?

I am trying to check if a number is palindrome or not, I took the numbers in a string then put them into an array of numbers, and I was able to reverse this array of numbers into a new array. Now I want to check if numbersL[]==numbersLreversed[].…
JOEGREEN
  • 29
  • 7
0
votes
2 answers

Generic class where type must implement IEquatable

I'm trying to create a generic "property" class that maintains both it's current value and the last value. public class GenericTrackingProperty where T : IEquatable { private T _oldValue; private T _currentValue; public T Value …
0
votes
3 answers

Comparing a collection of reference type objects for equality ignoring order of items in collection

I have the following sample classes public class Item { public string name { get; set; } public double price { get; set; } } public class Basket { public Item[] items; } I then made two instances of Basket, both containing Items var…
O'Neil Tomlinson
  • 702
  • 1
  • 6
  • 28
0
votes
2 answers

JavaScript: Why is the output false?

console.log(`${window === this} (window === this)`) console.log(`${window === self} (window === self)`) console.log(`${this === self} (this === self)`) console.log(`${window === this === self} (window === this === self)`) Why is window === self…
Nice18
  • 476
  • 2
  • 12
0
votes
1 answer

Parsed F# DateTime value not equal to the original DateTime value

Consider the following code that converts a DateTime to a string, tries to parse it using the TryParse method on DateTime, and returns an DateTime option indicating whether parsing the string was successful or not: let dt = DateTime.Now printfn…
user279185
  • 123
  • 1
  • 1
  • 6