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

Popular posts from this blog

python 3.x - Mapping specific letters onto a list of words -

javascript - jquery or ashx not working -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -