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:
scala has no
mutable.treemap- decided go around usingmutable.treeset(oddly scala hasmutable.treesetnomutable.treemap) storing keys , storing values in auxiliarymutable.map. unpleasant hack there better way?next problem scala's
mutable.treesethas no equivalent ofjava.util.treeset'sceilingkey,floorentry,pollfirst,polllasto(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
Post a Comment