2016-04-22 05:31:46 -04:00
|
|
|
#ifndef OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
|
|
|
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
|
|
|
|
|
|
|
#include <string>
|
2022-10-30 15:01:46 -04:00
|
|
|
#include <string_view>
|
2016-04-22 05:31:46 -04:00
|
|
|
#include <unordered_set>
|
2022-10-30 15:01:46 -04:00
|
|
|
#include <vector>
|
2016-12-15 12:27:09 -05:00
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::extractor
|
2016-04-22 05:31:46 -04:00
|
|
|
{
|
2016-07-11 11:44:58 -04:00
|
|
|
|
|
|
|
class ScriptingEnvironment;
|
|
|
|
|
2016-04-22 05:31:46 -04:00
|
|
|
// A table containing suffixes.
|
|
|
|
// At the moment, it is only a front for an unordered set. At some point we might want to make it
|
|
|
|
// country dependent and have it behave accordingly
|
|
|
|
class SuffixTable final
|
|
|
|
{
|
|
|
|
public:
|
2016-07-11 11:44:58 -04:00
|
|
|
SuffixTable(ScriptingEnvironment &scripting_environment);
|
2016-04-22 05:31:46 -04:00
|
|
|
|
|
|
|
// check whether a string is part of the know suffix list
|
|
|
|
bool isSuffix(const std::string &possible_suffix) const;
|
2022-11-04 06:49:54 -04:00
|
|
|
bool isSuffix(std::string_view possible_suffix) const;
|
2016-04-22 05:31:46 -04:00
|
|
|
|
|
|
|
private:
|
2016-12-15 12:27:09 -05:00
|
|
|
// 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;
|
2022-10-30 14:52:57 -04:00
|
|
|
std::unordered_set<std::string_view> suffix_set;
|
2016-04-22 05:31:46 -04:00
|
|
|
};
|
2016-09-12 09:24:15 -04:00
|
|
|
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::extractor
|
2016-04-22 05:31:46 -04:00
|
|
|
|
|
|
|
#endif /* OSRM_EXTRACTOR_SUFFIX_LIST_HPP_ */
|