Question

I have a byte array which holds n records of 32 bytes, thus the array size is n*32. This arrays back up a priority queue (its a heap), where I add and remove records at will. At some point, I stop putting new records on heap, when I just have to consume the existing ones in a sorted order.

When I had a heap of objects, giving up of the heap and simply sorting the array proved to be faster in practice. I'm wondering if I can obtain the same results with the byte array.

To do so, I have to order it. Is it possible to sort it respecting the fact that each cluster of 32 bytes form a record?

Was it helpful?

Solution

Is it possible to sort it respecting the fact that each cluster of 32 bytes form a record?

Possible? algorithmically yes, but not using any of the (current) JDK's sorting functionality - unless you do some preprocessing first (the trivial path: constructing a new array of n objects and sorting it instead), which is very likely to end up costing more (performance-wise) than writing your own sorting implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top