Migrating Java TreeMap code to Scala? -


i migrating java code base pure scala , stuck on 1 piece of code. have implementation of intervalmap i.e. data structures let's efficiently map ranges [from,to] values set, delete , get operations o(log n) (slightly different intervaltree or segmenttree).

this code uses java's java.util.treemaps , while migrating scala, ran 2 big issues:

  1. scala has no mutable.treemap - decided go around using mutable.treeset (oddly scala has mutable.treeset no mutable.treemap) storing keys , storing values in auxiliary mutable.map. unpleasant hack there better way?

  2. next problem scala's mutable.treeset has no equivalent of java.util.treeset's ceilingkey, floorentry, pollfirst, polllast o(log n) operations in java.

so, how can best migrate code scala? best practices in these situations? not want write own tree implementations. there more idiomatic scala way of writing intervalmaps not aware of? or there reputable library out there? or scala plain suck here gimped treeset , non-existent treemaps. ofcourse can use java's treemap in scala ugly , lose nice scala collection features , might use java then.

here current java code: https://gist.github.com/pathikrit/5574521

the answer is, unfortunately, use java treemap class.

scala doesn't have own copy of everything, , 1 of notable exceptions. 1 of reasons it's java-compatible don't have re-invent every wheel.

the reason still want use scala not every bit of code write treemap. intervalmap can scala intervalmap; use java treemap internally implement it. or use immutable version in scala, performs reasonably immutable version.

perhaps in 2.11 or 2.12 there mutable treemap; requires write it, test it, optimize it, etc., don't think there's philosophical objection having it.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -