| OLD | NEW |
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 | 60 |
| 61 if (iteration_depth_ == 0) | 61 if (iteration_depth_ == 0) |
| 62 data_.erase(i); | 62 data_.erase(i); |
| 63 else | 63 else |
| 64 removed_ids_.insert(id); | 64 removed_ids_.insert(id); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool IsEmpty() const { | 67 bool IsEmpty() const { |
| 68 return data_.empty(); | 68 return size() == 0u; |
| 69 } | 69 } |
| 70 | 70 |
| 71 T* Lookup(int32 id) const { | 71 T* Lookup(int32 id) const { |
| 72 typename HashTable::const_iterator i = data_.find(id); | 72 typename HashTable::const_iterator i = data_.find(id); |
| 73 if (i == data_.end()) | 73 if (i == data_.end()) |
| 74 return NULL; | 74 return NULL; |
| 75 return i->second; | 75 return i->second; |
| 76 } | 76 } |
| 77 | 77 |
| 78 size_t size() const { | 78 size_t size() const { |
| 79 return data_.size(); | 79 return data_.size() - removed_ids_.size(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // It is safe to remove elements from the map during iteration. All iterators | 82 // It is safe to remove elements from the map during iteration. All iterators |
| 83 // will remain valid. | 83 // will remain valid. |
| 84 template<class ReturnType> | 84 template<class ReturnType> |
| 85 class Iterator { | 85 class Iterator { |
| 86 public: | 86 public: |
| 87 Iterator(IDMap<T>* map) | 87 Iterator(IDMap<T>* map) |
| 88 : map_(map), | 88 : map_(map), |
| 89 iter_(map_->data_.begin()) { | 89 iter_(map_->data_.begin()) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 HashTable data_; | 154 HashTable data_; |
| 155 | 155 |
| 156 // See description above setter. | 156 // See description above setter. |
| 157 bool check_on_null_data_; | 157 bool check_on_null_data_; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(IDMap); | 159 DISALLOW_COPY_AND_ASSIGN(IDMap); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 #endif // BASE_ID_MAP_H_ | 162 #endif // BASE_ID_MAP_H_ |
| OLD | NEW |