sorting - Can you sort a mutable Scala collection in place? -


is possible sort arraybuffer, or other mutable scala collection, in place? see arraybuffer.sorted (and sortby) returns new collection, , sorting.quicksort sort array in place doesn't work on arraybuffers.

the reason ask i'm using combinebykey in spark build collections of scored objects limited in size (like "top ten" list key). if merge in new object , collection @ capacity, need drop lowest-scored object. use sorted collection priorityqueue or sortedset, don't need keep collections sorted time, in case when collection fills up.

so there way sort arraybuffer or listbuffer in place? or there other collection supports appending , sorting in place? i'm sure there's better way this, i'm new scala.

there presently no facilities sorting collections in place. said, if expect have sorting extremely rarely, investigate supporting both separately e.g. either[priorityqueue[a], arraybuffer[a]]; or if expect sorting common should use data structure don't pay such penalty each time add element--meaning use sortedset or priorityqueue. otherwise you'll slow really fast. (n^2 log n gets big quickly, if full sort each time add new element.)


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -