Skip to content

Commit

Permalink
Adding function DAEUtil.avlKeyCompare instead of hard-coding this
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19558 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 12, 2014
1 parent ae0d26c commit 402280f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -5045,6 +5045,14 @@ algorithm
str := DAEDump.dumpFunctionStr(Util.getOption(v));
end valueStr;

protected function avlKeyCompare
input DAE.AvlKey key1;
input DAE.AvlKey key2;
output Integer c;
algorithm
c := stringCompare(Absyn.pathStringNoQual(key1),Absyn.pathStringNoQual(key2));
end avlKeyCompare;

public function avlTreeNew "Return an empty tree"
output DAE.AvlTree tree;
annotation(__OpenModelica_EarlyInline = true);
Expand Down Expand Up @@ -5132,7 +5140,7 @@ algorithm
/* Insert to right */
case (DAE.AVLTREENODE(value = SOME(DAE.AVLTREEVALUE(rkey,rval)),height=h,left = left,right = (right)),key,value)
equation
true = stringCompare(Absyn.pathString(key),Absyn.pathString(rkey)) > 0;
true = avlKeyCompare(key,rkey) > 0;
t = createEmptyAvlIfNone(right);
t_1 = avlTreeAdd(t, key, value);
bt = balance(DAE.AVLTREENODE(SOME(DAE.AVLTREEVALUE(rkey,rval)),h,left,SOME(t_1)));
Expand Down Expand Up @@ -5391,22 +5399,22 @@ algorithm
// hash func Search to the right
case (DAE.AVLTREENODE(value = SOME(DAE.AVLTREEVALUE(rkey,rval))),key)
equation
0 = stringCompare(Absyn.pathStringNoQual(key),Absyn.pathStringNoQual(rkey));
0 = avlKeyCompare(key,rkey);
then
rval;

// Search to the right
case (DAE.AVLTREENODE(value = SOME(DAE.AVLTREEVALUE(rkey,rval)),right = SOME(right)),key)
equation
1 = stringCompare(Absyn.pathStringNoQual(key),Absyn.pathStringNoQual(rkey));
1 = avlKeyCompare(key,rkey);
res = avlTreeGet(right, key);
then
res;

// Search to the left
case (DAE.AVLTREENODE(value = SOME(DAE.AVLTREEVALUE(rkey,rval)),left = SOME(left)),key)
equation
-1 = stringCompare(Absyn.pathStringNoQual(key),Absyn.pathStringNoQual(rkey));
-1 = avlKeyCompare(key,rkey);
res = avlTreeGet(left, key);
then
res;
Expand Down

0 comments on commit 402280f

Please sign in to comment.