Skip to content
Snippets Groups Projects
Commit b1bbc924 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

check heap in both directions.

parent f7b953c8
Branches
No related tags found
No related merge requests found
......@@ -89,20 +89,33 @@ int queue_get ( struct queue *q , struct qsched *s , int insist ) {
/* Fix the heap. */
w = tasks[ inds[k] ].weight;
while ( 1 ) {
if ( ( j = 2*k + 1 ) >= count )
break;
if ( j+1 < count && tasks[ inds[j] ].weight < tasks[ inds[j+1] ].weight )
j = j + 1;
if ( tasks[ inds[j] ].weight > w ) {
temp = inds[j];
inds[j] = inds[k];
inds[k] = temp;
k = j;
if ( k > 0 && w > tasks[ inds[k/2] ].weight )
while ( k > 0 ) {
j = k / 2;
if ( w > tasks[ inds[j] ].weight ) {
temp = inds[j];
inds[j] = inds[k];
inds[k] = temp;
k = j;
}
else
break;
}
else
while ( 1 ) {
if ( ( j = 2*k + 1 ) >= count )
break;
if ( j+1 < count && tasks[ inds[j] ].weight < tasks[ inds[j+1] ].weight )
j = j + 1;
if ( tasks[ inds[j] ].weight > w ) {
temp = inds[j];
inds[j] = inds[k];
inds[k] = temp;
k = j;
}
else
break;
}
else
break;
}
} /* did we get a task? */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment