OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 NET_BASE_PRIORITY_QUEUE_H_ | 5 #ifndef NET_BASE_PRIORITY_QUEUE_H_ |
6 #define NET_BASE_PRIORITY_QUEUE_H_ | 6 #define NET_BASE_PRIORITY_QUEUE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 DCHECK(CalledOnValidThread()); | 257 DCHECK(CalledOnValidThread()); |
258 for (size_t i = 0; i < lists_.size(); ++i) { | 258 for (size_t i = 0; i < lists_.size(); ++i) { |
259 lists_[i].clear(); | 259 lists_[i].clear(); |
260 } | 260 } |
261 #if !defined(NDEBUG) | 261 #if !defined(NDEBUG) |
262 valid_ids_.clear(); | 262 valid_ids_.clear(); |
263 #endif | 263 #endif |
264 size_ = 0u; | 264 size_ = 0u; |
265 } | 265 } |
266 | 266 |
267 // This can be used to iterate through the composite container, in | |
268 // highest-to-lowest, first-inserted-to-last order. | |
269 Pointer NextHighest(const Pointer& previous) { | |
szym
2013/11/15 01:11:49
Is this any different from GetNextTowardsLastMin?
oystein (OOO til 10th of July)
2013/11/15 03:02:10
This patch was written before GetNextTowardsLastMi
| |
270 Priority priority = previous.priority_; | |
271 typename Pointer::ListIterator list_entry = previous.iterator_; | |
272 | |
273 if (list_entry != lists_[priority].end()) { | |
274 ++list_entry; | |
275 } | |
276 | |
277 while (priority < lists_.size()) { | |
278 if (list_entry == lists_[priority].end()) { | |
279 if (priority == 0) { | |
280 break; | |
281 } | |
282 priority--; | |
283 list_entry = lists_[priority].begin(); | |
284 } else { | |
285 return Pointer(priority, list_entry); | |
286 } | |
287 } | |
288 | |
289 return Pointer(); | |
290 } | |
291 | |
267 // Returns the number of priorities the queue supports. | 292 // Returns the number of priorities the queue supports. |
268 size_t num_priorities() const { | 293 size_t num_priorities() const { |
269 DCHECK(CalledOnValidThread()); | 294 DCHECK(CalledOnValidThread()); |
270 return lists_.size(); | 295 return lists_.size(); |
271 } | 296 } |
272 | 297 |
273 bool empty() const { | 298 bool empty() const { |
274 DCHECK(CalledOnValidThread()); | 299 DCHECK(CalledOnValidThread()); |
275 return size_ == 0; | 300 return size_ == 0; |
276 } | 301 } |
(...skipping 14 matching lines...) Expand all Loading... | |
291 | 316 |
292 ListVector lists_; | 317 ListVector lists_; |
293 size_t size_; | 318 size_t size_; |
294 | 319 |
295 DISALLOW_COPY_AND_ASSIGN(PriorityQueue); | 320 DISALLOW_COPY_AND_ASSIGN(PriorityQueue); |
296 }; | 321 }; |
297 | 322 |
298 } // namespace net | 323 } // namespace net |
299 | 324 |
300 #endif // NET_BASE_PRIORITY_QUEUE_H_ | 325 #endif // NET_BASE_PRIORITY_QUEUE_H_ |
OLD | NEW |