OMCompiler/Compiler/Util/HashTableSM1.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 HashTableSM1 " | ||
| 37 | HashTable instance specific code " | ||
| 38 | |||
| 39 | public import BaseHashTable; | ||
| 40 | public import DAE; | ||
| 41 | protected import ComponentReference; | ||
| 42 | protected import ComponentReferenceBasics; | ||
| 43 | protected import HashSet; | ||
| 44 | protected import BaseHashSet; | ||
| 45 | protected import List; | ||
| 46 | protected import InstStateMachineUtil; | ||
| 47 | |||
| 48 | public type Key = DAE.ComponentRef; | ||
| 49 | public type Value = InstStateMachineUtil.SMNode; | ||
| 50 | |||
| 51 | public type HashTableCrefFunctionsType = tuple<FuncHashCref, FuncCrefEqual, FuncCrefStr, FuncExpStr>; | ||
| 52 | public type HashTable = tuple<array<list<tuple<Key, Integer>>>, | ||
| 53 | tuple<Integer, Integer, array<Option<tuple<Key, Value>>>>, | ||
| 54 | Integer, | ||
| 55 | HashTableCrefFunctionsType>; | ||
| 56 | |||
| 57 | partial function FuncHashCref | ||
| 58 | input Key cr; | ||
| 59 | output Integer res; | ||
| 60 | end FuncHashCref; | ||
| 61 | |||
| 62 | partial function FuncCrefEqual | ||
| 63 | input Key cr1; | ||
| 64 | input Key cr2; | ||
| 65 | output Boolean res; | ||
| 66 | end FuncCrefEqual; | ||
| 67 | |||
| 68 | partial function FuncCrefStr | ||
| 69 | input Key cr; | ||
| 70 | output String res; | ||
| 71 | end FuncCrefStr; | ||
| 72 | |||
| 73 | partial function FuncExpStr | ||
| 74 | input Value exp; | ||
| 75 | output String res; | ||
| 76 | end FuncExpStr; | ||
| 77 | |||
| 78 | public function emptyHashTable | ||
| 79 | " | ||
| 80 | Returns an empty HashTable. | ||
| 81 | Using the default bucketsize.. | ||
| 82 | " | ||
| 83 | output HashTable hashTable; | ||
| 84 | algorithm | ||
| 85 | 7 | hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize); | |
| 86 | end emptyHashTable; | ||
| 87 | |||
| 88 | public function emptyHashTableSized | ||
| 89 | "Returns an empty HashTable. | ||
| 90 | Using the bucketsize size" | ||
| 91 | input Integer size; | ||
| 92 | output HashTable hashTable; | ||
| 93 | algorithm | ||
| 94 | 158439 | hashTable := BaseHashTable.emptyHashTableWork(size,(ComponentReferenceBasics.hashComponentRef,ComponentReferenceBasics.crefEqual,ComponentReferenceBasics.printComponentRefStr,modeStr)); | |
| 95 | end emptyHashTableSized; | ||
| 96 | |||
| 97 | public function modeStr | ||
| 98 | input InstStateMachineUtil.SMNode mode; | ||
| 99 | output String s; | ||
| 100 | protected | ||
| 101 | DAE.ComponentRef componentRef; | ||
| 102 | Boolean isInitial; | ||
| 103 | HashSet.HashSet edges; | ||
| 104 | list<DAE.ComponentRef> crefs; | ||
| 105 | list<String> paths; | ||
| 106 | algorithm | ||
| 107 | ✗ | InstStateMachineUtil.SMNODE(componentRef=componentRef, isInitial=isInitial, edges=edges) := mode; | |
| 108 | ✗ | crefs := BaseHashSet.hashSetList(edges); | |
| 109 | ✗ | paths := List.map(crefs, ComponentReferenceBasics.printComponentRefStr); | |
| 110 | ✗ | s := "SMNODE(" + ComponentReferenceBasics.printComponentRefStr(componentRef) + ", "+boolString(isInitial) + "," | |
| 111 | + "EDGES(" + stringDelimitList(paths, ", ") +"))\n"; | ||
| 112 | end modeStr; | ||
| 113 | |||
| 114 | annotation(__OpenModelica_Interface="frontend"); | ||
| 115 | end HashTableSM1; | ||
| 116 |