#pragma once #include #include #include #include namespace chatterino { class Prefix { public: Prefix(const QString &string); bool operator==(const Prefix &other) const; bool isStartOf(const QString &string) const; private: QChar first; QChar second; friend struct std::hash; }; } // namespace chatterino namespace std { template <> struct hash { size_t operator()(const chatterino::Prefix &prefix) const { return (size_t(prefix.first.unicode()) << 16) | size_t(prefix.second.unicode()); } }; } // namespace std namespace chatterino { class UsernameSet { public: static constexpr int PrefixLength = 2; using Iterator = std::set::iterator; using ConstIterator = std::set::const_iterator; class Range { public: Range(ConstIterator start, ConstIterator end); ConstIterator begin(); ConstIterator end(); private: ConstIterator start_; ConstIterator end_; }; ConstIterator begin() const; ConstIterator end() const; Range subrange(const Prefix &prefix) const; std::set::size_type size() const; std::pair insert(const QString &value); std::pair insert(QString &&value); private: void insertPrefix(const QString &string); std::set items; std::unordered_map firstKeyForPrefix; }; } // namespace chatterino