Split scala treeset from ordered object

50 views Asked by At

My use-case is very simple and looks like caching so maybe something like Guava is useful but I use scala and prefer not to pull in Guava if I dont need to.

case class AAA(index:Double) extends Ordered[AAA] {
    override def compare(that: AAA): Int = index.compare(that.index)
}
var aaaSet = mutable.TreeSet[AAA]()

AAA's mostly come in the set in increasing order but the index value might be lower then what already exists. What I need is a simple function that removes elements lower than a certain index (a Double). This does not -need- to be exact as long nothing above the index gets deleted. I can do this with O(log(n)) complexity but since I always can start at the bottom of the set(or head) I think it can be done more efficient. Obviously I quickly end up with caching libs but these indexes are not time-based and I need up to millions of these sets in my program (hence the wish to go faster then O(log(n))).

Some help and direction to possible solutions are much appreciated. Even if it means that O(log(n)) means best performance.

1

There are 1 answers

0
ovanwijk On BEST ANSWER

Even though it is not really the solution I was looking for I think this will be an ok solution:

aaaSet = aaaSet.dropWhile(aa => aa.index < 1.3)