diff --git a/src/storm/utility/string.cpp b/src/storm/utility/string.cpp index 536bacf24..7eca8b754 100644 --- a/src/storm/utility/string.cpp +++ b/src/storm/utility/string.cpp @@ -6,7 +6,7 @@ namespace storm { namespace utility { namespace string { - SimilarStrings::SimilarStrings(std::string reference, double similarityFactor, bool caseSensitive) : reference(reference), similarityFactor(similarityFactor), caseSensitive(caseSensitive), cmp([](std::pair const& lhs, std::pair const& rhs) { return lhs.first > rhs.first; }), distances(cmp) { + SimilarStrings::SimilarStrings(std::string reference, double similarityFactor, bool caseSensitive) : reference(reference), similarityFactor(similarityFactor), caseSensitive(caseSensitive) { // intentionally left empty. } @@ -20,11 +20,9 @@ namespace storm { } std::vector SimilarStrings::toList() const { - auto distancesCopy = distances; std::vector result; - while (!distancesCopy.empty()) { - result.push_back(distancesCopy.top().second); - distancesCopy.pop(); + for (auto const& dist : distances) { + result.push_back(dist.second); } return result; } @@ -37,11 +35,10 @@ namespace storm { } else if (size == 1) { return "Did you mean " + result + "?"; } else { - return "Did you mean any of [" + result + "]?"; + return "Did you mean any of [ " + result + " ]?"; } } - uint64_t levenshteinDistance(std::string const& lhs, std::string const& rhs, bool caseSensitive) { std::vector> d(lhs.size() + 1, std::vector(rhs.size() + 1, 0ull)); for (uint64_t row = 1; row < d.size(); ++row) { diff --git a/src/storm/utility/string.h b/src/storm/utility/string.h index 6b44992c5..1b749e9bf 100644 --- a/src/storm/utility/string.h +++ b/src/storm/utility/string.h @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include namespace storm { namespace utility { @@ -40,8 +39,13 @@ namespace storm { std::string reference; double similarityFactor; bool caseSensitive; - std::function const&, std::pair const&)> cmp; - std::priority_queue, std::vector>, decltype(cmp)> distances; + + struct comp { + bool operator() (std::pair const& lhs, std::pair const& rhs) const { + return lhs.first < rhs.first ? true : (lhs.first == rhs.first && lhs.second < rhs.second); + } + }; + std::set, comp> distances; }; /*!