作者: luckiejacky 時間: 2015-10-20 11:05 標題: unordered_set 點可以有兩種Compare behaviour?
- struct NodePoolKey {
- NodePoolKey(int minX, int maxX, int minZ, int maxZ, long t) {
- this->minX = minX;
- this->minZ = minZ;
- this->maxX = maxX;
- this->maxZ = maxZ;
- this->t = t;
- }
- bool operator==(const NodePoolKey& other) const
- {
- return (this->minX == other.minX) &&
- (this->minZ == other.minZ) &&
- (this->maxX == other.maxZ) &&
- (this->maxZ == other.maxZ) &&
- (this->t == other.t);
- }
-
- bool overlaps(const NodePoolKey& a, const NodePoolKey& b) const {
- if (a.maxX < b.minX) return false; // a is left of b
- if (a.minX > b.maxX) return false; // a is right of b
- if (a.maxZ < b.minZ) return false; // a is above b
- if (a.minZ > b.maxZ) return false;
- TRACE("overlaps");
- return true;
- }
- int minX;
- int maxX;
- int minZ;
- int maxZ;
- long t;
- };
同range
- if(tbl.find(key) != tbl.end())
- {
- // do equality checks
- }
- ///////
- if(tbl.find(key) != tbl.end())
- {
- // do range checks
- }
