Here is the topic in this section.
It seems that SortedMap can help you get involved, but what I have tested so far, I'm not sure if this is O (log (n)), what the search should be:
def searchMap(m: SortedMap[Int,_], k: Int) = { val left = m to(k) lastKey val right = m from(k) take(2) lastKey if (k - left < right - k) left else right }
Based on the definitions of from and to in terms of rangeImpl , it looks like it could be O (log (n)), but, based on the actual time of it, it seems to grow linearly for all plausible values โโof n.
So I'm not sure.
Owen
source share