Embolden domain in SSL clock interstitial.
[chromium-blink-merge.git] / base / metrics / sample_map.cc
blob42468cb57f31816fa6a5fbd0c2c5e734a86c6773
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
3 // found in the LICENSE file.
5 #include "base/metrics/sample_map.h"
7 #include "base/logging.h"
9 using std::map;
11 namespace base {
13 typedef HistogramBase::Count Count;
14 typedef HistogramBase::Sample Sample;
16 SampleMap::SampleMap() {}
18 SampleMap::~SampleMap() {}
20 void SampleMap::Accumulate(Sample value, Count count) {
21 sample_counts_[value] += count;
22 IncreaseSum(count * value);
23 IncreaseRedundantCount(count);
26 Count SampleMap::GetCount(Sample value) const {
27 map<Sample, Count>::const_iterator it = sample_counts_.find(value);
28 if (it == sample_counts_.end())
29 return 0;
30 return it->second;
33 Count SampleMap::TotalCount() const {
34 Count count = 0;
35 for (map<Sample, Count>::const_iterator it = sample_counts_.begin();
36 it != sample_counts_.end();
37 ++it) {
38 count += it->second;
40 return count;
43 scoped_ptr<SampleCountIterator> SampleMap::Iterator() const {
44 return scoped_ptr<SampleCountIterator>(new SampleMapIterator(sample_counts_));
47 bool SampleMap::AddSubtractImpl(SampleCountIterator* iter,
48 HistogramSamples::Operator op) {
49 Sample min;
50 Sample max;
51 Count count;
52 for (; !iter->Done(); iter->Next()) {
53 iter->Get(&min, &max, &count);
54 if (min + 1 != max)
55 return false; // SparseHistogram only supports bucket with size 1.
56 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count;
58 return true;
61 SampleMapIterator::SampleMapIterator(const SampleToCountMap& sample_counts)
62 : iter_(sample_counts.begin()),
63 end_(sample_counts.end()) {}
65 SampleMapIterator::~SampleMapIterator() {}
67 bool SampleMapIterator::Done() const {
68 return iter_ == end_;
71 void SampleMapIterator::Next() {
72 DCHECK(!Done());
73 iter_++;
76 void SampleMapIterator::Get(Sample* min, Sample* max, Count* count) const {
77 DCHECK(!Done());
78 if (min != NULL)
79 *min = iter_->first;
80 if (max != NULL)
81 *max = iter_->first + 1;
82 if (count != NULL)
83 *count = iter_->second;
86 } // namespace base