diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/multi_level_queue.h | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/common/multi_level_queue.h b/src/common/multi_level_queue.h index fc72a8238..d56ab6531 100644 --- a/src/common/multi_level_queue.h +++ b/src/common/multi_level_queue.h | |||
| @@ -107,6 +107,9 @@ public: | |||
| 107 | iterator_impl(const iterator_impl<false>& other) | 107 | iterator_impl(const iterator_impl<false>& other) |
| 108 | : mlq(other.mlq), it(other.it), current_priority(other.current_priority) {} | 108 | : mlq(other.mlq), it(other.it), current_priority(other.current_priority) {} |
| 109 | 109 | ||
| 110 | iterator_impl(const iterator_impl<true>& other) | ||
| 111 | : mlq(other.mlq), it(other.it), current_priority(other.current_priority) {} | ||
| 112 | |||
| 110 | iterator_impl& operator=(const iterator_impl<false>& other) { | 113 | iterator_impl& operator=(const iterator_impl<false>& other) { |
| 111 | mlq = other.mlq; | 114 | mlq = other.mlq; |
| 112 | it = other.it; | 115 | it = other.it; |
| @@ -149,7 +152,7 @@ public: | |||
| 149 | using iterator = iterator_impl<false>; | 152 | using iterator = iterator_impl<false>; |
| 150 | using const_iterator = iterator_impl<true>; | 153 | using const_iterator = iterator_impl<true>; |
| 151 | 154 | ||
| 152 | void add(T& element, u32 priority, bool send_back = true) { | 155 | void add(const T& element, u32 priority, bool send_back = true) { |
| 153 | if (send_back) | 156 | if (send_back) |
| 154 | levels[priority].push_back(element); | 157 | levels[priority].push_back(element); |
| 155 | else | 158 | else |
| @@ -158,23 +161,18 @@ public: | |||
| 158 | } | 161 | } |
| 159 | 162 | ||
| 160 | void remove(const T& element, u32 priority) { | 163 | void remove(const T& element, u32 priority) { |
| 161 | levels[priority].erase(ListIterateTo(levels[priority], element)); | 164 | auto it = ListIterateTo(levels[priority], element); |
| 165 | if (it == levels[priority].end()) | ||
| 166 | return; | ||
| 167 | levels[priority].erase(it); | ||
| 162 | if (levels[priority].empty()) { | 168 | if (levels[priority].empty()) { |
| 163 | used_priorities &= ~(1ULL << priority); | 169 | used_priorities &= ~(1ULL << priority); |
| 164 | } | 170 | } |
| 165 | } | 171 | } |
| 166 | 172 | ||
| 167 | void adjust(const T& element, u32 old_priority, u32 new_priority, bool adjust_front = false) { | 173 | void adjust(const T& element, u32 old_priority, u32 new_priority, bool adjust_front = false) { |
| 168 | const auto new_next = | 174 | remove(element, old_priority); |
| 169 | adjust_front ? levels[new_priority].cbegin() : levels[new_priority].cend(); | 175 | add(element, new_priority, !adjust_front); |
| 170 | ListSplice(levels[new_priority], new_next, levels[old_priority], | ||
| 171 | ListIterateTo(levels[old_priority], element)); | ||
| 172 | |||
| 173 | used_priorities |= 1ULL << new_priority; | ||
| 174 | |||
| 175 | if (levels[old_priority].empty()) { | ||
| 176 | used_priorities &= ~(1ULL << old_priority); | ||
| 177 | } | ||
| 178 | } | 176 | } |
| 179 | void adjust(const_iterator it, u32 old_priority, u32 new_priority, bool adjust_front = false) { | 177 | void adjust(const_iterator it, u32 old_priority, u32 new_priority, bool adjust_front = false) { |
| 180 | adjust(*it, old_priority, new_priority, adjust_front); | 178 | adjust(*it, old_priority, new_priority, adjust_front); |