Lines Matching refs:INDEX
18 * Optionally objects may know their index into the priority queue. The queue will update the index
19 * as the objects move through the queue. This is enabled by using a non-nullptr function for INDEX.
20 * When an INDEX function is provided random deletes from the queue are allowed using remove().
22 * afterwards. In debug builds the index will be set to -1 before an element is removed from the
27 int* (*INDEX)(const T&) = (int* (*)(const T&))nullptr>
48 SkDEBUGCODE(if (SkToBool(INDEX)) { *INDEX(fArray[0]) = -1; })
65 int index = fArray.count();
68 this->percolateUpIfNecessary(index);
72 /** Random access removal. This requires that the INDEX function is non-nullptr. */
74 SkASSERT(nullptr != INDEX);
75 int index = *INDEX(entry);
76 SkASSERT(index >= 0 && index < fArray.count());
78 SkDEBUGCODE(*INDEX(fArray[index]) = -1;)
79 if (index == fArray.count() - 1) {
83 fArray[index] = fArray[fArray.count() - 1];
85 this->setIndex(index);
86 this->percolateUpOrDown(index);
92 allowed if an INDEX function is provided. */
94 SkASSERT(nullptr != INDEX);
95 int index = *INDEX(entry);
96 SkASSERT(index >= 0 && index < fArray.count());
97 this->validate(index);
98 this->percolateUpOrDown(index);
102 /** Gets the item at index i in the priority queue (for i < this->count()). at(0) is equivalent
123 void percolateUpOrDown(int index) {
124 SkASSERT(index >= 0);
125 if (!percolateUpIfNecessary(index)) {
126 this->validate(index);
127 this->percolateDownIfNecessary(index);
131 bool percolateUpIfNecessary(int index) {
132 SkASSERT(index >= 0);
135 if (0 == index) {
136 this->setIndex(index);
139 int p = ParentOf(index);
140 if (LESS(fArray[index], fArray[p])) {
141 SkTSwap(fArray[index], fArray[p]);
142 this->setIndex(index);
143 index = p;
146 this->setIndex(index);
149 this->validate(index);
153 void percolateDownIfNecessary(int index) {
154 SkASSERT(index >= 0);
156 int child = LeftOf(index);
160 this->setIndex(index);
166 if (LESS(fArray[child], fArray[index])) {
167 SkTSwap(fArray[child], fArray[index]);
169 this->setIndex(index);
178 if (LESS(fArray[child], fArray[index])) {
179 SkTSwap(fArray[child], fArray[index]);
180 this->setIndex(index);
181 index = child;
184 this->setIndex(index);
187 this->validate(index);
191 void setIndex(int index) {
192 SkASSERT(index < fArray.count());
193 if (SkToBool(INDEX)) {
194 *INDEX(fArray[index]) = index;
204 SkASSERT(!SkToBool(INDEX) || *INDEX(fArray[i]) == i);