Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
use heap sort for ascending integer sort
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #2050
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Nov 24, 2017
1 parent 0e8a738 commit d76e9c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/ResolveLoops.mo
Expand Up @@ -494,10 +494,10 @@ algorithm
//print("there are both varCrossNodes and eqNodes\n");
//at least get paths of length 2 between eqCrossNodes
for i in 1:arrayLength(mIn) loop
arrayUpdate(mIn, i, List.sort(mIn[i], intGt));
arrayUpdate(mIn, i, List.heapSortIntList(mIn[i]));
end for;
for i in 1:arrayLength(mTIn) loop
arrayUpdate(mTIn, i, List.sort(mTIn[i], intGt));
arrayUpdate(mTIn, i, List.heapSortIntList(mTIn[i]));
end for;
eqCrossSet := AvlSetInt.addList(AvlSetInt.EMPTY(), eqCrossLstIn);
paths := getShortPathsBetweenEqCrossNodes(AvlSetInt.listKeysReverse(eqCrossSet), eqCrossSet, mIn, mTIn, {}, findExactlyOneLoop);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/SymbolicJacobian.mo
Expand Up @@ -1531,7 +1531,7 @@ algorithm
for i in 1:listLength(inSparsePattern) loop
tmpTuple := arrayGet(outSparsePattern,i);
(value, tmplist) := tmpTuple;
tmplist := List.sort(tmplist, intGt);
tmplist := List.heapSortIntList(tmplist);
tmpTuple := (value, tmplist);
MetaModelica.Dangerous.arrayUpdateNoBoundsChecking(outSparsePattern, i, tmpTuple);
end for;
Expand Down
11 changes: 11 additions & 0 deletions Compiler/Util/List.mo
Expand Up @@ -96,6 +96,7 @@ encapsulated package List
"

protected
import Array;
import MetaModelica.Dangerous.{listReverseInPlace, arrayGetNoBoundsChecking, arrayUpdateNoBoundsChecking, arrayCreateNoInit};
import MetaModelica.Dangerous;
import DoubleEndedList;
Expand Down Expand Up @@ -736,6 +737,16 @@ algorithm
end for;
end stripN;

public function heapSortIntList
input output list<Integer> lst;
algorithm
lst := match lst
case {} then lst;
case {_} then lst;
else arrayList(Array.heapSort(listArray(lst)));
end match;
end heapSortIntList;

public function sort<T>
"Sorts a list given an ordering function with the mergesort algorithm.
Example:
Expand Down

0 comments on commit d76e9c2

Please sign in to comment.