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

Unified Diff: third_party/tcmalloc/chromium/src/ranked_list.h

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Author label from new files; Check type in LeakDetectorValueType comparators; Add missing fi… Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/ranked_list.h
diff --git a/third_party/tcmalloc/chromium/src/ranked_list.h b/third_party/tcmalloc/chromium/src/ranked_list.h
new file mode 100644
index 0000000000000000000000000000000000000000..ac3caeaaca73c2b25530ff010e340c3bf550f000
--- /dev/null
+++ b/third_party/tcmalloc/chromium/src/ranked_list.h
@@ -0,0 +1,70 @@
+// Copyright (c) 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 _RANKED_LIST_H_
+#define _RANKED_LIST_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/custom_allocator.h"
+#include "base/stl_allocator.h"
+#include "leak_detector_value_type.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 // _RANKED_LIST_H_

Powered by Google App Engine
This is Rietveld 408576698