I have almost the same question as mentioned in Data structures that can map a range of keys to a value, but for Scala.
That is, I'd like to have a mutable system of non-overlapping 1D ranges [a[i], b[i]) that would map to some sort of value v[i]. A standard underlying data structure to do this kind of job is a red-black tree.
Operations that I'd like it to have, preferably all of them should have complexity of O(log n):
So, I guess so far I see the following variants, all of which have their cons:
floorEntry
Am I missing something here? Are there any Guava-like well-maintained collections extensions libraries using Scala-centric APIs that extend basic Scala collections?
Strongly related questions:
I'd most probably encapsulate Guava's RangeMap
. All you need is a three method class, behind which you can hide the non-scalaish collection.
I was curious how hard it'd be to roll my own Java NavigableMap
-based solution, and it's pretty trivial:
MyValue
containing (start, end, stored value)MyValue
With only 40 lines in Java with Lombok (and probably fewer in Scala), I wouldn't be afraid of any maintenance. I wrote just a very rudimentary test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With