6#include <unordered_map>
23 const std::string * s;
25 explicit SymbolStr(
const std::string & symbol): s(&symbol) {}
28 bool operator == (std::string_view s2)
const
33 operator const std::string & ()
const
38 operator const std::string_view ()
const
43 friend std::ostream & operator <<(std::ostream & os,
const SymbolStr & symbol);
58 explicit Symbol(uint32_t
id): id(
id) {}
63 explicit operator bool()
const {
return id > 0; }
65 bool operator<(
const Symbol other)
const {
return id < other.id; }
66 bool operator==(
const Symbol other)
const {
return id == other.id; }
67 bool operator!=(
const Symbol other)
const {
return id != other.id; }
77 std::unordered_map<std::string_view, std::pair<const std::string *, uint32_t>> symbols;
92 auto it = symbols.find(s);
93 if (it != symbols.end())
return Symbol(it->second.second + 1);
95 const auto & [rawSym, idx] = store.add(std::string(s));
96 symbols.emplace(rawSym, std::make_pair(&rawSym, idx));
102 if (s.id == 0 || s.id > store.size())
112 size_t totalSize()
const;
115 void dump(T callback)
const
117 store.forEach(callback);
Definition chunked-vector.hh:21
Definition symbol-table.hh:19
Definition symbol-table.hh:75
Symbol create(std::string_view s)
Definition symbol-table.hh:85
Definition symbol-table.hh:52