| Index: components/metrics/leak_detector/ranked_list.h
|
| diff --git a/components/metrics/leak_detector/ranked_list.h b/components/metrics/leak_detector/ranked_list.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1588a2e51e8ea2d96538fec8138841e61ecf1ee1
|
| --- /dev/null
|
| +++ b/components/metrics/leak_detector/ranked_list.h
|
| @@ -0,0 +1,71 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_LIST_H_
|
| +#define COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_LIST_H_
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include <vector>
|
| +
|
| +#include "components/metrics/leak_detector/leak_detector_value_type.h"
|
| +#include "components/metrics/leak_detector/stl_allocator.h"
|
| +#include <gperftools/custom_allocator.h>
|
| +
|
| +// RankedList lets you add entries and automatically sorts them internally, so
|
| +// they can be accessed in sorted order. The entries are stored as a vector
|
| +// array.
|
| +
|
| +namespace leak_detector {
|
| +
|
| +class RankedList {
|
| + public:
|
| + using ValueType = LeakDetectorValueType;
|
| +
|
| + // A single entry in the RankedList. The RankedList sorts entries by |count|.
|
| + struct Entry {
|
| + int count;
|
| + ValueType value;
|
| + };
|
| +
|
| + RankedList(size_t max_size) : max_size_(max_size) {
|
| + entries_.reserve(max_size + 1);
|
| + }
|
| + ~RankedList() {}
|
| +
|
| + // Access individual element. Does not do boundary checking.
|
| + const Entry& entry(int index) const {
|
| + return entries_[index];
|
| + }
|
| + size_t size() const {
|
| + return entries_.size();
|
| + }
|
| +
|
| + // Add a new value-count pair to the list. Does not check for existing entries
|
| + // with the same value.
|
| + void Add(const ValueType& value, int count);
|
| +
|
| + private:
|
| + // Returns the position to insert a new value. Returns -1 if it cannot be
|
| + // inserted.
|
| + int GetInsertionIndex(int count) const;
|
| +
|
| + // Max and min counts.
|
| + const int max_count() const {
|
| + return entries_.empty() ? 0 : entries_[0].count;
|
| + }
|
| + const int min_count() const {
|
| + return entries_.empty() ? 0 : entries_[size() - 1].count;
|
| + }
|
| +
|
| + // Max number of items in the list.
|
| + size_t max_size_;
|
| +
|
| + // Points to the array of entries.
|
| + std::vector<Entry, STL_Allocator<Entry, CustomAllocator>> entries_;
|
| +};
|
| +
|
| +} // namespace leak_detector
|
| +
|
| +#endif // COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_LIST_H_
|
|
|