1
Fork 0
mirror of https://github.com/Jaxan/hybrid-ads.git synced 2025-04-27 06:57:44 +02:00

Changes to unordered_map instead of map (1.5x speedup in reading)

This commit is contained in:
Joshua Moerman 2015-07-10 10:14:59 +02:00
parent a9e3fdfd1c
commit 33657de56a
2 changed files with 9 additions and 8 deletions

View file

@ -66,7 +66,7 @@ mealy read_mealy_from_txt(const std::string & filename) {
mealy read_mealy_from_dot(std::istream & in, translation & t){
mealy m;
std::map<std::string, state> state_indices;
std::unordered_map<std::string, state> state_indices;
state max_state = 0;
string line;
@ -142,7 +142,7 @@ std::pair<mealy, translation> read_mealy_from_dot(const string & filename){
template <typename T>
std::vector<std::string> create_reverse_map_impl(std::map<std::string, T> const & indices) {
std::vector<std::string> create_reverse_map_impl(std::unordered_map<std::string, T> const & indices) {
std::vector<std::string> ret(indices.size());
for (auto && p : indices) {
ret[p.second] = p.first;
@ -150,7 +150,7 @@ std::vector<std::string> create_reverse_map_impl(std::map<std::string, T> const
return ret;
}
std::vector<string> create_reverse_map(const std::map<string, input> & indices) {
std::vector<string> create_reverse_map(const std::unordered_map<string, input> & indices) {
return create_reverse_map_impl(indices);
}

View file

@ -3,7 +3,8 @@
#include "types.hpp"
#include <iosfwd>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
struct mealy;
@ -27,16 +28,16 @@ std::pair<mealy, translation> read_mealy_from_dot(std::string const & filename);
/// \brief For non-integral formats we use a translation to integers
struct translation {
std::map<std::string, input> input_indices;
std::unordered_map<std::string, input> input_indices;
input max_input = 0;
std::map<std::string, output> output_indices;
std::unordered_map<std::string, output> output_indices;
output max_output = 0;
};
/// \brief inverts the input_indices and output_indices maps
std::vector<std::string> create_reverse_map(std::map<std::string, input> const & indices);
std::vector<std::string> create_reverse_map(std::map<std::string, output> const & indices);
std::vector<std::string> create_reverse_map(std::unordered_map<std::string, input> const & indices);
std::vector<std::string> create_reverse_map(std::unordered_map<std::string, output> const & indices);
/// \brief defines trivial translation (the string represent integers directly)
translation create_translation_for_mealy(mealy const & m);