简体   繁体   中英

std::map::lower_bound or std::map::upper_bound when the key is not contained?

If I well understand, in a given map m : If I want to find the first key greater or equal to a given key k , I use m.lower_bound(k) . If I want to find the first key strictly greater than a given key k , I use m.upper_bound(k) .

If I still well understand, there is no difference if the key k is not contained yet in the map m . In this specific case (I KNOW my map doesn't contain the key), is there any reason to chose one or the other ? Is there one faster than the other ?

Note: I don't use C++11/14/17 for compatibility reason.

According to standard, they both run in Logarithmic time and it doens't really matter if you map contains the key or not. If there are differences in performance it will be platform specific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM