| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 public: | 42 public: |
| 43 typedef uint32 Priority; | 43 typedef uint32 Priority; |
| 44 | 44 |
| 45 // A pointer to a value stored in the queue. The pointer becomes invalid | 45 // A pointer to a value stored in the queue. The pointer becomes invalid |
| 46 // when the queue is destroyed or cleared, or the value is erased. | 46 // when the queue is destroyed or cleared, or the value is erased. |
| 47 class Pointer { | 47 class Pointer { |
| 48 public: | 48 public: |
| 49 // Constructs a null pointer. | 49 // Constructs a null pointer. |
| 50 Pointer() : priority_(kNullPriority) {} | 50 Pointer() : priority_(kNullPriority) { |
| 51 #if !defined(NDEBUG) |
| 52 id_ = static_cast<size_t>(-1); |
| 53 #endif |
| 54 } |
| 51 | 55 |
| 52 bool is_null() const { return priority_ == kNullPriority; } | 56 bool is_null() const { return priority_ == kNullPriority; } |
| 53 | 57 |
| 54 Priority priority() const { return priority_; } | 58 Priority priority() const { return priority_; } |
| 55 | 59 |
| 56 #if !defined(NDEBUG) | 60 #if !defined(NDEBUG) |
| 57 const T& value() const { return iterator_->second; } | 61 const T& value() const { return iterator_->second; } |
| 58 #else | 62 #else |
| 59 const T& value() const { return *iterator_; } | 63 const T& value() const { return *iterator_; } |
| 60 #endif | 64 #endif |
| 61 | 65 |
| 62 // Comparing to Pointer from a different PriorityQueue is undefined. | 66 // Comparing to Pointer from a different PriorityQueue is undefined. |
| 63 bool Equals(const Pointer& other) const { | 67 bool Equals(const Pointer& other) const { |
| 64 return (priority_ == other.priority_) && (iterator_ == other.iterator_); | 68 return (priority_ == other.priority_) && (iterator_ == other.iterator_); |
| 65 } | 69 } |
| 66 | 70 |
| 71 void Reset() { |
| 72 *this = Pointer(); |
| 73 } |
| 74 |
| 67 private: | 75 private: |
| 68 friend class PriorityQueue; | 76 friend class PriorityQueue; |
| 69 | 77 |
| 70 // Note that we need iterator not const_iterator to pass to List::erase. | 78 // Note that we need iterator not const_iterator to pass to List::erase. |
| 71 // When C++0x comes, this could be changed to const_iterator and const could | 79 // When C++0x comes, this could be changed to const_iterator and const could |
| 72 // be added to First, Last, and OldestLowest. | 80 // be added to First, Last, and OldestLowest. |
| 73 typedef typename PriorityQueue::List::iterator ListIterator; | 81 typedef typename PriorityQueue::List::iterator ListIterator; |
| 74 | 82 |
| 75 static const Priority kNullPriority = static_cast<Priority>(-1); | 83 static const Priority kNullPriority = static_cast<Priority>(-1); |
| 76 | 84 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 #endif | 213 #endif |
| 206 | 214 |
| 207 ListVector lists_; | 215 ListVector lists_; |
| 208 size_t size_; | 216 size_t size_; |
| 209 }; | 217 }; |
| 210 | 218 |
| 211 } // namespace net | 219 } // namespace net |
| 212 | 220 |
| 213 #endif // NET_BASE_PRIORITY_QUEUE_H_ | 221 #endif // NET_BASE_PRIORITY_QUEUE_H_ |
| 214 | 222 |
| OLD | NEW |