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

Side by Side Diff: base/metrics/bucket_ranges.cc

Issue 10834011: Refactor of Histogram related code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/metrics/bucket_ranges.h" 5 #include "base/metrics/bucket_ranges.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 // Static table of checksums for all possible 8 bit bytes. 13 // Static table of checksums for all possible 8 bit bytes.
14 static const uint32 kCrcTable[256] = { 0x0, 0x77073096L, 0xee0e612cL, 14 const uint32 kCrcTable[256] = { 0x0, 0x77073096L, 0xee0e612cL,
15 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, 15 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L,
16 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x9b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 16 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x9b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
17 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 17 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL,
18 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 18 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL,
19 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 19 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L,
20 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 20 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL,
21 0xa50ab56bL, 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 21 0xa50ab56bL, 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
22 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 0xc8d75180L, 22 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 0xc8d75180L,
23 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL, 0x2802b89eL, 23 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL, 0x2802b89eL,
24 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 24 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 checksum_(0) {} 100 checksum_(0) {}
101 101
102 BucketRanges::~BucketRanges() {} 102 BucketRanges::~BucketRanges() {}
103 103
104 void BucketRanges::set_range(size_t i, HistogramBase::Sample value) { 104 void BucketRanges::set_range(size_t i, HistogramBase::Sample value) {
105 DCHECK_LT(i, ranges_.size()); 105 DCHECK_LT(i, ranges_.size());
106 DCHECK_GE(value, 0); 106 DCHECK_GE(value, 0);
107 ranges_[i] = value; 107 ranges_[i] = value;
108 } 108 }
109 109
110 uint32 BucketRanges::CalculateChecksum() { 110 uint32 BucketRanges::CalculateChecksum() const {
111 // Seed checksum. 111 // Seed checksum.
112 uint32 checksum = static_cast<uint32>(ranges_.size()); 112 uint32 checksum = static_cast<uint32>(ranges_.size());
113 113
114 for (size_t index = 0; index < ranges_.size(); ++index) 114 for (size_t index = 0; index < ranges_.size(); ++index)
115 checksum = Crc32(checksum, ranges_[index]); 115 checksum = Crc32(checksum, ranges_[index]);
116 return checksum; 116 return checksum;
117 } 117 }
118 118
119 bool BucketRanges::HasValidChecksum() { 119 bool BucketRanges::HasValidChecksum() const {
120 return CalculateChecksum() == checksum_; 120 return CalculateChecksum() == checksum_;
121 } 121 }
122 122
123 void BucketRanges::ResetChecksum() { 123 void BucketRanges::ResetChecksum() {
124 checksum_ = CalculateChecksum(); 124 checksum_ = CalculateChecksum();
125 } 125 }
126 126
127 bool BucketRanges::Equals(const BucketRanges* other) const { 127 bool BucketRanges::Equals(const BucketRanges* other) const {
128 if (checksum_ != other->checksum_) 128 if (checksum_ != other->checksum_)
129 return false; 129 return false;
130 if (ranges_.size() != other->ranges_.size()) 130 if (ranges_.size() != other->ranges_.size())
131 return false; 131 return false;
132 for (size_t index = 0; index < ranges_.size(); ++index) { 132 for (size_t index = 0; index < ranges_.size(); ++index) {
133 if (ranges_[index] != other->ranges_[index]) 133 if (ranges_[index] != other->ranges_[index])
134 return false; 134 return false;
135 } 135 }
136 return true; 136 return true;
137 } 137 }
138 138
139 } // namespace base 139 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698