OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTDPQueue_DEFINED | 8 #ifndef SkTDPQueue_DEFINED |
9 #define SkTDPQueue_DEFINED | 9 #define SkTDPQueue_DEFINED |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 allowed if an INDEX function is provided. */ | 85 allowed if an INDEX function is provided. */ |
86 void priorityDidChange(T entry) { | 86 void priorityDidChange(T entry) { |
87 SkASSERT(NULL != INDEX); | 87 SkASSERT(NULL != INDEX); |
88 int index = *INDEX(entry); | 88 int index = *INDEX(entry); |
89 SkASSERT(index >= 0 && index < fArray.count()); | 89 SkASSERT(index >= 0 && index < fArray.count()); |
90 this->validate(index); | 90 this->validate(index); |
91 this->percolateUpOrDown(index); | 91 this->percolateUpOrDown(index); |
92 this->validate(); | 92 this->validate(); |
93 } | 93 } |
94 | 94 |
95 #ifdef SK_DEBUG | 95 /** Gets the item at index i in the priority queue (for i < this->count()).
at(0) is equivalent |
| 96 to peek(). Otherwise, there is no guarantee about ordering of elements i
n the queue. */ |
96 T at(int i) const { return fArray[i]; } | 97 T at(int i) const { return fArray[i]; } |
97 #endif | |
98 | 98 |
99 private: | 99 private: |
100 static int LeftOf(int x) { SkASSERT(x >= 0); return 2 * x + 1; } | 100 static int LeftOf(int x) { SkASSERT(x >= 0); return 2 * x + 1; } |
101 static int ParentOf(int x) { SkASSERT(x > 0); return (x - 1) >> 1; } | 101 static int ParentOf(int x) { SkASSERT(x > 0); return (x - 1) >> 1; } |
102 | 102 |
103 void percolateUpOrDown(int index) { | 103 void percolateUpOrDown(int index) { |
104 SkASSERT(index >= 0); | 104 SkASSERT(index >= 0); |
105 if (!percolateUpIfNecessary(index)) { | 105 if (!percolateUpIfNecessary(index)) { |
106 this->validate(index); | 106 this->validate(index); |
107 this->percolateDownIfNecessary(index); | 107 this->percolateDownIfNecessary(index); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 #endif | 187 #endif |
188 } | 188 } |
189 | 189 |
190 SkTDArray<T> fArray; | 190 SkTDArray<T> fArray; |
191 | 191 |
192 typedef SkNoncopyable INHERITED; | 192 typedef SkNoncopyable INHERITED; |
193 }; | 193 }; |
194 | 194 |
195 #endif | 195 #endif |
OLD | NEW |