Hacker News new | past | comments | ask | show | jobs | submit login

I don't see how you can add that level of indirection if you can only sort an array of numbers. Let's say you have a Person object with property 'age' which is an Int. I can put the Person's ages into an Int Array and sort that. Where to add this indirection to get to the sorted array of Person objects?



1. Have an immutable container of Persons named `persons`

2. Have another container named `indices` representing the index or iterator into your Persons container

In C++:

3. `std::sort(begin(indices), end(indices), [&](int lhs, int rhs)->bool{ return persons[lhs].age() < persons[rhs].age(); });`

I don't know Java but I am sure there are many ways to do it in Java.


Eh yes, this works, but you are not using Arrays.intSort here. Which means that the optimizations that the article is about won't apply. intSort (or any other of the sorts in the article) works purely on an Array of Ints, moving them around and comparing them to each other.

It's quite hard to come up with something that we could use in every day programming that will benefit from the new optimizations.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: