Why ceiling and floor are missing in TreeSet and TreeMap?

For example, if I want to get the max value which is less than 4 in TreeSet(1, 3, 5), I have to use code like TreeSet(1, 3, 5).to(4).max or TreeSet(1, 3, 5).maxBy(x => if (x < 4) x else Int.MinValue). But these code will create an new intermediate TreeSet, which leads to higher complexity of O(n). But in a red-black tree, this operation should only take O(logn). And in Java, ceiling and floor are provided in TreeSet. Why they are missing in Scala?

Hi, that’s a good point. We could add these operations. Could you please open an issue in the collection-strawman repository?

Thank you! I opened one. #298

1 Like