OMCompiler/Compiler/FrontEnd/FHashTableUnitToString.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 FHashTableUnitToString " | ||
| 37 | This file is an extension to OpenModelica. | ||
| 38 | |||
| 39 | Copyright (c) 2013 TU Dresden | ||
| 40 | |||
| 41 | All rights reserved. | ||
| 42 | |||
| 43 | file: FHashTableUnitToString.mo | ||
| 44 | package: FHashTableUnitToString | ||
| 45 | description: Unit.Unit to String | ||
| 46 | |||
| 47 | |||
| 48 | " | ||
| 49 | |||
| 50 | /* Below is the instance specific code. For each hashtable the user must define: | ||
| 51 | |||
| 52 | Key - The key used to uniquely define elements in a hashtable | ||
| 53 | Value - The data to associate with each key | ||
| 54 | hashFunc - A function that maps a key to a positive integer. | ||
| 55 | keyEqual - A comparison function between two keys, returns true if equal. | ||
| 56 | */ | ||
| 57 | |||
| 58 | /* HashTable instance specific code */ | ||
| 59 | |||
| 60 | public import BaseHashTable; | ||
| 61 | public import FUnit; | ||
| 62 | |||
| 63 | public type Key = FUnit.Unit; | ||
| 64 | public type Value = String; | ||
| 65 | |||
| 66 | public type HashTableCrefFunctionsType = tuple<FuncHashKey,FuncKeyEqual,FuncKeyStr,FuncValueStr>; | ||
| 67 | public type HashTable = tuple< | ||
| 68 | array<list<tuple<Key,Integer>>>, | ||
| 69 | tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>, | ||
| 70 | Integer, | ||
| 71 | HashTableCrefFunctionsType | ||
| 72 | >; | ||
| 73 | |||
| 74 | partial function FuncHashKey | ||
| 75 | input Key cr; | ||
| 76 | output Integer res; | ||
| 77 | end FuncHashKey; | ||
| 78 | |||
| 79 | partial function FuncKeyEqual | ||
| 80 | input Key cr1; | ||
| 81 | input Key cr2; | ||
| 82 | output Boolean res; | ||
| 83 | end FuncKeyEqual; | ||
| 84 | |||
| 85 | partial function FuncKeyStr | ||
| 86 | input Key cr; | ||
| 87 | output String res; | ||
| 88 | end FuncKeyStr; | ||
| 89 | |||
| 90 | partial function FuncValueStr | ||
| 91 | input Value exp; | ||
| 92 | output String res; | ||
| 93 | end FuncValueStr; | ||
| 94 | |||
| 95 | public function emptyHashTable | ||
| 96 | " | ||
| 97 | Returns an empty HashTable. | ||
| 98 | Using the default bucketsize.. | ||
| 99 | " | ||
| 100 | output HashTable hashTable; | ||
| 101 | algorithm | ||
| 102 | ✗ | hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize); | |
| 103 | end emptyHashTable; | ||
| 104 | |||
| 105 | protected function id | ||
| 106 | input String inStr; | ||
| 107 | output String outStr; | ||
| 108 | algorithm | ||
| 109 | outStr := inStr; | ||
| 110 | end id; | ||
| 111 | |||
| 112 | public function emptyHashTableSized | ||
| 113 | " | ||
| 114 | Returns an empty HashTable. | ||
| 115 | Using the bucketsize size. | ||
| 116 | " | ||
| 117 | input Integer size; | ||
| 118 | output HashTable hashTable; | ||
| 119 | algorithm | ||
| 120 | 10 | hashTable := BaseHashTable.emptyHashTableWork(size,(FUnit.hashUnit,FUnit.unitEqual,FUnit.unit2string,id)); | |
| 121 | end emptyHashTableSized; | ||
| 122 | |||
| 123 | annotation(__OpenModelica_Interface="frontend"); | ||
| 124 | end FHashTableUnitToString; | ||
| 125 |