A generic map from ranges to values based on a TreeMap backed by Scala's red-black tree.
The underlying data structure is a TreeMap backed by a Red-black tree mapping from a lower bound of K
to a
RangeEntry[K, V]
, sorted by an implicit Ordering[K]
. Overlapping ranges are allowed with put
, non overlapping
ranges are handled using putCoalesce
.
sbt
"com.charlesahunt" %% "range-tree-map" % "0.3.1"
mill
ivy"com.charlesahunt::range-tree-map:0.3.1"
import scala.math.Ordering._
val rangeMap = RangeTreeMap.apply[Int, String]
val rangeKey = RangeKey[Int](lower = 5, upper = 10)
rangeMap.put(rangeKey, "exampleValue")
For more examples and usage, please refer to the Wiki
- 0.3.1
- Fix bug in putCoalesce with intersections on different values
- 0.3.0
- Complete putCoalesce - First release with full functionality
- 0.2.3
- Fix put to create discreet ranges, refactor putCoalesce which still needs to be completed
- 0.2.2
- Fix bug with intersection which reverses the result lower and upper bound in the RangeKey
- 0.2.1
- Rough completion of putCoalescing along with intersection and disjoint
- 0.1.5
- Fix inclusive bugs in enclose and intersects functionality, add tests
- 0.1.4
- Initial design and structuring, some basic functionality
Charles Hunt – Website – charlesalberthunt@gmail.com
Distributed under the MIT license. See LICENSE
for more information.