Implements Zero-Copy String Views onto Contiguous Memory, resolves #3265.
- http://www.boost.org/doc/libs/1_61_0/libs/utility/doc/html/string_ref.html - http://en.cppreference.com/w/cpp/string/basic_string_view
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "util/string_view.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
@@ -21,9 +23,20 @@ class SuffixTable final
|
||||
|
||||
// check whether a string is part of the know suffix list
|
||||
bool isSuffix(const std::string &possible_suffix) const;
|
||||
bool isSuffix(util::StringView possible_suffix) const;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> suffix_set;
|
||||
// Store lower-cased strings in SuffixTable and a set of StringViews for quick membership
|
||||
// checks.
|
||||
//
|
||||
// Why not uset<StringView>? StringView is non-owning, the vector<string> holds the string
|
||||
// contents, the set<StringView> only holds [first,last) pointers into the vector.
|
||||
//
|
||||
// Then why not simply uset<string>? Because membership tests against StringView keys would
|
||||
// require us to first convert StringViews into strings (allocation), do the membership,
|
||||
// and destroy the StringView again.
|
||||
std::vector<std::string> suffixes;
|
||||
std::unordered_set<util::StringView> suffix_set;
|
||||
};
|
||||
|
||||
} /* namespace extractor */
|
||||
|
||||
Reference in New Issue
Block a user