Skip to content

Commit d76e9c2

Browse files
hkielOpenModelica-Hudson
authored andcommitted
use heap sort for ascending integer sort
Belonging to [master]: - OpenModelica/OMCompiler#2050
1 parent 0e8a738 commit d76e9c2

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Compiler/BackEnd/ResolveLoops.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ algorithm
494494
//print("there are both varCrossNodes and eqNodes\n");
495495
//at least get paths of length 2 between eqCrossNodes
496496
for i in 1:arrayLength(mIn) loop
497-
arrayUpdate(mIn, i, List.sort(mIn[i], intGt));
497+
arrayUpdate(mIn, i, List.heapSortIntList(mIn[i]));
498498
end for;
499499
for i in 1:arrayLength(mTIn) loop
500-
arrayUpdate(mTIn, i, List.sort(mTIn[i], intGt));
500+
arrayUpdate(mTIn, i, List.heapSortIntList(mTIn[i]));
501501
end for;
502502
eqCrossSet := AvlSetInt.addList(AvlSetInt.EMPTY(), eqCrossLstIn);
503503
paths := getShortPathsBetweenEqCrossNodes(AvlSetInt.listKeysReverse(eqCrossSet), eqCrossSet, mIn, mTIn, {}, findExactlyOneLoop);

Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ algorithm
15311531
for i in 1:listLength(inSparsePattern) loop
15321532
tmpTuple := arrayGet(outSparsePattern,i);
15331533
(value, tmplist) := tmpTuple;
1534-
tmplist := List.sort(tmplist, intGt);
1534+
tmplist := List.heapSortIntList(tmplist);
15351535
tmpTuple := (value, tmplist);
15361536
MetaModelica.Dangerous.arrayUpdateNoBoundsChecking(outSparsePattern, i, tmpTuple);
15371537
end for;

Compiler/Util/List.mo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ encapsulated package List
9696
"
9797

9898
protected
99+
import Array;
99100
import MetaModelica.Dangerous.{listReverseInPlace, arrayGetNoBoundsChecking, arrayUpdateNoBoundsChecking, arrayCreateNoInit};
100101
import MetaModelica.Dangerous;
101102
import DoubleEndedList;
@@ -736,6 +737,16 @@ algorithm
736737
end for;
737738
end stripN;
738739

740+
public function heapSortIntList
741+
input output list<Integer> lst;
742+
algorithm
743+
lst := match lst
744+
case {} then lst;
745+
case {_} then lst;
746+
else arrayList(Array.heapSort(listArray(lst)));
747+
end match;
748+
end heapSortIntList;
749+
739750
public function sort<T>
740751
"Sorts a list given an ordering function with the mergesort algorithm.
741752
Example:

0 commit comments

Comments
 (0)