MCPcopy Create free account
hub / github.com/F-Stack/f-stack / HeapDown

Method HeapDown

adapter/micro_thread/heap.h:197–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197inline void HeapList::HeapDown(int index)
198{
199 int min_son;
200 for (int pos = index; pos <= _count; pos = min_son)
201 {
202 if (pos*2 > _count) // pos is a leaf node.
203 {
204 break;
205 }
206 else if (pos*2 == _count)
207 {
208 min_son = pos*2;
209 }
210 else
211 {
212 if (_list[pos*2+1]->HeapValueCmp(_list[pos*2]) < 0)
213 {
214 min_son = pos*2+1;
215 }
216 else
217 {
218 min_son = pos*2;
219 }
220 }
221
222 if (_list[pos]->HeapValueCmp(_list[min_son]) > 0)
223 {
224 HeapEntry* tmp = _list[min_son];
225 _list[min_son] = _list[pos];
226 _list[pos] = tmp;
227
228 _list[pos]->SetIndex(pos);
229 _list[min_son]->SetIndex(min_son);
230 }
231 else
232 {
233 break;
234 }
235 }
236}
237
238
239inline int HeapList::HeapPush(HeapEntry* item)

Callers

nothing calls this directly

Calls 2

HeapValueCmpMethod · 0.80
SetIndexMethod · 0.80

Tested by

no test coverage detected