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

Side by Side Diff: components/safe_browsing_db/v4_rice.h

Issue 2228393003: PVer4: DecodeHashes needs to sort the output of the Rice decoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_checksum
Patch Set: Fix the corresponding test in v4_store_unittest.cc also Created 4 years, 4 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Rice-Golomb decoder for blacklist updates. 5 // Rice-Golomb decoder for blacklist updates.
6 // Details at: https://en.wikipedia.org/wiki/Golomb_coding 6 // Details at: https://en.wikipedia.org/wiki/Golomb_coding
7 7
8 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 8 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
9 #define COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 9 #define COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 public: 58 public:
59 // Decodes the Rice-encoded string in |encoded_data| as a list of integers 59 // Decodes the Rice-encoded string in |encoded_data| as a list of integers
60 // and stores them in |out|. |rice_parameter| is the exponent of 2 for 60 // and stores them in |out|. |rice_parameter| is the exponent of 2 for
61 // calculating 'M', |first_value| is the first value in the output sequence, 61 // calculating 'M', |first_value| is the first value in the output sequence,
62 // |num_entries| is the number of subsequent encoded entries. Each decoded 62 // |num_entries| is the number of subsequent encoded entries. Each decoded
63 // value is a positive offset from the previous value. 63 // value is a positive offset from the previous value.
64 // So, for instance, if the unencoded sequence is: [3, 7, 25], then 64 // So, for instance, if the unencoded sequence is: [3, 7, 25], then
65 // |first_value| = 3, |num_entries| = 2 and decoding the |encoded_data| will 65 // |first_value| = 3, |num_entries| = 2 and decoding the |encoded_data| will
66 // produce the offsets: [4, 18]. 66 // produce the offsets: [4, 18].
67 static V4DecodeResult DecodeIntegers( 67 static V4DecodeResult DecodeIntegers(
68 const ::google::protobuf::int32 first_value, 68 const ::google::protobuf::int64 first_value,
69 const ::google::protobuf::int32 rice_parameter, 69 const ::google::protobuf::int32 rice_parameter,
70 const ::google::protobuf::int32 num_entries, 70 const ::google::protobuf::int32 num_entries,
71 const std::string& encoded_data, 71 const std::string& encoded_data,
72 ::google::protobuf::RepeatedField<::google::protobuf::int32>* out); 72 ::google::protobuf::RepeatedField<::google::protobuf::int32>* out);
73 73
74 // Decodes the Rice-encoded string in |encoded_data| as a string of 4-byte 74 // Decodes the Rice-encoded string in |encoded_data| as a string of 4-byte
75 // hash prefixes and stores them in |out|. The rest of the arguments are the 75 // hash prefixes and stores them in |out|. The rest of the arguments are the
76 // same as for |DecodeIntegers|. 76 // same as for |DecodeIntegers|.
77 static V4DecodeResult DecodeBytes( 77 static V4DecodeResult DecodeBytes(
78 const ::google::protobuf::int32 first_value, 78 const ::google::protobuf::int64 first_value,
79 const ::google::protobuf::int32 rice_parameter, 79 const ::google::protobuf::int32 rice_parameter,
80 const ::google::protobuf::int32 num_entries, 80 const ::google::protobuf::int32 num_entries,
81 const std::string& encoded_data, 81 const std::string& encoded_data,
82 std::string* out); 82 std::string* out);
83 83
84 virtual ~V4RiceDecoder(); 84 virtual ~V4RiceDecoder();
85 85
86 std::string DebugString() const; 86 std::string DebugString() const;
87 87
88 private: 88 private:
89 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextWordWithNoData); 89 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextWordWithNoData);
90 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextBitsWithNoData); 90 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextBitsWithNoData);
91 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoData); 91 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoData);
92 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoEntries); 92 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithNoEntries);
93 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithSmallValues); 93 friend class V4RiceTest;
94 FRIEND_TEST_ALL_PREFIXES(V4RiceTest, TestDecoderGetNextValueWithLargeValues);
95 94
96 // Validate some of the parameters passed to the decode methods. 95 // Validate some of the parameters passed to the decode methods.
97 static V4DecodeResult ValidateInput( 96 static V4DecodeResult ValidateInput(
98 const ::google::protobuf::int32 rice_parameter, 97 const ::google::protobuf::int32 rice_parameter,
99 const ::google::protobuf::int32 num_entries, 98 const ::google::protobuf::int32 num_entries,
100 const std::string& encoded_data); 99 const std::string& encoded_data);
101 100
102 // The |rice_parameter| is the exponent of 2 for calculating 'M', 101 // The |rice_parameter| is the exponent of 2 for calculating 'M',
103 // |num_entries| is the number of encoded entries in the |encoded_data| and 102 // |num_entries| is the number of encoded entries in the |encoded_data| and
104 // |encoded_data| is the Rice-encoded string to decode. 103 // |encoded_data| is the Rice-encoded string to decode.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // The 32-bit value read from |data_|. All bit reading operations operate on 146 // The 32-bit value read from |data_|. All bit reading operations operate on
148 // |current_word_|. 147 // |current_word_|.
149 uint32_t current_word_; 148 uint32_t current_word_;
150 }; 149 };
151 150
152 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder); 151 std::ostream& operator<<(std::ostream& os, const V4RiceDecoder& rice_decoder);
153 152
154 } // namespace safe_browsing 153 } // namespace safe_browsing
155 154
156 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_ 155 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_RICE_H_
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_rice.cc » ('j') | components/safe_browsing_db/v4_rice.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698