Skip to content

Commit

Permalink
fix reheap when sorting the array
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2048
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Nov 24, 2017
1 parent 68ab904 commit 0e8a738
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Compiler/Util/Array.mo
Expand Up @@ -84,11 +84,11 @@ end mapNoCopy_1;

protected function downheap
input output array<Integer> inArray;
input Integer n;
input Integer vIn;
protected
Integer v = vIn;
Integer w = 2*v+1;
Integer n = arrayLength(inArray);
Integer tmp;
algorithm
while w<n loop
Expand All @@ -114,16 +114,15 @@ protected
Integer n = arrayLength(inArray);
Integer tmp;
algorithm
for v in (intDiv(arrayLength(inArray),2)-1):-1:0 loop
downheap(inArray, v);
for v in (intDiv(n,2)-1):-1:0 loop
inArray := downheap(inArray, n, v);
end for;
while n>1 loop
n := n - 1;
for v in n:-1:2 loop
tmp := inArray[1];
inArray[1] := inArray[n+1];
inArray[n+1] := tmp;
downheap(inArray, 0);
end while;
inArray[1] := inArray[v];
inArray[v] := tmp;
inArray := downheap(inArray, v-1, 0);
end for;
end heapSort;

function findFirstOnTrue<T>
Expand Down

0 comments on commit 0e8a738

Please sign in to comment.