Questions tagged [comparison]

Questions about data comparison and efficient ways to accomplish it. Please avoid using this tag for generic (meta) comparison of two issues or concepts.

Questions about data comparison and efficient ways to accomplish it, e.g.: "Which is the fastest algorithm to compare two recordsets and decide which one has more palindromes?", or "What is the fastest way to compare two strings and say if they have more than Y characters in common?"

There are generally six basic "comparison operators": less than, <; less than or equal to, <=; equal to, ==; not equal to, !=; greater than or equal to, >=; and greater than, >.

8118 questions
95
votes
7 answers

How are strings compared?

I'm wondering how Python does string comparison, more specifically how it determines the outcome when a less than < or greater than > operator is used. For instance if I put print('abc' < 'bac') I get True. I understand that it compares…
davelupt
  • 1,845
  • 4
  • 21
  • 32
95
votes
18 answers

Samples of Scala and Java code where Scala code looks simpler/has fewer lines?

I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should solve the same problem). If there is only Scala…
Roman
  • 64,384
  • 92
  • 238
  • 332
95
votes
2 answers

Which is better H2 or HSQLDB?

HSQLDB 2.0 is soon to be released. I wonder if it will outperform H2 since, as far as I know, most users prefer H2 than HSQLDB. I am interested in the MVCC support of HSQLDB 2.0. I have learned that MVCC on H2 is still experimental. With regards to…
dexter
  • 1,869
  • 2
  • 14
  • 13
94
votes
6 answers

Algorithm to check similarity of colors

I'm looking for an algorithm that compares two RGB colors and generates a value of their similarity (where similarity means "similar with respect to average human perception"). Any ideas? EDIT: Since I cannot answer anymore I decided to put my…
Kai Huppmann
  • 10,705
  • 6
  • 47
  • 78
91
votes
5 answers

Value for epsilon in Python

Is there a standard value for (or method for obtaining) epsilon in Python? I need to compare floating point values and want to compare against the smallest possible difference. In C++ there's a function provided numeric_limits::epsilon( ) which…
thornate
  • 4,902
  • 9
  • 39
  • 43
91
votes
14 answers

Compare version numbers in Objective-C

I am writing an application that receives data with items and version numbers. The numbers are formatted like "1.0.1" or "1.2.5". How can I compare these version numbers? I think they have to be formatted as a string first, no? What options do I…
mlecho
  • 1,149
  • 2
  • 10
  • 14
90
votes
5 answers

Calculate minimal operations to make two tree structures identical

This is more of a CS question, but an interesting one : Let's say we have 2 tree structures with more or less the same nodes reorganized. How would you find any in some sense minimal sequence of operations MOVE(A, B) - moves node A under node B…
Tomas Vana
  • 18,317
  • 9
  • 53
  • 64
90
votes
6 answers

Comparing boolean and int using isinstance

Can someone give me an explanation why isinstance() returns True in the following case? I expected False, when writing the code. print isinstance(True, (float, int)) True My guess would be that its Python's internal subclassing, as zero and one -…
jake77
  • 1,892
  • 2
  • 15
  • 22
89
votes
5 answers

Java Integer compareTo() - why use comparison vs. subtraction?

I've found that java.lang.Integer implementation of compareTo method looks as follows: public int compareTo(Integer anotherInteger) { int thisVal = this.value; int anotherVal = anotherInteger.value; return (thisVal
Vladimir
  • 12,753
  • 19
  • 62
  • 77
88
votes
9 answers

How do I deal with "signed/unsigned mismatch" warnings (C4018)?

I work with a lot of calculation code written in c++ with high-performance and low memory overhead in mind. It uses STL containers (mostly std::vector) a lot, and iterates over that containers almost in every single function. The iterating code…
Andrew T
  • 5,549
  • 7
  • 43
  • 55
88
votes
2 answers

How to check identical array in most efficient way?

I want to check if the two arrays are identical (not content wise, but in exact order). For example: array1 = [1,2,3,4,5] array2 = [1,2,3,4,5] array3 = [3,5,1,2,4] Array 1 and 2 are identical but 3 is not. Is there a good way to do this in…
ssdesign
  • 2,743
  • 6
  • 37
  • 53
87
votes
0 answers

php == vs === operator

What is the difference between == and === in php. I am unsure when to use both. Updated note: So that it shows up in StackOverflow search, the difference between == and === is the same as the difference between != and !==.
user34537
87
votes
25 answers

Sort on a string that may contain a number

I need to write a Java Comparator class that compares Strings, however with one twist. If the two strings it is comparing are the same at the beginning and end of the string are the same, and the middle part that differs is an integer, then compare…
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
86
votes
12 answers

get NSDate today, yesterday, this Week, last Week, this Month, last Month... variables

I am trying to do is to get NSDate today, yesterday, this Week, last Week, this Month, last Month variables ready for comparison for headers to be added on UITableView's titleForHeaderInSection What I want is done manually in the code below for date…
hasnat
  • 2,647
  • 1
  • 20
  • 23
86
votes
13 answers

Comparison of CI Servers?

I am searching for a comparison of different continuous integration (CI) Servers (esp. focusing on .NET) and couldn't find any. Therefore I'd like to know what you think about the different solutions available, what are the pros and cons, what are…
Johannes Rudolph
  • 35,298
  • 14
  • 114
  • 172