rchillyard / The-repository-formerly-known-as

2 stars 12 forks source link

Sort on a different kind of object that cannot be perfectly encoded #26

Closed rchillyard closed 4 years ago

rchillyard commented 4 years ago

At present, we have sorts tested for two kinds of Date, Integer, Long, Double, BigInteger, and BigDecimal. The first four of these are "perfect" encodings and not very interesting (although still a lot faster than sorting them by system sort). The third thru fifth are rather unimportant because if we had a lot of such values to sort, we would convert them into an array of primitives first and use quicksort.

I'd like to see a sort on some other kind of object which does not have perfect encoding. I haven't been able to think of a good example. But one possibility would be, say, where we want to sort a tuple for a database where the tuple includes things like name, social security number, address (including zip code). That would be a good demonstration of the idea, I think, because the normal strategy is to sort (for indexing purposes) only on the primary key (e.g. SSN). A second sort on one of the other columns would, of course, be expensive. Instead, we could define an encoding which, for example, sorted on name first, then on zip code, etc. We would have everything in our ideal order all in one shot!