OMCompiler/Compiler/Util/SBAtomicSet.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 uniontype SBAtomicSet | ||
| 37 | |||
| 38 | import SBMultiInterval; | ||
| 39 | import SBInterval; | ||
| 40 | import UnorderedSet; | ||
| 41 | |||
| 42 | protected | ||
| 43 | |||
| 44 | public | ||
| 45 | record ATOMIC_SET | ||
| 46 | SBMultiInterval aset; | ||
| 47 | Integer ndim; | ||
| 48 | end ATOMIC_SET; | ||
| 49 | |||
| 50 | function new | ||
| 51 | input SBMultiInterval mi; | ||
| 52 | output SBAtomicSet set; | ||
| 53 | algorithm | ||
| 54 | 13145 | set := ATOMIC_SET(SBMultiInterval.copy(mi), mi.ndim); | |
| 55 | end new; | ||
| 56 | |||
| 57 | function newEmpty | ||
| 58 | output SBAtomicSet set; | ||
| 59 | algorithm | ||
| 60 | 586 | set := ATOMIC_SET(SBMultiInterval.newEmpty(), 0); | |
| 61 | end newEmpty; | ||
| 62 | |||
| 63 | function copy | ||
| 64 | input SBAtomicSet set; | ||
| 65 | output SBAtomicSet outSet; | ||
| 66 | algorithm | ||
| 67 | 5149 | outSet := ATOMIC_SET(SBMultiInterval.copy(set.aset), set.ndim); | |
| 68 | end copy; | ||
| 69 | |||
| 70 | function ndim | ||
| 71 | input SBAtomicSet set; | ||
| 72 | output Integer ndim = set.ndim; | ||
| 73 | end ndim; | ||
| 74 | |||
| 75 | function isEmpty | ||
| 76 | input SBAtomicSet set; | ||
| 77 | output Boolean empty = SBMultiInterval.isEmpty(set.aset); | ||
| 78 | end isEmpty; | ||
| 79 | |||
| 80 | function contains | ||
| 81 | input array<Integer> vals; | ||
| 82 | input SBAtomicSet set; | ||
| 83 | output Boolean res = SBMultiInterval.contains(vals, set.aset); | ||
| 84 | end contains; | ||
| 85 | |||
| 86 | function intersection | ||
| 87 | input SBAtomicSet set1; | ||
| 88 | input SBAtomicSet set2; | ||
| 89 | output SBAtomicSet res; | ||
| 90 | algorithm | ||
| 91 | 10733 | res := new(SBMultiInterval.intersection(set1.aset, set2.aset)); | |
| 92 | end intersection; | ||
| 93 | |||
| 94 | function complement | ||
| 95 | input SBAtomicSet set1; | ||
| 96 | input SBAtomicSet set2; | ||
| 97 | output UnorderedSet<SBAtomicSet> res; | ||
| 98 | protected | ||
| 99 | UnorderedSet<SBMultiInterval> diff; | ||
| 100 | algorithm | ||
| 101 | 293 | diff := SBMultiInterval.complement(set1.aset, set2.aset); | |
| 102 | 293 | res := UnorderedSet.new(hash, isEqual, UnorderedSet.bucketCount(diff)); | |
| 103 | |||
| 104 |
2/2✓ Branch 1 taken 208 times.
✓ Branch 2 taken 85 times.
|
293 | if not UnorderedSet.isEmpty(diff) then |
| 105 |
2/2✓ Branch 2 taken 85 times.
✓ Branch 3 taken 85 times.
|
255 | for s in UnorderedSet.toArray(diff) loop |
| 106 | 85 | UnorderedSet.add(new(s), res); | |
| 107 | end for; | ||
| 108 | end if; | ||
| 109 | end complement; | ||
| 110 | |||
| 111 | function crossProd | ||
| 112 | input SBAtomicSet set1; | ||
| 113 | input SBAtomicSet set2; | ||
| 114 | output SBAtomicSet res; | ||
| 115 | algorithm | ||
| 116 | ✗ | res := new(SBMultiInterval.crossProd(set1.aset, set2.aset)); | |
| 117 | end crossProd; | ||
| 118 | |||
| 119 | function cardinality | ||
| 120 | input SBAtomicSet set; | ||
| 121 | input output Integer card = 0; | ||
| 122 | algorithm | ||
| 123 | ✗ | card := card + SBMultiInterval.cardinality(set.aset); | |
| 124 | end cardinality; | ||
| 125 | |||
| 126 | function aset | ||
| 127 | input SBAtomicSet set; | ||
| 128 | output SBMultiInterval res = set.aset; | ||
| 129 | end aset; | ||
| 130 | |||
| 131 | function minElem | ||
| 132 | input SBAtomicSet set; | ||
| 133 | output array<Integer> res = SBMultiInterval.minElem(set.aset); | ||
| 134 | end minElem; | ||
| 135 | |||
| 136 | function replace | ||
| 137 | input SBInterval i; | ||
| 138 | input Integer dim; | ||
| 139 | input SBAtomicSet set; | ||
| 140 | output SBAtomicSet res; | ||
| 141 | algorithm | ||
| 142 | 1 | res := new(SBMultiInterval.replace(i, dim, set.aset)); | |
| 143 | end replace; | ||
| 144 | |||
| 145 | function isEqual | ||
| 146 | input SBAtomicSet set1; | ||
| 147 | input SBAtomicSet set2; | ||
| 148 | output Boolean equal = SBMultiInterval.isEqual(set1.aset, set2.aset); | ||
| 149 | end isEqual; | ||
| 150 | |||
| 151 | function hash | ||
| 152 | input SBAtomicSet set1; | ||
| 153 | output Integer hash = SBMultiInterval.hash(set1.aset); | ||
| 154 | end hash; | ||
| 155 | |||
| 156 | function toString | ||
| 157 | input SBAtomicSet set; | ||
| 158 | output String str = "{" + SBMultiInterval.toString(set.aset) + "}"; | ||
| 159 | end toString; | ||
| 160 | |||
| 161 | annotation(__OpenModelica_Interface="util"); | ||
| 162 | end SBAtomicSet; | ||
| 163 |