Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: net/tools/domain_security_preload_generator/trie/trie_bit_buffer.h

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: fix base64 issue and accidental replace. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
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_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
7
8 #include <stdint.h>
9
10 #include <vector>
11
12 #include "net/tools/domain_security_preload_generator/bit_writer.h"
13 #include "net/tools/domain_security_preload_generator/huffman/huffman_frequency_ tracker.h"
14
15 namespace net {
16
17 // TrieBitBuffer acts as a buffer for TrieWriter. It can write bits, characters,
18 // and positions. The characters are stored as their Huffmanrepresentation.
agl 2016/12/06 18:51:36 Huffmanrepresentation -> HuffmanRepresentation
martijnc 2016/12/07 22:37:54 Done.
19 // Positions are references to other locations in the trie.
20 class TrieBitBuffer {
21 public:
22 TrieBitBuffer();
23 ~TrieBitBuffer();
24
25 // Write |bit| to the buffer.
26 void WriteBit(uint8_t bit);
27
28 // Write the last |number_of_bits| from |bits| to the buffer.
29 void WriteBits(uint32_t bits, uint8_t number_of_bits);
30
31 // Write a position the the buffer. Actually stores the difference between
32 // |position| and |last_position|. |last_position| will updated to equal the
agl 2016/12/06 18:51:36 "be" after "will"
martijnc 2016/12/07 22:37:54 Done.
33 // input |position|.
34 void WritePosition(int position, int* last_position);
35
36 // Write the character in |byte| to the buffer using its Huffman
37 // representation in |table|. Optionally tracks usage of the character in
38 // |tracker|.
39 void WriteChar(uint8_t byte,
40 const HuffmanRepresentationTable& table,
41 HuffmanFrequencyTracker* tracker);
42
43 // Write the entire buffer to |writer|.
agl 2016/12/06 18:51:36 Comment should say what the return value is.
martijnc 2016/12/07 22:37:54 Done.
44 uint32_t WriteToBitWriter(BitWriter& writer);
45
46 // Appends the buffered bits in |current_byte_| to |elements_|. empty bits
47 // are filled with zero's.
48 void Close();
agl 2016/12/06 18:51:36 Likewise, I'd probably call this Flush.
martijnc 2016/12/07 22:37:54 Renamed.
49
50 private:
51 // Represents either the last |number_of_bits| bits in |bits| or a position
52 // (offset) in the trie.
53 struct BitsOrPosition {
54 uint8_t bits;
55 uint8_t number_of_bits;
56 int position;
57 };
58
59 // Returns the minimum number of bits needed to represent |input|.
60 uint8_t BitLength(int input) const;
61
62 // Append a new element to |elements_|.
63 void AppendBitsElement(uint8_t bits, uint8_t number_of_bits);
64 void AppendPositionElement(int position);
65
66 // Buffers bits until it can fill a byte.
67 uint8_t current_byte_;
agl 2016/12/06 18:51:36 I would use " = 0" syntax for these rather than se
martijnc 2016/12/07 22:37:54 Done.
68
69 // The number of bits currently in |current_byte_|.
70 uint32_t used_;
71
72 std::vector<BitsOrPosition> elements_;
73 };
74
75 } // namespace net
76
77 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698