Problem
I wondered how to make an effective comparison of two types of collections (lists, sets, maps, etc.). It should be noted that structural equality is desirable, rather than link-based equality.
Usually, you need to sort through all the elements of the collection and make a comparison between them at the price of O (1) per comparison, which gives an amazing comparison time O (n).
This can affect the hash table of lists where collision checking is quite expensive or a contract design is used (for example, comparison and old collection with new ones).
Direction of the current decision
I have ways to identify quick fixes, but they all seem experienced / non-deterministic. The idea is that you can use some unique hash of all the elements that can be stored and compared. A good hashing algorithm should provide sufficient entropy, so there is little chance of a collision.
This hash-based comparison method can be enhanced by using some constant-time comparison in the list (for example, comparing the first 10 elements). Two lists with the same elements at the beginning and using a good hashing algorithm should theoretically give a somewhat unique comparison.
Question
Is it possible to create some kind of comparison on the time constant (both generalized and specialized for some time, for example, integers), and can it be achieved using the unique hash method?
Update
To clarify the issue, I donโt need a perfect equality check, but a quick โbefore equalityโ check as a way to speed up a real equality check. Although many hash code implementations are useful for comparison, I'm also interested in (ordered) comparison.
Yet Another Geek
source share