|
| 1 | +/* |
| 2 | + * This file is part of OpenModelica. |
| 3 | + * |
| 4 | + * Copyright (c) 1998-2014, 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 GPL VERSION 3 LICENSE OR |
| 11 | + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. |
| 12 | + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES |
| 13 | + * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, |
| 14 | + * ACCORDING TO RECIPIENTS CHOICE. |
| 15 | + * |
| 16 | + * The OpenModelica software and the Open Source Modelica |
| 17 | + * Consortium (OSMC) Public License (OSMC-PL) are obtained |
| 18 | + * from OSMC, either from the above address, |
| 19 | + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or |
| 20 | + * http://www.openmodelica.org, and in the OpenModelica distribution. |
| 21 | + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. |
| 22 | + * |
| 23 | + * This program is distributed WITHOUT ANY WARRANTY; without |
| 24 | + * even the implied warranty of MERCHANTABILITY or FITNESS |
| 25 | + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH |
| 26 | + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. |
| 27 | + * |
| 28 | + * See the full OSMC Public License conditions for more details. |
| 29 | + * |
| 30 | + */ |
| 31 | + |
| 32 | +encapsulated package NFHashTable |
| 33 | + |
| 34 | +/* Below is the instance specific code. For each hashtable the user must define: |
| 35 | +
|
| 36 | +Key - The key used to uniquely define elements in a hashtable |
| 37 | +Value - The data to associate with each key |
| 38 | +hashFunc - A function that maps a key to a positive integer. |
| 39 | +keyEqual - A comparison function between two keys, returns true if equal. |
| 40 | +*/ |
| 41 | + |
| 42 | +/* NFHashTable instance specific code */ |
| 43 | + |
| 44 | +public import BaseHashTable; |
| 45 | +import ComponentRef = NFComponentRef; |
| 46 | + |
| 47 | +public type Key = ComponentRef; |
| 48 | +public type Value = Integer; |
| 49 | + |
| 50 | +public type HashTableCrefFunctionsType = tuple<FuncHashCref, FuncCrefEqual, FuncCrefStr, FuncExpStr>; |
| 51 | +public type HashTable = tuple<array<list<tuple<Key, Integer>>>, |
| 52 | + tuple<Integer, Integer, array<Option<tuple<Key, Value>>>>, |
| 53 | + Integer, |
| 54 | + HashTableCrefFunctionsType>; |
| 55 | + |
| 56 | +partial function FuncHashCref |
| 57 | + input Key cr; |
| 58 | + input Integer mod; |
| 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 | + 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 | + hashTable := BaseHashTable.emptyHashTableWork(size,(ComponentRef.hash,ComponentRef.isEqual,ComponentRef.toString,intString)); |
| 95 | +end emptyHashTableSized; |
| 96 | + |
| 97 | +annotation(__OpenModelica_Interface="frontend"); |
| 98 | +end NFHashTable; |
0 commit comments