简体   繁体   中英

Searching a map<pair<int, int>, ...> with lower and upper bound

I would like to know if looking up a map that takes a pair of ints (coordinates) as a key with lower_bound and upper_bound has any usable meaning?

using Point = std::pair<int, int>;
std::map<Point, Vertex> vertex_map = {};

const auto p = std::make_pair(0, 0);
const auto q = std::make_pair(10, 10);

auto foo = vertex_map.lower_bound(p);
auto bar = vertex_map.upper_bound(q);

Particularly, I would like to check if the map contains any vertices bound by the given rectangle (p, q).

No, I don't think it's possible. You need a comparator such that p < x && x < p iff x is bound by Rectangle (p, q) and this comparator must define a strict weak ordering

As far as I can tell this is not possible.

The way this problem is tackled in an efficient manner is to hold two lists: one with the points ordered by the x component and the other with the points ordered by the y component.

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