-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifndef UNPACKING_STATISTICS_HPP | ||
#define UNPACKING_STATISTICS_HPP | ||
|
||
#include "util/typedefs.hpp" | ||
|
||
#include <utility> | ||
#include <unordered_map> | ||
|
||
namespace std | ||
{ | ||
template<> struct hash<std::pair<NodeID, NodeID>> | ||
{ | ||
typedef std::pair<NodeID, NodeID> argument_type; | ||
typedef std::size_t result_type; | ||
result_type operator()(argument_type const& pair) const noexcept | ||
{ | ||
result_type const h1 ( std::hash<unsigned int>{}(pair.first) ); | ||
result_type const h2 ( std::hash<unsigned int>{}(pair.second) ); | ||
return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion) | ||
} | ||
}; | ||
|
||
} | ||
namespace osrm | ||
{ | ||
namespace engine | ||
{ | ||
class UnpackingStatistics | ||
{ | ||
std::pair<NodeID, NodeID> edge; | ||
unsigned number_of_nodes; | ||
|
||
|
||
std::unordered_map<std::pair<NodeID, NodeID>, int> cache; | ||
int number_of_lookups; | ||
int number_of_finds; | ||
int number_of_misses; | ||
|
||
public: | ||
UnpackingStatistics(unsigned number_of_nodes) : | ||
number_of_nodes(number_of_nodes), number_of_lookups(0), number_of_finds(0), number_of_misses(0) {} | ||
// UnpackingStatistics(std::pair<NodeID, NodeID> edge) : edge(edge) {} | ||
|
||
// UnpackingStatistics() : edge(std::make_pair(SPECIAL_NODEID, SPECIAL_NODEID)) {} | ||
|
||
void Clear() | ||
{ | ||
cache.clear(); | ||
number_of_lookups = 0; | ||
number_of_finds = 0; | ||
number_of_misses = 0; | ||
} | ||
|
||
void CollectStats(std::pair<NodeID, NodeID> edge) | ||
{ | ||
|
||
// check if edge is in the map | ||
// if edge is in the map : | ||
// - increment number_of_lookups, number_of_finds | ||
// - update cache with edge:number_of_times to edge:number_of_times++ | ||
// if edge is not in map: | ||
// - increment number_of_lookups, number_of_misses | ||
// - insert edge into map with value 1 | ||
|
||
number_of_lookups = number_of_lookups + 1; | ||
|
||
if (cache.find(edge) == cache.end()) { | ||
++number_of_misses; | ||
} else { | ||
++number_of_finds; | ||
} | ||
++cache[edge]; | ||
|
||
std::cout << "Misses :" << number_of_misses << " Finds: " << number_of_finds << " Total Lookups So Far: " << number_of_lookups << std::endl; | ||
} | ||
|
||
void Print(std::pair<NodeID, NodeID> edge) | ||
{ | ||
std::cout << "{" << edge.first << ", " << edge.second << "}" << std::endl; | ||
} | ||
|
||
void Print() | ||
{ | ||
std::cout << "{I'm heeeear}" << std::endl; | ||
} | ||
}; | ||
} // engine | ||
} // osrm | ||
|
||
#endif // UNPACKING_STATISTICS_HPP |
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
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
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