- UInt currentIndex = startIndex;
- ItemValue* startItemValue = heap->array->datas[startIndex];
- while (C_TRUE)
- {
- if (currentIndex * heap->arity >= heap->array->size)
- {
- // moving element has landed (in a leaf): apply final affectation
- heap->array->datas[currentIndex] = startItemValue;
- break;
- }
- // find top child (min or max)
- UInt topChildIndex;
- Real topChildValue = (heap->hType == MIN_T ? INFINITY : -INFINITY);
- for (Int i=0; i<heap->arity; i++)
- {
- UInt childIndex = i + currentIndex * heap->arity;
- if (childIndex >= heap->array->size)
- break;
- Real childValue = ((ItemValue*)(heap->array->datas[childIndex]))->value;
- if ((heap->hType == MIN_T && childValue < topChildValue) ||
- (heap->hType == MAX_T && childValue > topChildValue))
- {
- topChildIndex = childIndex;
- topChildValue = childValue;
- }
- }
- // compare to top child
- if ((heap->hType == MIN_T && startItemValue->value > topChildValue) ||
- (heap->hType == MAX_T && startItemValue->value < topChildValue))
- {
- // move one level down: the child goes one level up
- heap->array->datas[currentIndex] = heap->array->datas[topChildIndex];
- }
- else
- {
- // moving element has landed: apply final affectation
- heap->array->datas[currentIndex] = startItemValue;
- break;
- }
- currentIndex = topChildIndex;
- }
+ UInt currentIndex = startIndex;
+ ItemValue* startItemValue = heap->array->datas[startIndex];
+ while (true)
+ {
+ if (currentIndex * heap->arity >= heap->array->size)
+ {
+ // moving element has landed (in a leaf): apply final affectation
+ heap->array->datas[currentIndex] = startItemValue;
+ break;
+ }
+ // find top child (min or max)
+ UInt topChildIndex;
+ Real topChildValue = (heap->hType == MIN_T ? INFINITY : -INFINITY);
+ for (UInt i = 0; i < heap->arity; i++)
+ {
+ UInt childIndex = i + currentIndex * heap->arity;
+ if (childIndex >= heap->array->size)
+ break;
+ Real childValue = ((ItemValue*)(heap->array->datas[childIndex]))->value;
+ if ((heap->hType == MIN_T && childValue < topChildValue) ||
+ (heap->hType == MAX_T && childValue > topChildValue))
+ {
+ topChildIndex = childIndex;
+ topChildValue = childValue;
+ }
+ }
+ // compare to top child
+ if ((heap->hType == MIN_T && startItemValue->value > topChildValue) ||
+ (heap->hType == MAX_T && startItemValue->value < topChildValue))
+ {
+ // move one level down: the child goes one level up
+ heap->array->datas[currentIndex] = heap->array->datas[topChildIndex];
+ }
+ else
+ {
+ // moving element has landed: apply final affectation
+ heap->array->datas[currentIndex] = startItemValue;
+ break;
+ }
+ currentIndex = topChildIndex;
+ }