Questions tagged [comparison]

Questions about data comparison and efficient ways to accomplish it.

Filter by
Sorted by
Tagged with
0 votes
5 answers
202 views

Comparing Java objects with different member variables

I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList ...
Delta88's user avatar
  • 19
-3 votes
1 answer
122 views

Is it a common practice to compare HLDs with the source code? [closed]

We have recently completed the development of a large system (150,000 lines of code more or less) which was developed from an HLD. Our stakeholders want to take the HLD and compare it with the source ...
Von Hymann's user avatar
0 votes
0 answers
460 views

Best way to check for truthy values in PHP?

In PHP, there are several ways to check whether a value is true, or similar: true === $v, only works for bool true == $v || !!$v, works with int and string, but a non empty array can also be ...
Gabriel Smoljar's user avatar
-4 votes
3 answers
180 views

How to identify whether or not 2 pieces of text are identical? [closed]

Let's say I was to create a scraper. At some point I'll need to come up with algorithm of identifing whether or not a piece of a newly scraped text matches the one that's already in the DB. How would ...
Nicholas E. Harding's user avatar
2 votes
2 answers
580 views

Isn't data migration a major benefit of MongoDB compared to the commonly used relational databases?

I was reading an old answer which was recently updated, and noticed that the author doesn't quote the simplicity of data migration as a benefit of MongoDB. I always thought that the major benefit of a ...
Arseni Mourzenko's user avatar
1 vote
4 answers
680 views

Can writing Object-Orientated Code in a Functional style improve performance?

Given a scenario where you have consecutive setters or a series of events where an object is modified, can it be more performant to instead write code in a way where a new state is returned rather ...
artman41's user avatar
  • 129
0 votes
4 answers
251 views

Language design : use equals symbol = both for affectation and comparison, like in MySQL

I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator. Most modern languages use ==, but amongst the database languages ...
ibi0tux's user avatar
  • 241
9 votes
4 answers
2k views

"REST Vs GraphQL" is it a correct comparison?

I saw in many sites that compare REST with GraphQL. after investigating this concern (actually my concern) that, "is it a correct comparison?", I being more confused. Since the REST has a different ...
m3hr24d's user avatar
  • 107
0 votes
1 answer
57 views

Objectreference vs Equality [closed]

While coding I stumbled upon something like this (extremely simplified example): public bool Func() { Object[] array = new Object[] {false, false}; return array[0] != array[1]; } I was ...
Sebastian L's user avatar
2 votes
4 answers
132 views

Date comparison with the last second of a day

Would you consider WHERE SomeDate <= '2018-01-01 23:59:59' instead of WHERE SomeDate < '2018-01-02' When the intention is that SomeDate goes no further then 2018-01-01 a code smell and if ...
axk's user avatar
  • 129
1 vote
1 answer
88 views

Simulating Comparison Without Using Comparison Primitives

In the same way that you can simulate the if statement and functions, I am wondering if there is a way to simulate the comparison operators ==, !=, >, >=, <, <=. For example, in ...
Lance's user avatar
  • 2,585
-4 votes
1 answer
561 views

TIOBE Index: why c++ is in 3rd place and C is having more land in the last year?

Searching for c++ ranking on the TIOBE index, I was stumped to see that C is in front of C++, and from 2017, C took a leap. Could someone explain why?
Rogério Dec's user avatar
2 votes
2 answers
4k views

Proving Two Zip file are identical

I migrated some files from one Version Control System to another. I have to prove that content are identical (between source and destination, denote 1 , 2). There are a few zips files (lets call them ...
meah1991's user avatar
12 votes
2 answers
2k views

Is the IComparable interface outdated/"harmful"?

IComparable only works one way Let's say you have a Employee class. In one view, you want to show all Employees sorted by name - in another, by address. How are you going to achieve that? Not with ...
R. Schmitz's user avatar
  • 2,608
1 vote
2 answers
339 views

Is comparing "dollar-hours" for running a specific piece of code practical as an estimate of rented system performance?

Background: there'a a gazillion types of virtual machines in Microsoft Azure each having different performance and price. Such virtual machines are paid per hour. The goal is to decide how to get "the ...
sharptooth's user avatar
  • 4,357
1 vote
1 answer
818 views

Best approach for name similarity

As part of validation, we perform name similarity check and allow only if the threshold is reached. I got some help from StackOverflow regarding the implementation and finally implemented JaroWinkler ...
Vamsidhar's user avatar
  • 169
-1 votes
2 answers
274 views

Why in Tournament Sorting do we neglect the number of comparisons to find the Minimum?

Here the professor said that, Tournament sort needs (n-1) + 2(n-1)logn comparisons. {Where (n-1) for calculating Maximum or say creating Tournament structure and 2(n-1)logn for other elements to sort}...
Bhaskar's user avatar
  • 47
18 votes
1 answer
3k views

How does integer comparison work internally?

E.g. when comparing two integers as follows in a C-like language: if (3 > 2) { // do something } How is the judgement whether 3 is greater than 2 (true) or not (false) made internally?
Niek's user avatar
  • 307
1 vote
2 answers
2k views

What are the most idiomatic abbreviations for comparison operators [closed]

I am wondering what the most idiomatic text abbreviations for comparison operators are. I need to build a custom enum with them, so I cannot use their symbols. To me personally, these seem idiomatic: ...
Felk's user avatar
  • 184
1 vote
0 answers
585 views

I want to write an application to compare files, similar to WinMerge. I'm not sure how to design it, though

My current project is to implement a kind of WinMerge clone to compare two files. I am using C++ with the Win32-API (WTL, ATL, that stuff), and I already designed an UI for this. However, I am now ...
Sossenbinder's user avatar
1 vote
1 answer
91 views

How to analyse user input and determine if it (kind of) matches an answer

I'm working on a quiz system that will allow users to enter text as an answer. The question could be something simple to start with, looking for a short phrase, or a select few words as the "correct" ...
simonw16's user avatar
  • 133
5 votes
4 answers
8k views

Four-way XML comparison in C#

I have 4 XML files: A, B, C, and D. I want to know if the difference between A and B is the same as the difference between C and D. The XML files are serializations of the same .NET object; one of ...
EJoshuaS - Stand with Ukraine's user avatar
1 vote
4 answers
698 views

Comparing objects with tolerance

The following code says that c1 == c2 and c2 == c3, but c1 != c3. TOL = 0.11 class C: def __init__(self, x): self.x = x def __eq__(self, other): return abs(self.x - other.x) ...
stenci's user avatar
  • 115
0 votes
0 answers
57 views

Is there some reason into allowing assignations in a conditional? [duplicate]

I bet I'm not the only one here that has had problems with something like this: you want to check something in a language that has the == operator for checking equality and instead you do something ...
user2638180's user avatar
1 vote
1 answer
212 views

How do travel search engines combine flights

I'm curious about how the flight/train search engines combine the results from multiple sources. For example, let's say I'm asking to go from London to Paris, and let's assume there are no direct ...
André Borie's user avatar
2 votes
2 answers
556 views

Algorithm for lines comparison

I'm working on the import of land-use data into Openstreetmap. Unfortunately I've encountered a problem that has delayed my time table. Take a look at the picture below: the red line is the main road ...
Davide_sd's user avatar
  • 147
0 votes
1 answer
211 views

Developing a simple HTML exercises with JavaScript [closed]

I'm developing a website with some simple HTML exercises (like the ones in Codeschool and Codacademy), and now I'm stuck at the correction phase, how can I compare two HTML strings and decide if the ...
Bassel Shmali's user avatar
43 votes
10 answers
8k views

Why do most mainstream languages not support "x < y < z" syntax for 3-way Boolean comparisons?

If I want to compare two numbers (or other well-ordered entities), I would do so with x < y. If I want to compare three of them, the high-school algebra student will suggest trying x < y < z....
JesseTG's user avatar
  • 657
1 vote
3 answers
512 views

How to effectively compare the (almost) same code which has been auto-formatted?

I am trying to infer the differences between two projects, however so far it has been really painful, because one of the parties has done auto-formatting on the code. Basically, this makes a merging ...
Kristof Pal's user avatar
0 votes
1 answer
21 views

Comparing articles from various web-stores

Today I had the idea to write a program that compares the prizes between different web-stores. The key question I am asking myself is how to find (with a high probability) the same article on another ...
Bobface's user avatar
  • 123
8 votes
4 answers
19k views

Avoiding Division by Zero Using Float Comparison

Source code analyzers (like SonarQube) complain about float (or double) equality comparisons because equality is a tricky thing with floats; the values compared can be the results of computations ...
Alfe's user avatar
  • 241
7 votes
2 answers
1k views

Efficient algorithm to merge n successive sorted arrays in place

I am developing an in-place sorting algorithm that leaves the array into a state where it is basically a succession of sorted subsequences of any size (most are bigger than log2(size(array))); then it ...
Morwenn's user avatar
  • 1,756
0 votes
1 answer
1k views

Comparison Function Returns True or False

In my python CS class at school, we were given a true or false question as follows. A comparison function returns either True or False. When originally answering I thought about two things. First,...
intboolstring's user avatar
26 votes
5 answers
2k views

Could an instance be equal to some other instance of a more specific type?

I've read this article: How to Write an Equality Method in Java. Basically, it provides a solution for an equals() method that supports inheritance: Point2D twoD = new Point2D(10, 20); Point3D ...
Wes's user avatar
  • 832
0 votes
3 answers
8k views

Functional programming: Compare all items in an array

In functional programming, how do I do an equality comparison of all items in an array? I have an array of items that I want to compare, for example for equality. Is it possible to use a fold (also ...
dalgard's user avatar
  • 147
2 votes
0 answers
435 views

Algorithm to maximize pairwise comparisons using transitive property

I'm looking for some direction on building an algorithm that will maximize the number of pairwise comparisons of objects in a set using transitivity. To explain in detail: Suppose there are x ...
user3290799's user avatar
4 votes
3 answers
737 views

Determine frequency-range that matches closest to input list of frequencies

Since this question is not about "code not working", I'm asking my first question here instead of StackOverflow. Inform me if any required information is missing from the question. Setup: I have two ...
Abbas's user avatar
  • 543
1 vote
2 answers
188 views

Multi-pattern matching

I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you ...
Rui Pedro Caldeira's user avatar
0 votes
1 answer
265 views

Should a comparison method ever return the same type back as it's comparing?

First, this is homework, but no, I'm not asking for anyone to do any code for me. My course start date isn't for another month (it's online), so I can't ask for clarification. I thought I'd see if ...
Carcigenicate's user avatar
5 votes
4 answers
1k views

Legitimate cases of having .equals() behaving inconsistently with .compareTo()?

Java documentation says it's "strongly recommended" to have them behaving consistently. But are there legitimate cases of java/c#/python/etc Object.equals() method behaving inconsistently with the ...
Wes's user avatar
  • 832
12 votes
4 answers
54k views

List comparing techniques for faster performance

I need to cross names from two lists, and find all occurrences of one name in the other. The lists are too big, one have 50k elements and the other 400k. For a small list I would use two foreach ...
cap7's user avatar
  • 287
0 votes
0 answers
1k views

Compare names and the use of Levenshtein's algorithm

I need to cross names from two lists. What is the best away to compare the names? As you may expect, in one list we can have the complete name, on the other just the first and last. Besides that, ...
cap7's user avatar
  • 287
0 votes
3 answers
825 views

Is JavaScript fail-safe?

I was compiling a list of comparison of top 10 programming languages (JavaScript included). I was doing it from this Wikipedia page. However, in the third table (Failsafe I/O), there is no row for ...
discussedtree's user avatar
2 votes
1 answer
56 views

Comparing path strings against list of rules

I am trying to find a way to enhance a filtering algorithm. I am developing a backup software that enables users to specify custom filters to exclude unwanted files/directories. Currently when trying ...
Zaid Amir's user avatar
5 votes
4 answers
2k views

Why are return values from compare functions in many languages defined loosely?

Many languages define that compare functions should return ANY negative value, zero, or ANY positive value. Is there some reason that it shouldn't be clearly defined as -1 0 and 1? Does a wide range ...
Shane's user avatar
  • 163
-2 votes
1 answer
408 views

Why are mostly 9999, 99999.... are used for making comparisons [closed]

I (I am sure everyone else also) have always seen comparisons of some value to 999 or 9999 .... etc. for e.g.: in CSS z-index: 9999 or some times str.length < 99999 I wonder if there is some ...
Digvijay Yadav's user avatar
25 votes
2 answers
25k views

Algorithm to merge two sorted arrays with minimum number of comparisons

Given are two sorted arrays a, b of type T with size n and m. I am looking for an algorithm that merges the two arrays into a new array (of maximum size n+m). If you have a cheap comparison ...
Rüdiger Klaehn's user avatar
6 votes
5 answers
2k views

Algorithm to test file equivalence

I'm writing a program that needs to test if a file is equivalent to one or more other files. To accomplish this, every time we see a new file we stat the file and get the size. We use the size as a ...
AlexLordThorsen's user avatar
0 votes
2 answers
1k views

Comparing doubles [duplicate]

I need to compare to double variables like this if (distance <= radius) both distance and radius are doubles and I remember in class how to use epsilon comparisons for checking equality but how ...
user3347937's user avatar
7 votes
3 answers
2k views

Is there a language-agnostic specification for "string natural sorting order"?

As I painfully try to find a good natural sorting algorithm written in JavaScript, I then stumble upon a bunch of different implementations, interesting blog posts, and answers on StackOverflow. Each ...
Adriano's user avatar
  • 181