1 // Copyright 2018 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_TOOLS_HUFFMAN_TRIE_TRIE_ENTRY_H_ 6 #define NET_TOOLS_HUFFMAN_TRIE_TRIE_ENTRY_H_ 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 namespace net::huffman_trie { 13 14 class TrieBitBuffer; 15 16 class TrieEntry { 17 public: 18 TrieEntry(); 19 virtual ~TrieEntry(); 20 21 // The name to be used when inserting the entry to the trie. E.g. for HSTS 22 // preload list, this is the hostname. 23 virtual std::string name() const = 0; 24 virtual bool WriteEntry(huffman_trie::TrieBitBuffer* writer) const = 0; 25 }; 26 27 // std::unique_ptr's are not covariant, so operations on TrieEntry uses a vector 28 // of raw pointers instead. 29 using TrieEntries = std::vector<TrieEntry*>; 30 31 // ReversedEntry points to a TrieEntry and contains the reversed name for 32 // that entry. This is used to construct the trie. 33 struct ReversedEntry { 34 ReversedEntry(std::vector<uint8_t> reversed_name, const TrieEntry* entry); 35 ~ReversedEntry(); 36 37 std::vector<uint8_t> reversed_name; 38 const TrieEntry* entry; 39 }; 40 41 using ReversedEntries = std::vector<std::unique_ptr<ReversedEntry>>; 42 43 } // namespace net::huffman_trie 44 45 #endif // NET_TOOLS_HUFFMAN_TRIE_TRIE_ENTRY_H_ 46