Questions tagged [compare]

The analysis required to assess the differences and similarities between two or more entities.

This tag is used to classify a question as one dealing with the comparison of at least two entities. The essence of questions that are tagged should boil down to one of the following questions:

  1. How do I control when the compiler/interpreter thinks that two entities are equal? How do I control when the compiler/interpreter thinks that two entities are unequal?
  2. How do I control when the compiler/interpreter thinks that one entity is bigger than the other?
  3. How do I control when the compiler/interpreter thinks that one entity is smaller than the other?

Note that in some languages, it is possible to define asymmetric inequalities. That is, cases in which a<b does not mean that b<a. This is why in python, there exist separate functions for __gt__ (greater than) and __lt__ (less than), etc

10212 questions
26
votes
5 answers

Compare 2 arrays and list the differences - Swift

I was wondering how one would go about comparing 2 boolean arrays and listing the non matching booleans. I have written up a simple example of 2 arrays. let array1 = [true, false, true, false] let array2 = [true, true, true, true] How would I…
simlimsd3
  • 599
  • 2
  • 6
  • 14
26
votes
4 answers

Compare Version Identifiers

Here is my code, which takes two version identifiers in the form "1, 5, 0, 4" or "1.5.0.4" and determines which is the newer version. Suggestions or improvements, please! /// /// Compares two specified version strings and returns…
Nick
  • 13,238
  • 17
  • 64
  • 100
26
votes
1 answer

Why can I assign structs but not compare them

Even though I am a long time C programmer, I only recently learned that one can directly assign structure variables to one another instead of using memcpy: struct MyStruct a,b; ... a = b; /* implicit memcpy */ Though this feels a bit "high-level"…
Tomas
  • 5,067
  • 1
  • 35
  • 39
25
votes
3 answers

Diff between commits in Visual Studio 2015 using git

Using Visual Studio 2015 Update 2 and git as source control, how do you diff between 2 commits on a branch? Note that I am not talking about diff on the granular file level (ie. view history of file and comparing), but rather for entire commits. I…
bitbyte
  • 483
  • 1
  • 6
  • 10
25
votes
2 answers

Github: comparing across forks?

Short version When I compare two forks on Github, it does not compare the latest states, but the current state of the base fork with the last common commit (or am I wrong?); so how can I compare the latest states/heads on Github? Longer version I am…
arthur.sw
  • 11,052
  • 9
  • 47
  • 104
24
votes
7 answers

Java file equals

I don't know about you guys but at least I expected that f1 would be equal to f2 in the below code but apparently that's not the case! What's your thoughts about this? It seems like I have to write my own equals method to support it, right? import…
aandeers
  • 431
  • 1
  • 6
  • 19
24
votes
8 answers

Compare every item to every other item in ArrayList

I'm having trouble with what I thought should be a pretty simple problem. I need to compare every item in an arrayList with every other item in the the list without comparing items to themselves. It's not as simple as calling an equals() comparison,…
JavaKungFu
  • 1,264
  • 2
  • 11
  • 24
24
votes
6 answers

How to compare two dates along with time in java

I have two Date objects with the below format. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String matchDateTime = sdf.parse("2014-01-16T10:25:00"); Date matchDateTime = null; try { matchDateTime =…
user2636874
  • 889
  • 4
  • 15
  • 36
24
votes
1 answer

Secure string compare function

I just came across this code in the HTTP Auth library of the Zend Framework. It seems to be using a special string compare function to make it more secure. However, I don't quite understand the comments. Could anybody explain why this function is…
laurent
  • 88,262
  • 77
  • 290
  • 428
23
votes
4 answers

Libpuzzle Indexing millions of pictures?

its about the libpuzzle libray for php ( http://libpuzzle.pureftpd.org/project/libpuzzle ) from Mr. Frank Denis. I´am trying to understand how to index and store the data in my mysql database. The generation of the vector is absolutly no problem.…
phpman
  • 253
  • 4
  • 6
23
votes
6 answers

Comparing strings in VB.NET

Hopefully this should be an easy question. In Java I think it's compareTo(). How do I compare two string variables to determine if they are the same? ie: If (string1 = string2 And string3 = string4) Then 'perform operation Else 'perform…
aspguy
23
votes
5 answers

Bash script compare two date variables

I'm trying to compare a date given by a user to a date in a file, basically a text file with lots of dates and times listed. for example the user would enter a date such as 22/08/2007 and a time of 1:00, what i need the script to do is count how…
Xleedos
  • 948
  • 2
  • 9
  • 17
23
votes
3 answers

How to compare two dataframe and print columns that are different in scala

We have two data frames here: the expected dataframe: +------+---------+--------+----------+-------+--------+ |emp_id| emp_city|emp_name| emp_phone|emp_sal|emp_site| +------+---------+--------+----------+-------+--------+ | 3| Chennai| …
rominoushana
  • 451
  • 2
  • 4
  • 17
23
votes
7 answers

In Intellij IDEA how to compare 2 text files that are not part of an open project

I would like to compare 2 files in intellij. Both files are not part of a specific project. Is there a way to do so? I am running Intellij 15 and 16.
galusben
  • 5,948
  • 6
  • 33
  • 52
23
votes
2 answers

Javascript method to find number of milliseconds from 1970-01-01?

Say, I have a date var dt = new Date('2012-01-01'); Is there a method in Javascript to return number of milliseconds since 1970-01-01? For this particulat date it would return 1325376000000 For this purpose, there is a method "toUTC()" that runs…
Cute_Ninja
  • 4,742
  • 4
  • 39
  • 63