Skip to content

Commit

Permalink
replaced O(n) listLength(L)==0 by O(1) List.isEmpty(L)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18258 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Nov 23, 2013
1 parent 7d2f4af commit 421c1e8
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 61 deletions.
16 changes: 8 additions & 8 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -1784,7 +1784,7 @@ algorithm
equation
(DAE.PARTIAL_EQUATION(cond), source) = Inline.simplifyAndInlineEquationExp(DAE.PARTIAL_EQUATION(cond), (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(res, reinit) = lowerWhenEqn2(listReverse(eqnl), cond, functionTree, inEquationLst, {});
whenClauseList = makeWhenClauses(listLength(reinit) > 0, cond, reinit, inWhenClauseLst);
whenClauseList = makeWhenClauses(List.isNotEmpty(reinit), cond, reinit, inWhenClauseLst);
then
(res, whenClauseList);

Expand All @@ -1793,7 +1793,7 @@ algorithm
(elseEqnLst, whenClauseList) = lowerWhenEqn(elsePart, functionTree, {}, inWhenClauseLst);
(DAE.PARTIAL_EQUATION(cond), source) = Inline.simplifyAndInlineEquationExp(DAE.PARTIAL_EQUATION(cond), (SOME(functionTree), {DAE.NORM_INLINE()}), source);
(trueEqnLst, reinit) = lowerWhenEqn2(listReverse(eqnl), cond, functionTree, {}, {});
whenClauseList = makeWhenClauses(listLength(reinit) > 0, cond, reinit, whenClauseList);
whenClauseList = makeWhenClauses(List.isNotEmpty(reinit), cond, reinit, whenClauseList);
res = mergeClauses(trueEqnLst, elseEqnLst, inEquationLst);
then
(res, whenClauseList);
Expand Down Expand Up @@ -3752,7 +3752,7 @@ algorithm
e_1 = DAE.LUNARY(op, e1);
{zc} = makeZeroCrossings({e_1}, {eq_count}, {wc_count});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
Debug.fcall(Flags.RELIDX, BackendDump.debugExpStr, (e_1, "\n"));
then
((e, false, ((zeroCrossings, relations, samples, numRelations, numMathFunctions), (eq_count, wc_count, vars, knvars))));
Expand All @@ -3766,7 +3766,7 @@ algorithm
e_1 = DAE.LBINARY(e_1, op, e_2);
{zc} = makeZeroCrossings({e_1}, {eq_count}, {wc_count});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1, false, ((zeroCrossings, relations, samples, numRelations1, numMathFunctions), (eq_count, wc_count, vars, knvars))));
Expand Down Expand Up @@ -3920,7 +3920,7 @@ algorithm
e_1 = DAE.LUNARY(op, e1);
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
Debug.fcall(Flags.RELIDX, BackendDump.debugExpStr, (e_1, "\n"));
then
((e, false, (iterator, le, range, (zeroCrossings, relations, samples, numRelations, numMathFunctions), (alg_indx, vars, knvars))));
Expand All @@ -3934,7 +3934,7 @@ algorithm
e_1 = DAE.LBINARY(e_1, op, e_2);
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1, false, (iterator, le, range, (zeroCrossings, relations, samples, numRelations1, numMathFunctions), (alg_indx, vars, knvars))));
Expand Down Expand Up @@ -4104,7 +4104,7 @@ algorithm
e_1 = DAE.LUNARY(op, e1);
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
Debug.fcall(Flags.RELIDX, BackendDump.debugExpStr, (e_1, "\n"));
then
((e_1, false, (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations, numMathFunctions), (alg_indx, vars, knvars))));
Expand Down Expand Up @@ -4138,7 +4138,7 @@ algorithm
e_1 = DAE.LBINARY(e_1, op, e_2);
{zc} = makeZeroCrossings({e_1}, {alg_indx}, {});
zc_lst = List.select1(zeroCrossings, sameZeroCrossing, zc);
zeroCrossings = Util.if_(listLength(zc_lst)==0, listAppend(zeroCrossings, {zc}), zeroCrossings);
zeroCrossings = Util.if_(List.isEmpty(zc_lst), listAppend(zeroCrossings, {zc}), zeroCrossings);
print(Debug.fcallret1(Flags.RELIDX, BackendDump.zeroCrossingListString, zeroCrossings, ""));
then
((e_1, false, (iterator, inExpLst, range, (zeroCrossings, relations, samples, numRelations1, numMathFunctions), (alg_indx, vars, knvars))));
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -1163,7 +1163,7 @@ algorithm
(syst,m,mT) = BackendDAEUtil.getIncidenceMatrixfromOption(syst,BackendDAE.NORMAL(),SOME(funcs));
// check equations
(m_1,(mT_1,_,eqns1,changed)) = traverseIncidenceMatrix(m,removeEqualFunctionCallFinder,(mT,vars,eqns,{}));
b = intGt(listLength(changed),0);
b = List.isNotEmpty(changed);
// update arrayeqns and algorithms, collect info for wrappers
syst = BackendDAE.EQSYSTEM(vars,eqns,SOME(m_1),SOME(mT_1),BackendDAE.NO_MATCHING(),stateSets);
syst = BackendDAEUtil.updateIncidenceMatrix(syst,BackendDAE.NORMAL(),NONE(),changed);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -274,7 +274,7 @@ algorithm
case ((exp,(vars,lstExpCrefs)))
equation
((_,(_,crefs))) = Expression.traverseExp(exp,traversecheckBackendDAEExp,(vars,{}));
lstExpCrefs1 = Util.if_(listLength(crefs)>0,(exp,crefs)::lstExpCrefs,lstExpCrefs);
lstExpCrefs1 = Util.if_(List.isNotEmpty(crefs),(exp,crefs)::lstExpCrefs,lstExpCrefs);
then
((exp,(vars,lstExpCrefs1)));
case _ then inTpl;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -178,7 +178,7 @@ algorithm
//get all predecessors (childs)
(predecessors, _) = getSuccessorsByTask(head, iTaskGraphT, iAllTasks);
(successors, successorIdc) = getSuccessorsByTask(head, iTaskGraph, iAllTasks);
true = intGt(listLength(predecessors), 0); //in this case the node has predecessors
true = List.isNotEmpty(predecessors); //in this case the node has predecessors
//print("Handle task " +& intString(index) +& " with " +& intString(listLength(predecessors)) +& " child nodes and " +& intString(listLength(successorIdc)) +& " parent nodes.\n");

//get last child finished time
Expand Down Expand Up @@ -1327,7 +1327,7 @@ algorithm
//get all predecessors (childs)
(predecessors, _) = getSuccessorsByTask(head, iTaskGraphT, iAllTasks);
(successors, successorIdc) = getSuccessorsByTask(head, iTaskGraph, iAllTasks);
true = intGt(listLength(predecessors), 0); //in this case the node has predecessors
true = List.isNotEmpty(predecessors); //in this case the node has predecessors
//print("Handle task " +& intString(index) +& " with " +& intString(listLength(predecessors)) +& " child nodes and " +& intString(listLength(successorIdc)) +& " parent nodes.\n");

//find thread for scheduling
Expand Down
18 changes: 9 additions & 9 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -479,7 +479,7 @@ algorithm
(adjLst,rootNodes);
case(_,_,_,_,_)
equation
true = listLength(parentLst) == 0;
true = List.isEmpty(parentLst);
rootNodes = childNode::rootNodesIn;
then
(adjLstIn,rootNodes);
Expand Down Expand Up @@ -1689,7 +1689,7 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars=orderedVars) = systIn;
varLst = BackendVariable.varList(orderedVars);
stateVars = getStates(varLst,{},1);
true = listLength(stateVars) >= 1;
true = List.isNotEmpty(stateVars);
stateVars = List.map1(stateVars,intAdd,varOffset);
stateNodes = matchWithAssignments(stateVars,varSccMapping);
stateNodes = List.map3(stateNodes,getCompInComps,1,inComps,arrayCreate(arrayLength(inComps),0));
Expand All @@ -1702,7 +1702,7 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars=orderedVars) = systIn;
varLst = BackendVariable.varList(orderedVars);
stateVars = getStates(varLst,{},1);
true = listLength(stateVars) == 0;
true = List.isEmpty(stateVars);
varOffsetNew = listLength(varLst)+varOffset;
then
((stateNodesIn,varOffsetNew));
Expand Down Expand Up @@ -3127,7 +3127,7 @@ algorithm
oneChildren := List.removeOnTrue(1,compareListLengthOnTrue,oneChildren); // remove paths of length 1
//oneChildren := List.fold1(List.intRange(listLength(oneChildren)),checkParentNode,graphIn,oneChildren); // deletes the lists with just one entry that have more than one parent
(graphOut,graphDataOut) := contractNodesInGraph(oneChildren,graphIn,graphDataIn);
oChanged := intGt(listLength(oneChildren), 0);
oChanged := List.isNotEmpty(oneChildren);
end mergeSimpleNodes;


Expand All @@ -3145,7 +3145,7 @@ algorithm
iGraphT := transposeTaskGraph(iGraph);
mergedNodes := mergeParentNodes0(iGraph, iGraphT, iGraphData, 1, {});
(oGraph,oGraphData) := contractNodesInGraph(mergedNodes, iGraph, iGraphData);
oChanged := intGt(listLength(mergedNodes),0);
oChanged := List.isNotEmpty(mergedNodes);
end mergeParentNodes;

protected function mergeParentNodes0
Expand Down Expand Up @@ -4744,7 +4744,7 @@ algorithm
case(_,_,TASKGRAPHMETA(inComps=inComps,exeCosts=exeCosts),_,_)
equation //critical path of node is currently unknown -> calculate it
childNodes = arrayGet(iGraph, iNode);
true = intGt(listLength(childNodes),0); //has children
true = List.isNotEmpty(childNodes); //has children
criticalPaths = List.map4(childNodes, getCriticalPath1, iGraph, iGraphData, iHandleCommCosts, iNodeCriticalPaths);
criticalPathIdx = getCriticalPath2(criticalPaths, 1, -1.0, -1);
((cpCalcTime, criticalPathChild)) = listGet(criticalPaths, criticalPathIdx);
Expand All @@ -4760,7 +4760,7 @@ algorithm
case(_,_,TASKGRAPHMETA(inComps=inComps,exeCosts=exeCosts),_,_)
equation //critical path of node is currently unknown -> calculate it
childNodes = arrayGet(iGraph, iNode);
false = intGt(listLength(childNodes),0); //has no children
false = List.isNotEmpty(childNodes); //has no children
criticalPath = iNode :: {};
nodeComps = arrayGet(inComps, iNode);
calcTime = addUpExeCostsForNode(nodeComps, exeCosts, 0.0); //sum up calc times of all components
Expand Down Expand Up @@ -5530,7 +5530,7 @@ algorithm
equation
commCosts = arrayGet(iCommCosts, iParentComp);
filteredCommCosts = List.filter1OnTrue(commCosts, getCommCostBetweenNodes1, iChildComps);
true = intGt(listLength(filteredCommCosts), 0);
true = List.isNotEmpty(filteredCommCosts);
highestCommCost = getHighestCommCost(filteredCommCosts, (-1,-1,-1));
then SOME(highestCommCost);
else then NONE();
Expand Down Expand Up @@ -5724,7 +5724,7 @@ end sumUpExecCosts1;
// //print("for "+&intString(childNodeIn)+&" the parents "+&stringDelimitList(List.map(parents,intString),",")+&"\n");
// //print("collected Nodes "+&stringDelimitList(List.map(collectedNodes,intString),",")+&"\n");
// (_,parents,_) = List.intersection1OnTrue(parents,childNodeIn::collectedNodes,intEq);
// true = listLength(parents) == 0;
// true = List.isEmpty(parents);
// then
// childNodeIn;
// else
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Initialization.mo
Expand Up @@ -190,7 +190,7 @@ algorithm
Debug.fcall2(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpBackendDAE, initdae, "solved initial system");

// warn about selected default initial conditions
b = intGt(listLength(dumpVars), 0);
b = List.isNotEmpty(dumpVars);
Debug.bcall(b and (not Flags.isSet(Flags.INITIALIZATION)), Error.addCompilerWarning, "The initial conditions are not fully specified. Use +d=initialization for more information.");
Debug.bcall(b and Flags.isSet(Flags.INITIALIZATION), Error.addCompilerWarning, "Assuming fixed start value for the following " +& intString(listLength(dumpVars)) +& " variables:\n" +& warnAboutVars2(dumpVars));

Expand Down
14 changes: 7 additions & 7 deletions Compiler/BackEnd/OnRelaxation.mo
Expand Up @@ -654,7 +654,7 @@ algorithm
// remove assigned equation of this row
next = List.removeOnTrue(ass1[r], intEq, next);
// print("Eqns use Var " +& intString(r) +& " : " +& stringDelimitList(List.map(next,intString),", ") +& "\n");
true = intGt(listLength(next),0);
true = List.isNotEmpty(next);
then
generateCliquesResidual1(rest,ass1,ass2,m,mt,mark,rowmarks,colummarks,ifoundFlow,vars);
case (r::rest,_,_,_,_,_,_,_,_,_)
Expand All @@ -666,7 +666,7 @@ algorithm
next = List.select2(next, unmarked, colummarks, mark);
// remove assigned equation of this row
next = List.removeOnTrue(ass1[r], intEq, next);
false = intGt(listLength(next),0);
false = List.isNotEmpty(next);
_ = arrayUpdate(rowmarks,r,mark);
e = ass1[r];
// print("Go From " +& intString(r) +& " to " +& intString(e) +& "\n");
Expand Down Expand Up @@ -883,7 +883,7 @@ algorithm
// remove assigned
next = List.fold1(ass2[e],List.removeOnTrue, intEq, next);
// print("Used Vars of " +& intString(e) +& " : " +& stringDelimitList(List.map(next,intString),", ") +& "\n");
true = intGt(listLength(next),0);
true = List.isNotEmpty(next);
then
prepairOrphansOrder1(rest,ass1,ass2,m,mt,mark,rowmarks,colummarks,preorphan,orphans,prer,ifoundFlow,vars);
case (e::rest,_,_,_,_,_,_,_,_,_,_,_,_)
Expand All @@ -895,7 +895,7 @@ algorithm
next = List.select2(next, unmarked, rowmarks, mark);
// remove assigned
next = List.fold1(ass2[e],List.removeOnTrue, intEq, next);
false = intGt(listLength(next),0);
false = List.isNotEmpty(next);
_ = arrayUpdate(colummarks,e,mark);
r = ass2[e];
// print("Go From " +& intString(e) +& " to " +& stringDelimitList(List.map(r,intString),", ") +& "\n");
Expand Down Expand Up @@ -2905,7 +2905,7 @@ algorithm
// print("Process Colum " +& intString(c) +& " Rows " +& stringDelimitList(List.map(r,intString),", ") +& " " +& boolString(b) +&"\n");
(colums1,b2) = getIndexQueque1(r,c,mT,mark,rowmarks,{},false);
// BackendDump.debuglst((colums1,intString,", ","\n"));
b1 = intGt(listLength(colums),0);
b1 = List.isNotEmpty(colums);
// cons next rows in front to jump over marked nodes
queue = Debug.bcallret3(b1, List.unionOnTrue, colums1, nextqueue, intEq, nextqueue);
// print("queue: "); BackendDump.debuglst((queue,intString,", ","\n"));
Expand Down Expand Up @@ -3002,15 +3002,15 @@ protected function isResOrphan
input array<list<Integer>> ass;
output Boolean b;
algorithm
b := intLt(listLength(ass[indx]),1);
b := List.isEmpty(ass[indx]);
end isResOrphan;

protected function isNoResOrphan
input Integer indx;
input array<list<Integer>> ass;
output Boolean b;
algorithm
b := intGt(listLength(ass[indx]),0);
b := List.isNotEmpty(ass[indx]);
end isNoResOrphan;

protected function doAssign "author: Frenkel TUD 2012-05"
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/OpenTURNS.mo
Expand Up @@ -375,7 +375,7 @@ algorithm

varLst := BackendDAEUtil.getAllVarLst(dae2);
varLst := List.select(varLst,BackendVariable.varHasDistributionAttribute);
Util.addInternalError(listLength(varLst) == 0, "OpenTURNS.generateDistributions: No variable in the DAE has the distribution attribute! Check your model ...");
Util.addInternalError(List.isEmpty(varLst), "OpenTURNS.generateDistributions: No variable in the DAE has the distribution attribute! Check your model ...");
dists := List.map(varLst,BackendVariable.varDistribution);
(sLst,distributionVarLst) := List.map1_2(List.threadTuple(dists,List.map(varLst,BackendVariable.varCref)),generateDistributionVariable,dae2);

Expand Down

0 comments on commit 421c1e8

Please sign in to comment.