As I commented in the other thread, you can (in principle) do better than this by combining the pop and push operations: Maintaining a fixed size "top N" values list - #7 by stevengj (and that implementation also accepts an arbitrary Ordering).
As I commented in the other thread, you can (in principle) do better than this by combining the pop and push operations: Maintaining a fixed size "top N" values list - #7 by stevengj (and that implementation also accepts an arbitrary Ordering).