Lines Matching refs:idx
78 void sift_up(size_t idx);
79 void sift_down(size_t idx);
97 size_t idx = size(); // index of last element since 1-indexed
98 indices.insert({a, idx});
99 sift_up(idx); // get the pq back in order
106 size_t idx = indices[a];
107 if (idx >= pq.size()) {
110 if (idx == size()) { // if a is the last element, i.e. at index idx == size() == (pq.size()-1)
115 // move last element (guaranteed not to be at idx) to idx, then delete a
117 pq[idx] = last_a;
119 indices[last_a] = idx;
122 // get the heap back in order (since the element at idx is not in order)
123 sift_up(idx);
124 sift_down(idx);
134 const size_t idx = 1;
135 if (idx == size()) { // if a is the last element
140 // move last element (guaranteed not to be at idx) to idx, then delete a
142 pq[idx] = last_a;
144 indices[last_a] = idx;
147 // get the heap back in order (since the element at idx is not in order)
148 sift_down(idx);
171 void indexed_priority_queue<AA, Comparator>::sift_up(size_t idx) {
172 while (idx > 1) {
173 size_t parent = idx / 2;
174 if (higher(idx, parent))
175 swap_indices(idx, parent);
178 idx = parent;
183 void indexed_priority_queue<AA, Comparator>::sift_down(size_t idx) {
184 while (2 * idx <= size()) {
185 size_t child = 2 * idx;
187 if (higher(child, idx))
188 swap_indices(child, idx);
191 idx = child;