Here is the translated content in Markdown format suitable for Hugo with the Go code example translated to Modelica:
Maps are Modelica’s built-in associative data type (sometimes called hashes or dicts in other languages).
To create an empty map, use the builtin DynamicArray and Tuple:
Set key-value pairs using typical name[key] = val syntax:
Printing a map will show all of its key/value pairs:
Get a value for a key with name[key]:
If the key doesn’t exist, the zero value of the value type is returned:
The builtin size returns the number of key/value pairs when called on a map:
The builtin delete removes key/value pairs from a map:
To remove all key/value pairs from a map, use the clear builtin:
The optional second return value when getting a value from a map indicates if the key was present in the map. This can be used to disambiguate between missing keys and keys with zero values like 0 or "". Here we didn’t need the value itself, so we ignored it with the blank identifier _:
You can also declare and initialize a new map in the same line with this syntax:
The maps package contains a number of useful utility functions for maps:
Note that maps appear in the form map[k:v k:v] when printed with SI.Print.