3. Overview Map¶
A map is a collection that associates a key name with a matrix. The matrix is either a string matrix, a real matrix or a complex matrix. Unlike a Container (see Overview Container) the matrix is not accessed through an index (1,2,3,…) but by a key name like “Engine”, “Test”, etc.
Example
hMap = MapCreate();
MapSetAt(hMap, "Mot-No12", ["1,6l", "4 Valves", "74kW"]);
MapSetAt(hMap, "Mot-No432", ["2.0l", "4 Valves", "100kW"]);
MapSetAt(hMap, "Mot-No42", ["2.5l", "4 Valves", "115kW"]);
MapSetAt(hMap, "Mot-No132", ["3.0l", "4 Valves", "150kW"]);
ssKey = "Mot-No42";
svMotData = MapLookup(hMap, ssKey);
if (ObjGetOk() == FALSE) {
MessageBox(sprintf("Key \"%s\" not found", ssKey));
return FALSE;
}
sprintf("The engine has %s" svMotData[3]);
Create and Destroy |
|
---|---|
MapCreate creates a new map object. |
|
MapDestroy destroys the given map and frees any memory the map occupied. |
Set |
|
---|---|
MapInitHashTable initializes the hash table. |
|
MapLoad loads a map from a file, that was created with the MapSave function. |
|
MapPrint prints the data elements of a map into the command window. |
|
MapRemoveAt looks up the map entry corresponding to the supplied key. If the key is found, it removes the entry. |
|
The MapSave function saves the data elements of a map in a file. |
|
MapSetAt means to insert an element in a map. First, the key is looked up. If the key is found, then the corresponding value is changed; otherwise a new key-value pair is created. |
|
OBJSetMap saves a map in an object. |
Get |
|
---|---|
MapCopy creates a copy of the given map object. |
|
MapGetCount returns the number of elements in the map. |
|
MapGetKeys returns a vector of keys. |
|
Checks if a key already exists in the map. |
|
MapLookup uses a hashing algorithm to quickly find the map element with a key that exactly matches the given key. |
|
OBJGetMap returns a map handle for a given name saved in the specified object. |
|
OBJGetMapNames returns a string vector with map names or an empty string if the object does not contain any maps. |
See also
id-630667