| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_HUFFMAN_FREQUENCY_TRACKER_H_ | 5 #ifndef NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_HUFFMAN_BUILDER_H_ |
| 6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_HUFFMAN_FREQUENCY_TRACKER_H_ | 6 #define NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_HUFFMAN_BUILDER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace transport_security_state { | 16 namespace transport_security_state { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 class HuffmanNode; | 19 class HuffmanNode; |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 struct HuffmanRepresentation { | 22 struct HuffmanRepresentation { |
| 23 uint32_t bits; | 23 uint32_t bits; |
| 24 uint32_t number_of_bits; | 24 uint32_t number_of_bits; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // A HuffmanRepresentationTable maps the original characters to their Huffman | 27 // A HuffmanRepresentationTable maps the original characters to their Huffman |
| 28 // representation. The Huffman representation consists of the number of bits | 28 // representation. The Huffman representation consists of the number of bits |
| 29 // needed to represent the character and the actual bits. | 29 // needed to represent the character and the actual bits. |
| 30 using HuffmanRepresentationTable = std::map<uint8_t, HuffmanRepresentation>; | 30 using HuffmanRepresentationTable = std::map<uint8_t, HuffmanRepresentation>; |
| 31 using HuffmanRepresentationPair = std::pair<uint8_t, HuffmanRepresentation>; | 31 using HuffmanRepresentationPair = std::pair<uint8_t, HuffmanRepresentation>; |
| 32 | 32 |
| 33 // This class tracks the number of times each character is used and calculates | 33 // This class tracks the number of times each character is used and calculates |
| 34 // a space efficient way to represent all tracked characters by constructing a | 34 // a space efficient way to represent all tracked characters by constructing a |
| 35 // Huffman tree based on the number of times each character is seen. | 35 // Huffman tree based on the number of times each character is seen. |
| 36 class HuffmanFrequencyTracker { | 36 class HuffmanBuilder { |
| 37 public: | 37 public: |
| 38 HuffmanFrequencyTracker(); | 38 HuffmanBuilder(); |
| 39 ~HuffmanFrequencyTracker(); | 39 ~HuffmanBuilder(); |
| 40 | 40 |
| 41 // Will increase the count for |character| by one, indicating it has been | 41 // Will increase the count for |character| by one, indicating it has been |
| 42 // used. | 42 // used. |
| 43 void RecordUsage(uint8_t character); | 43 void RecordUsage(uint8_t character); |
| 44 | 44 |
| 45 // Returns a HuffmanRepresentationTable based on the usage data collected | 45 // Returns a HuffmanRepresentationTable based on the usage data collected |
| 46 // through RecordUsage(). | 46 // through RecordUsage(). |
| 47 HuffmanRepresentationTable ToTable(); | 47 HuffmanRepresentationTable ToTable(); |
| 48 | 48 |
| 49 // Outputs the Huffman representation as a vector of uint8_t's in a format | 49 // Outputs the Huffman representation as a vector of uint8_t's in a format |
| (...skipping 24 matching lines...) Expand all Loading... |
| 74 | 74 |
| 75 // Holds usage information for the tracked characters. Maps the character to | 75 // Holds usage information for the tracked characters. Maps the character to |
| 76 // the number of times its usage has been recorded through RecordUsage(). | 76 // the number of times its usage has been recorded through RecordUsage(). |
| 77 std::map<uint8_t, uint32_t> counts_; | 77 std::map<uint8_t, uint32_t> counts_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace transport_security_state | 80 } // namespace transport_security_state |
| 81 | 81 |
| 82 } // namespace net | 82 } // namespace net |
| 83 | 83 |
| 84 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_HUFFMAN_FREQUENCY_TRACKER
_H_ | 84 #endif // NET_TOOLS_TRANSPORT_SECURITY_STATE_GENERATOR_HUFFMAN_BUILDER_H_ |
| OLD | NEW |