Skip to content

Commit

Permalink
- Add a HT
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12112 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 19, 2012
1 parent ccce539 commit 67c7e9d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Compiler/FrontEnd/SCodeInst.mo
Expand Up @@ -42,9 +42,11 @@ encapsulated package SCodeInst
public import Absyn;
public import DAE;
public import InstTypes;
public import HashTablePathToFunction;
public import SCode;
public import SCodeEnv;

protected import BaseHashTable;
protected import ClassInf;
protected import ComponentReference;
protected import Connect;
Expand Down Expand Up @@ -78,7 +80,7 @@ public type Element = InstTypes.Element;
public type Env = SCodeEnv.Env;
public type Equation = InstTypes.Equation;
public type Function = InstTypes.Function;
public type FunctionHashTable = Integer;
public type FunctionHashTable = HashTablePathToFunction.HashTable;
public type Modifier = InstTypes.Modifier;
public type ParamType = InstTypes.ParamType;
public type Prefixes = InstTypes.Prefixes;
Expand All @@ -94,9 +96,6 @@ protected uniontype InstPolicy
record INST_ONLY_CONST end INST_ONLY_CONST;
end InstPolicy;

protected constant FunctionHashTable dummyFunctions = -128912362;
protected constant FunctionHashTable emptyFunctions = -128912362;

public function instClass
"Flattens a class."
input Absyn.Path inClassPath;
Expand Down Expand Up @@ -128,7 +127,7 @@ algorithm
(item, path, env) =
SCodeLookup.lookupClassName(inClassPath, inEnv, Absyn.dummyInfo);
(cls, _, _, functions) = instClassItem(item, InstTypes.NOMOD(),
InstTypes.NO_PREFIXES(), env, InstTypes.emptyPrefix, INST_ALL(), emptyFunctions);
InstTypes.NO_PREFIXES(), env, InstTypes.emptyPrefix, INST_ALL(), HashTablePathToFunction.emptyHashTableSized(BaseHashTable.lowBucketSize));
(const_el,functions) = instGlobalConstants(inGlobalConstants, inClassPath, inEnv, functions);
cls = InstUtil.addElementsToClass(const_el, cls);

Expand Down
1 change: 1 addition & 0 deletions Compiler/Makefile.common
Expand Up @@ -171,6 +171,7 @@ HashTable3.mo \
HashTable4.mo \
HashTable5.mo \
HashTableCG.mo \
HashTablePathToFunction.mo \
HashTableStringToPath.mo \
HashTableExpToIndex.mo \
IOStream.mo \
Expand Down
107 changes: 107 additions & 0 deletions Compiler/Util/HashTablePathToFunction.mo
@@ -0,0 +1,107 @@
encapsulated package HashTablePathToFunction "
This file is an extension to OpenModelica.

Copyright (c) 2007 MathCore Engineering AB

All rights reserved.

file: HashTablePathToFunction.mo
package: HashTablePathToFunction
description: Absyn.Path to InstTypes.Function

RCS: $Id$

"

/* Below is the instance specific code. For each hashtable the user must define:
Key - The key used to uniquely define elements in a hashtable
Value - The data to associate with each key
hashFunc - A function that maps a key to a positive integer.
keyEqual - A comparison function between two keys, returns true if equal.
*/

/* HashTable instance specific code */

public import BaseHashTable;
public import Absyn;
public import InstTypes;

protected import System;
protected import Util;

public type Key = Absyn.Path;
public type Value = InstTypes.Function;

public type HashTableCrefFunctionsType = tuple<FuncHashCref,FuncCrefEqual,FuncCrefStr,FuncExpStr>;
public type HashTable = tuple<
array<list<tuple<Key,Integer>>>,
tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
Integer,
Integer,
HashTableCrefFunctionsType
>;

partial function FuncHashCref
input Key cr;
input Integer mod;
output Integer res;
end FuncHashCref;

partial function FuncCrefEqual
input Key cr1;
input Key cr2;
output Boolean res;
end FuncCrefEqual;

partial function FuncCrefStr
input Key cr;
output String res;
end FuncCrefStr;

partial function FuncExpStr
input Value exp;
output String res;
end FuncExpStr;

protected function hashFunc
"Calculates a hash value for Key"
input Key path;
input Integer mod;
output Integer res;
protected
String str;
algorithm
str := Absyn.pathString(path);
res := System.stringHashDjb2Mod(str,mod);
end hashFunc;

protected function valString
input Value v;
output String str;
algorithm
str := "/* a function of some kind */";
end valString;

public function emptyHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,Absyn.pathEqual,Absyn.pathString,valString));
end emptyHashTableSized;

end HashTablePathToFunction;
8 changes: 8 additions & 0 deletions Compiler/Util/Util.mo
Expand Up @@ -3346,4 +3346,12 @@ algorithm
end matchcontinue;
end nextPrime_isPrime2;

public function anyToEmptyString "Useful if you do not want to write an unparser"
input A a;
output String empty;
replaceable type A subtypeof Any;
algorithm
empty := "";
end anyToEmptyString;

end Util;

0 comments on commit 67c7e9d

Please sign in to comment.