upper_bound / lower_bound for java.util.TreeMap?  
Author Message
Sylvain





PostPosted: 2005-2-7 21:48:00 Top

java-programmer, upper_bound / lower_bound for java.util.TreeMap? Dear all,

I have to convert some c++ STL code using extensively the function
upper_bound and lower_bound of STL's map<>.

As I am quite new to Java Collection (I am trying to use the 1.5 generics)
I am a bit confused, because no method return iterator for example...

Could somebody give me a first hint for getting something similar to
upper/lower_bound with java collections? Is there a workaround or a third
party library doing it that I missed while googling?

Thank you very much in advance,

Sylvain
 
Sylvain





PostPosted: 2005-2-15 16:53:00 Top

java-programmer >> upper_bound / lower_bound for java.util.TreeMap? > I have to convert some c++ STL code using extensively the function
> upper_bound and lower_bound of STL's map<>.

Well, finally I found some hints myself:

- in SortedMap/Set, headMap/Set(x).last() is essentially an
upper_bound(x), tailMap/Set(x).first() is essentially a lower_bound(x),
and it is possible to use subMap/Set to have an equal_range

- the source code for TreeMap/Set contains a lot of very interesting
private internal function in a not so confused way. Some of them are
directly upper_bound lower_bound and things like that. I think writing a
specialized class using this code could be a good idea to obtain a much
richer interface to the power of the red/black tree algorithm for eg.