java - TreeMap removing all keys greater than a certain key -
in project need remove objects having key value greater key (key type date
, if matters).
as far know treemap
implemented in java red-black tree binary search tree. should o(n)
when removing subtree.
can't find method other making tail view , remove 1 one, takes o(logn)
.
any ideas implementing function? believe treemap correct datastructure use , should able this.
thanks in advance
quite simple. instead of removing entries one-by-one, use map.clear()
remove elements. in code:
map.tailmap(key).clear();
Comments
Post a Comment