equality

What is the difference between equivalence and equality?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 04:46:49
What is the difference between equivalence and equality in C++? There is a very similar question here . However, this question is tagged with math , while I am interested in the meaning in C++ context. To see the terms in context: Scott Meyers uses them in an example in this video . On cppreference.com i found the following quote: For the types that are both EqualityComparable and LessThanComparable, the C++ standard library makes a distinction between equality, which is the value of the expression a == b and equivalence, which is the value of the expression !(a < b) && !(b < a). 来源: https:/

Tuple vs string as a Dictionary key in C#

▼魔方 西西 提交于 2019-12-03 04:25:15
I have a cache that I implement using a ConcurrentDictionary, The data that I need to keep depends on 5 parameters. So the Method to get it from the cache is: (I show only 3 parameters here for simplicity, and I changed the data type to represent CarData for clearity) public CarData GetCarData(string carModel, string engineType, int year); I wonder what type of key will be better to use in my ConcurrentDictionary, I can do it like this: var carCache = new ConcurrentDictionary<string, CarData>(); // check for car key bool exists = carCache.ContainsKey(string.Format("{0}_{1}_{2}", carModel,

PHP: Testing whether three variables are equal

旧街凉风 提交于 2019-12-03 04:13:48
I've never come across this before, but how would you test whether three variables are the same? The following, obviously doesn't work but I can't think of an elegant (and correct) way to write the following: if ($select_above_average === $select_average === $select_below_average) { } if ((a == b) && (b == c)) { ... they're all equal ... } by the transitive relation $values = array($select_above_average, $select_average, $select_below_average); if(count(array_unique($values)) === 1) { // do stuff if all elements are the same } Would be another way to do it. Dogbert if ($select_above_average ==

Determining Date Equality in Javascript

非 Y 不嫁゛ 提交于 2019-12-03 04:08:56
I need to find out if two dates the user selects are the same in Javascript. The dates are passed to this function in a String ("xx/xx/xxxx").That is all the granularity I need. Here is my code: var valid = true; var d1 = new Date($('#datein').val()); var d2 = new Date($('#dateout').val()); alert(d1+"\n"+d2); if(d1 > d2) { alert("Your check out date must be after your check in date."); valid = false; } else if(d1 == d2) { alert("You cannot check out on the same day you check in."); valid = false; } The javascript alert after converting the dates to objects looks like this: Tue Jan 25 2011 00

`Refl` thing in Calculus of Constructions?

眉间皱痕 提交于 2019-12-03 03:05:39
In languages such as Agda , Idris , or Haskell with type extensions, there is a = type sort of like the following data a :~: b where Refl :: a :~: a a :~: b means that a and b are the same. Can such a type be defined in the calculus of constructions or Morte (which is programming language based on the calculus of construction)? The standard Church-encoding of a :~: b in CoC is: (a :~: b) = forall (P :: * -> * -> *). (forall c :: *. P c c) -> P a b Refl being Refl a :: a :~: a Refl a = \ (P :: * -> * -> *) (h :: forall (c::*). P c c) -> h a The above formulates equality between types . For

Best practice to choose fields for equals() implementation

≡放荡痞女 提交于 2019-12-03 01:58:55
When writing unit-tests, I often face the situation when equals() for some object in tests -- in assertEquals -- should work differently from how it works in actual environment. Take for example some interface ReportConfig . It has id and several other fields. Logically, one config equals to another one when their id s match. But when it comes to testing some specific implementation, say, XmlReportConfig , obviously I want to match all fields. One solution is not to use equals in tests and just iterate over the object properties or fields and compare them, but it doesn't seem like a good

isEqual doesn't always work for NSIndexPath? What can I use in its place?

天大地大妈咪最大 提交于 2019-12-02 20:12:44
I've got some code that relies on comparing two NSIndexPaths and executing different code based on their equality or lack thereof (using -isEqual). Most of the time it works properly, but sometimes it doesn't. I've used the debugger console to test the two indexpaths during code execution, and they look identical to me. Here's the code: - (BOOL)selectedStreetIsSameAsLastSelectedStreet { return [self.indexPathOfSelectedStreet isEqual:self.previousObject.indexPathOfSelectedStreet]; } Here's the output during the execution of the code: (gdb) po self.indexPathOfSelectedStreet <NSIndexPath

Difference between hash() and id()

試著忘記壹切 提交于 2019-12-02 18:19:55
I have two user-defined objects, say a and b . Both these objects have the same hash values. However, the id(a) and id(b) are unequal. Moreover, >>> a is b False >>> a == b True From this observation, can I infer the following? Unequal objects may have the same hash values. Equal objects need to have the same id values. Whenever obj1 is obj2 is called, the id values of both objects is compared, not their hash values. There are three concepts to grasp when trying to understand id , hash and the == and is operators: identity , value and hash value . Not all objects have all three. All objects

Why does an assignment in an if statement equate to true?

五迷三道 提交于 2019-12-02 16:02:59
问题 Let me start off by saying I understand the difference between = , == , and === . The first is used to assign the right-hand value to the left-hand variable, the second is used to compare the equivalency of the two values, and the third is used not just for equivalency but type comparison as well (ie true === 1 would return false ). So I know that almost any time you see if (... = ...) , there's a pretty good chance the author meant to use == . That said, I don't entirely understand what's

Why is x == (x = y) not the same as (x = y) == x?

淺唱寂寞╮ 提交于 2019-12-02 15:44:51
Consider the following example: class Quirky { public static void main(String[] args) { int x = 1; int y = 3; System.out.println(x == (x = y)); // false x = 1; // reset System.out.println((x = y) == x); // true } } I'm not sure if there is an item in the Java Language Specification that dictates loading the previous value of a variable for comparison with the right side ( x = y ) which, by the order implied by brackets, should be calculated first. Why does the first expression evaluate to false , but the second evaluate to true ? I would have expected (x = y) to be evaluated first, and then it