Re:Why databases use ordered indexes but programming uses ha...
by dajohnson89 on Monday December 09, 2019 @11:16PM
(#21749538)
doesn't this force you to define a comparator for everything though?
[ Parent
| on HN ]
Re:Why databases use ordered indexes but programming uses ha...
by _greim_ on Tuesday December 10, 2019 @01:38AM
(#21750234)
As opposed to defining a hash code for everything, yes. Parent asserts that writing obviously-correct comparators is easier.
Re:Why databases use ordered indexes but programming uses ha...
by LgWoodenBadger on Tuesday December 10, 2019 @11:22AM
(#21753866)
IDEs have had good equals/hashcode auto-generation mechanisms for years.
Java itself introduced Objects.hash(Object...) in 1.7 https://docs.oracle.com/javase/7/docs/api/java/util/Objects....
It's never really been an issue at all to implement equals/hashcode, which you're required to do for effectively all Collections-based usage anyway.
Re:Why databases use ordered indexes but programming uses ha...
by 91aintprime on Tuesday December 10, 2019 @10:43AM
(#21753467)
funny enough, a hash code defines an order on a set
Re:Why databases use ordered indexes but programming uses ha...
by tempguy9999 on Tuesday December 10, 2019 @01:08PM
(#21754990)
Is it in any sense a useful order though? You can assign any order to any set of objects, but you'd want it to be useful. A hash - the more hash-ey it is, the less the order means AFAICS.
Re:Why databases use ordered indexes but programming uses ha...
by n3k5 on Wednesday December 11, 2019 @09:03AM
(#21762369)
For the purpose of making a tree data structure, all linear orderings would be equally useful. Hashing only provides a partial order, so it's important to choose a hash function that won't assign the same hash to large batches of items.
But it only needs to have this property for hashes of one particular size, whereas a hash map requires a function that behaves well for a variety of hash sizes. So there's an opportunity for using a cheaper hash function.