Created
February 11, 2015 15:21
-
-
Save riebl/e98b6ae98a63c5e75e65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 08b3ec9698ba21b724bb7f54897fa30dfbbac1f3 Mon Sep 17 00:00:00 2001 | |
From: Raphael Riebl <raphael.riebl@thi.de> | |
Date: Wed, 11 Feb 2015 16:15:40 +0100 | |
Subject: ObstacleControl: use unordered_map for CacheEntries | |
Change implemented by Stefan Neumeier | |
--- | |
src/veins/modules/obstacle/ObstacleControl.h | 20 ++++++++++++++++++-- | |
1 file changed, 18 insertions(+), 2 deletions(-) | |
diff --git a/src/veins/modules/obstacle/ObstacleControl.h b/src/veins/modules/obstacle/ObstacleControl.h | |
index 42dc610..19dc9c0 100644 | |
--- a/src/veins/modules/obstacle/ObstacleControl.h | |
+++ b/src/veins/modules/obstacle/ObstacleControl.h | |
@@ -22,7 +22,7 @@ | |
#define OBSTACLE_OBSTACLECONTROL_H | |
#include <list> | |
- | |
+#include <unordered_map> | |
#include <omnetpp.h> | |
#include "veins/base/utils/Coord.h" | |
#include "veins/modules/obstacle/Obstacle.h" | |
@@ -78,12 +78,28 @@ class ObstacleControl : public cSimpleModule | |
} | |
}; | |
+ struct KeyEqual { | |
+ bool operator()(const CacheKey& lhs, const CacheKey& rhs) const | |
+ { | |
+ return lhs.receiverPos == rhs.receiverPos && lhs.senderPos == rhs.senderPos; | |
+ } | |
+ }; | |
+ | |
+ struct KeyHash { | |
+ std::size_t operator()(const CacheKey& k) const | |
+ { | |
+ std::hash<double> dblHash; | |
+ return dblHash(k.senderPos.x) ^ dblHash(k.senderPos.y) ^ dblHash(k.senderPos.z) ^ | |
+ dblHash(k.receiverPos.x) ^ dblHash(k.receiverPos.y) ^ dblHash(k.receiverPos.z); | |
+ } | |
+ }; | |
+ | |
enum { GRIDCELL_SIZE = 1024 }; | |
typedef std::list<Obstacle*> ObstacleGridCell; | |
typedef std::vector<ObstacleGridCell> ObstacleGridRow; | |
typedef std::vector<ObstacleGridRow> Obstacles; | |
- typedef std::map<CacheKey, double> CacheEntries; | |
+ typedef std::unordered_map<CacheKey, double, KeyHash, KeyEqual> CacheEntries; | |
bool debug; /**< whether to emit debug messages */ | |
cXMLElement* obstaclesXml; /**< obstacles to add at startup */ | |
-- | |
2.2.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment