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

Side by Side Diff: base/id_map.h

Issue 604048: Correctly recognize emptiness of IDMap. (Closed)
Patch Set: Created 10 years, 10 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
« no previous file with comments | « no previous file | base/id_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef BASE_ID_MAP_H_ 5 #ifndef BASE_ID_MAP_H_
6 #define BASE_ID_MAP_H_ 6 #define BASE_ID_MAP_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 if (iteration_depth_ == 0) { 76 if (iteration_depth_ == 0) {
77 Releaser<OS, 0>::release(i->second); 77 Releaser<OS, 0>::release(i->second);
78 data_.erase(i); 78 data_.erase(i);
79 } else { 79 } else {
80 removed_ids_.insert(id); 80 removed_ids_.insert(id);
81 } 81 }
82 } 82 }
83 83
84 bool IsEmpty() const { 84 bool IsEmpty() const {
85 return data_.empty(); 85 return size() == 0u;
86 } 86 }
87 87
88 T* Lookup(KeyType id) const { 88 T* Lookup(KeyType id) const {
89 typename HashTable::const_iterator i = data_.find(id); 89 typename HashTable::const_iterator i = data_.find(id);
90 if (i == data_.end()) 90 if (i == data_.end())
91 return NULL; 91 return NULL;
92 return i->second; 92 return i->second;
93 } 93 }
94 94
95 size_t size() const { 95 size_t size() const {
96 return data_.size(); 96 return data_.size() - removed_ids_.size();
97 } 97 }
98 98
99 // It is safe to remove elements from the map during iteration. All iterators 99 // It is safe to remove elements from the map during iteration. All iterators
100 // will remain valid. 100 // will remain valid.
101 template<class ReturnType> 101 template<class ReturnType>
102 class Iterator { 102 class Iterator {
103 public: 103 public:
104 Iterator(IDMap<T>* map) 104 Iterator(IDMap<T>* map)
105 : map_(map), 105 : map_(map),
106 iter_(map_->data_.begin()) { 106 iter_(map_->data_.begin()) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 HashTable data_; 190 HashTable data_;
191 191
192 // See description above setter. 192 // See description above setter.
193 bool check_on_null_data_; 193 bool check_on_null_data_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(IDMap); 195 DISALLOW_COPY_AND_ASSIGN(IDMap);
196 }; 196 };
197 197
198 #endif // BASE_ID_MAP_H_ 198 #endif // BASE_ID_MAP_H_
OLDNEW
« no previous file with comments | « no previous file | base/id_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698