Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- start to implement new index calculation
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12789 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Jens Frenkel
committed
Sep 5, 2012
1 parent
bc5af82
commit 35b2426
Showing
3 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
encapsulated package HashTableCrSimVars " | ||
This file is an extension to OpenModelica. | ||
|
||
Copyright (c) 2007 MathCore Engineering AB | ||
|
||
All rights reserved. | ||
|
||
file: HashTableCrSimVars.mo | ||
package: HashTableCrSimVars | ||
description: DAE.CR to DAE.Exp | ||
|
||
RCS: $Id: HashTableCrSimVars.mo 8796 2011-05-03 19:43:08Z adrpo $ | ||
|
||
" | ||
|
||
/* 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 DAE; | ||
public import SimCode; | ||
protected import ComponentReference; | ||
protected import System; | ||
|
||
public type Key = DAE.ComponentRef; | ||
public type Value = list<Simcode.SimVar>; | ||
|
||
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; | ||
|
||
public function hashFunc | ||
"Calculates a hash value for Key" | ||
input Key cr; | ||
input Integer mod; | ||
output Integer res; | ||
protected | ||
String crstr; | ||
algorithm | ||
crstr := ComponentReference.printComponentRefStr(cr); | ||
res := System.stringHashDjb2Mod(crstr,mod); | ||
end hashFunc; | ||
|
||
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,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,printVarListStr)); | ||
end emptyHashTableSized; | ||
|
||
public function printVarListStr | ||
input list<SimCode.SimVar> ilst; | ||
output String res; | ||
algorithm | ||
res := "{" +& stringDelimitList(List.map(ilst, simVarString), ",") +& "}"; | ||
end printVarListStr; | ||
|
||
protected function simVarString | ||
input SimCode.SimVar var; | ||
output String res; | ||
protected | ||
DAE.ComponentRef cr; | ||
algorithm | ||
SimCode.SIMVAR(name=cr) := var; | ||
res := ComponentReference.printComponentRefStr(cr); | ||
end simVarString; | ||
|
||
|
||
|
||
end HashTableCrSimVars; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters