From 43f0aa04f227b5b244dd100b916915b3bda7aa37 Mon Sep 17 00:00:00 2001 From: "lperron@google.com" Date: Wed, 22 Sep 2010 09:33:12 +0000 Subject: [PATCH] Improve AdjustablePriorityQueue implementation --- base/adjustable_priority_queue.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/base/adjustable_priority_queue.h b/base/adjustable_priority_queue.h index c7d8b143ef..ec5fb5a2bc 100644 --- a/base/adjustable_priority_queue.h +++ b/base/adjustable_priority_queue.h @@ -34,9 +34,9 @@ template class AdjustablePriorityQueue { } void Remove(T* const val) { - int i = val->GetHeapIndex(); - if (i == Size() - 1) { - elems_.resize(Size()-1); + const int i = val->GetHeapIndex(); + if (i == elems_.size() - 1) { + elems_.pop_back(); return; } elems_[i] = elems_.back(); @@ -71,18 +71,18 @@ template class AdjustablePriorityQueue { int Size() const { return elems_.size(); } - bool IsEmpty() const { return elems_.size() == 0; } + bool IsEmpty() const { return elems_.empty(); } - void Clear() { elems_.resize(0); } + void Clear() { elems_.clear(); } void CheckValid() const { - for (int i = 0; i < Size(); ++i) { - int left_child = 1 + 2 * i; - if (left_child < Size()) { + for (int i = 0; i < elems_.size(); ++i) { + const int left_child = 1 + 2 * i; + if (left_child < elems_.size()) { CHECK_GE(elems_[i], elems_[left_child]); } - int right_child = left_child + 1; - if (right_child < Size()) { + const int right_child = left_child + 1; + if (right_child < elems_.size()) { CHECK_GE(elems_[i], elems_[right_child]); } }