set.h 997 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "comptrie_trie.h"
  3. template <typename T = char>
  4. class TCompactTrieSet: public TCompactTrie<T, ui8, TNullPacker<ui8>> {
  5. public:
  6. typedef TCompactTrie<T, ui8, TNullPacker<ui8>> TBase;
  7. using typename TBase::TBuilder;
  8. using typename TBase::TKey;
  9. using typename TBase::TKeyBuf;
  10. using typename TBase::TSymbol;
  11. TCompactTrieSet() = default;
  12. explicit TCompactTrieSet(const TBlob& data)
  13. : TBase(data)
  14. {
  15. }
  16. template <typename D>
  17. explicit TCompactTrieSet(const TCompactTrie<T, D, TNullPacker<D>>& trie)
  18. : TBase(trie.Data()) // should be binary compatible for any D
  19. {
  20. }
  21. TCompactTrieSet(const char* data, size_t len)
  22. : TBase(data, len)
  23. {
  24. }
  25. bool Has(const typename TBase::TKeyBuf& key) const {
  26. return TBase::Find(key.data(), key.size());
  27. }
  28. bool FindTails(const typename TBase::TKeyBuf& key, TCompactTrieSet<T>& res) const {
  29. return TBase::FindTails(key, res);
  30. }
  31. };