Skip to content

Commit

Permalink
Implement and use List.listArrayReverse()
Browse files Browse the repository at this point in the history
as a short cut for listArray(listReverse(lst))
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Mar 14, 2016
1 parent 6d761ce commit 0bcc79a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -121,7 +121,7 @@ algorithm
vlst := list(arrayGet(ass2, e) for e guard(arrayGet(ass2, e) > 0) in elst);
end for;

outAcc := listArray(listReverse(acc));
outAcc := List.listArrayReverse(acc);
end eqnAssignmentNonScalar;

public function varAssignmentNonScalar
Expand Down
8 changes: 3 additions & 5 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -2264,10 +2264,8 @@ algorithm
outIncidenceArrayT := fillincidenceMatrixT(row, row_indices, outIncidenceArrayT);
end for;

iarr := Dangerous.listReverseInPlace(iarr);
imap := Dangerous.listReverseInPlace(imap);
outIncidenceArray := listArray(iarr);
omapIncRowEqn := listArray(imap);
outIncidenceArray := List.listArrayReverse(iarr);
omapIncRowEqn := List.listArrayReverse(imap);
end incidenceMatrixDispatchScalar;

protected function fillincidenceMatrixT
Expand Down Expand Up @@ -3866,7 +3864,7 @@ algorithm
// index = numberOfEqs (we reach the end)
case (_, _, _, _, _, _, false, _, _, _, _, _)
then
(listArray(listReverse(inIncidenceArray)),inIncidenceArrayT,listArray(listReverse(imapEqnIncRow)),listArray(listReverse(imapIncRowEqn)));
(List.listArrayReverse(inIncidenceArray),inIncidenceArrayT,List.listArrayReverse(imapEqnIncRow),List.listArrayReverse(imapIncRowEqn));

// index < numberOfEqs
case (_, _, iArr, _, _, _, true, _, _, _, _ , _)
Expand Down
3 changes: 1 addition & 2 deletions Compiler/BackEnd/OnRelaxation.mo
Expand Up @@ -1403,8 +1403,7 @@ algorithm
outMT := List.fold1(lst, Array.consToElement, i, outMT);
m := lst::m;
end for;
m := Dangerous.listReverseInPlace(m);
outM := listArray(m);
outM := List.listArrayReverse(m);
outMT := mT;
end getOrphansIncidenceMatrix;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -465,7 +465,7 @@ protected
algorithm
if foundSimple then
// transform simpleeqns to array
simpleeqns := listArray(listReverse(iSimpleeqnslst));
simpleeqns := List.listArrayReverse(iSimpleeqnslst);
// collect and handle sets
(vars, eqnslst, shared, repl) := handleSets(arrayLength(simpleeqns), 1, simpleeqns, iMT, iUnreplaceable, iVars, iEqnslst, ishared, iRepl);
// perform replacements and try again
Expand Down Expand Up @@ -768,7 +768,7 @@ algorithm
case (true, _, _, _, _, _, _, _, _, _, _)
equation
// transform simpleeqns to array
simpleeqns = listArray(listReverse(iSimpleeqnslst));
simpleeqns = List.listArrayReverse(iSimpleeqnslst);
// collect and handle sets
(vars, eqnslst, shared, repl) = handleSets(arrayLength(simpleeqns), 1, simpleeqns, iMT, iUnreplaceable, iVars, iEqnslst, ishared, iRepl);
// perform replacements and try again
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/BasePVector.mo
Expand Up @@ -49,6 +49,7 @@ encapsulated partial package BasePVector
replaceable type T = Integer; // Should be Any.

protected
import List;
import MetaModelica.Dangerous;

uniontype Vector
Expand Down Expand Up @@ -155,7 +156,7 @@ algorithm
e :: rest := rest;
node_lst := VALUE(e) :: node_lst;
end for;
tail := arrayAppend(tail, listArray(listReverse(node_lst)));
tail := arrayAppend(tail, List.listArrayReverse(node_lst));
end if;

// Keep track of the size so we know where to push new nodes.
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/GraphML.mo
Expand Up @@ -593,7 +593,7 @@ algorithm
GRAPHINFO(graphs,graphCount,nodes,nodeCount,edges,edgeCount,attributes,graphNodeKey,graphEdgeKey) := iGraphInfo;
graphsArr := listArray(graphs);
nodesArr := listArray(nodes);
attributesArr := listArray(listReverse(attributes));
attributesArr := List.listArrayReverse(attributes);
oGraphInfo := GRAPHINFOARR(graphsArr,nodesArr,edges,attributesArr,graphNodeKey,graphEdgeKey);
end convertToGraphInfoArr;

Expand Down
23 changes: 22 additions & 1 deletion Compiler/Util/List.mo
Expand Up @@ -96,7 +96,8 @@ encapsulated package List
"

protected
import MetaModelica.Dangerous.{listReverseInPlace, arrayGetNoBoundsChecking};
import MetaModelica.Dangerous.{listReverseInPlace, arrayGetNoBoundsChecking, arrayUpdateNoBoundsChecking, arrayCreateNoInit};
import MetaModelica.Dangerous;

public function create<T>
"Creates a list from an element."
Expand Down Expand Up @@ -1493,6 +1494,26 @@ algorithm
end for;
end transposeList;

public function listArrayReverse<T>
input list<T> inLst;
output array<T> outArr;
protected
Integer len;
T defaultValue;
algorithm
if listEmpty(inLst) then
outArr := listArray(inLst);
return;
end if;
len := listLength(inLst);
defaultValue::_ := inLst;
outArr := arrayCreateNoInit(len,defaultValue);
for e in inLst loop
arrayUpdateNoBoundsChecking(outArr, len, e);
len := len-1;
end for;
end listArrayReverse;

public function setEqualOnTrue<T>
"Takes two lists and a comparison function over two elements of the lists.
It returns true if the two sets are equal, false otherwise."
Expand Down

0 comments on commit 0bcc79a

Please sign in to comment.