OMCompiler/Compiler/Util/HashTableCrIntToExp.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package HashTableCrIntToExp | ||
| 37 | |||
| 38 | /* Below is the instance specific code. For each hashtable the user must define: | ||
| 39 | |||
| 40 | Key - The key used to uniquely define elements in a hashtable | ||
| 41 | Value - The data to associate with each key | ||
| 42 | hashFunc - A function that maps a key to a positive integer. | ||
| 43 | keyEqual - A comparison function between two keys, returns true if equal. | ||
| 44 | */ | ||
| 45 | |||
| 46 | /* HashTable instance specific code */ | ||
| 47 | |||
| 48 | public import BaseHashTable; | ||
| 49 | public import DAE; | ||
| 50 | protected import ComponentReference; | ||
| 51 | protected import ComponentReferenceBasics; | ||
| 52 | protected import ExpressionBasics; | ||
| 53 | protected import Util; | ||
| 54 | |||
| 55 | public type Key = tuple<DAE.ComponentRef,Integer>; | ||
| 56 | public type Value = DAE.Exp; | ||
| 57 | |||
| 58 | public type HashTableCrefFunctionsType = tuple<FuncHashCref,FuncCrefEqual,FuncCrefStr,FuncExpStr>; | ||
| 59 | public type HashTable = tuple< | ||
| 60 | array<list<tuple<Key,Integer>>>, | ||
| 61 | tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>, | ||
| 62 | Integer, | ||
| 63 | HashTableCrefFunctionsType | ||
| 64 | >; | ||
| 65 | |||
| 66 | partial function FuncHashCref | ||
| 67 | input Key cr; | ||
| 68 | output Integer res; | ||
| 69 | end FuncHashCref; | ||
| 70 | |||
| 71 | partial function FuncCrefEqual | ||
| 72 | input Key cr1; | ||
| 73 | input Key cr2; | ||
| 74 | output Boolean res; | ||
| 75 | end FuncCrefEqual; | ||
| 76 | |||
| 77 | partial function FuncCrefStr | ||
| 78 | input Key cr; | ||
| 79 | output String res; | ||
| 80 | end FuncCrefStr; | ||
| 81 | |||
| 82 | partial function FuncExpStr | ||
| 83 | input Value exp; | ||
| 84 | output String res; | ||
| 85 | end FuncExpStr; | ||
| 86 | |||
| 87 | protected function hashFunc | ||
| 88 | "Calculates a hash value for Key" | ||
| 89 | input Key tpl; | ||
| 90 | output Integer res; | ||
| 91 | algorithm | ||
| 92 | 52083 | res := ComponentReferenceBasics.hashComponentRef(Util.tuple21(tpl)) + Util.tuple22(tpl); | |
| 93 | end hashFunc; | ||
| 94 | |||
| 95 | protected function keyEqual | ||
| 96 | input Key tpl1; | ||
| 97 | input Key tpl2; | ||
| 98 | output Boolean res; | ||
| 99 | algorithm | ||
| 100 | res := matchcontinue (tpl1,tpl2) | ||
| 101 | local | ||
| 102 | DAE.ComponentRef cr1,cr2; | ||
| 103 | Integer i1,i2; | ||
| 104 | case ((cr1,i1),(cr2,i2)) | ||
| 105 | algorithm | ||
| 106 |
2/2✓ Branch 0 taken 1110 times.
✓ Branch 1 taken 23888 times.
|
24998 | true := intEq(i1,i2) "int compare is less expensive"; |
| 107 | 23888 | then ComponentReferenceBasics.crefEqual(cr1,cr2); | |
| 108 | else false; | ||
| 109 | end matchcontinue; | ||
| 110 | end keyEqual; | ||
| 111 | |||
| 112 | protected function printKey | ||
| 113 | input Key tpl; | ||
| 114 | output String res; | ||
| 115 | algorithm | ||
| 116 | ✗ | res := ComponentReferenceBasics.printComponentRefStr(Util.tuple21(tpl)) + "," + intString(Util.tuple22(tpl)); | |
| 117 | end printKey; | ||
| 118 | |||
| 119 | public function emptyHashTable | ||
| 120 | " | ||
| 121 | Returns an empty HashTable. | ||
| 122 | Using the default bucketsize.. | ||
| 123 | " | ||
| 124 | output HashTable hashTable; | ||
| 125 | algorithm | ||
| 126 | 12297 | hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize); | |
| 127 | end emptyHashTable; | ||
| 128 | |||
| 129 | public function emptyHashTableSized | ||
| 130 | " | ||
| 131 | Returns an empty HashTable. | ||
| 132 | Using the bucketsize size. | ||
| 133 | " | ||
| 134 | input Integer size; | ||
| 135 | output HashTable hashTable; | ||
| 136 | algorithm | ||
| 137 | 12297 | hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,keyEqual,printKey,ExpressionBasics.printExpStr)); | |
| 138 | end emptyHashTableSized; | ||
| 139 | |||
| 140 | annotation(__OpenModelica_Interface="frontend"); | ||
| 141 | end HashTableCrIntToExp; | ||
| 142 |