LSPMap Class¶
- class localsolver.modeler.LSPMap¶
An LSPMap is a data structure mapping keys to values. A map is both an associative table and an array. Setting a value to an existing key will overwrite any value previously set for that key.
When used as an array-like structure, adding a new unkeyed element to an LSPMap with
LSPMap.AddValue
automatically assigns an integer key to the element equal to the largest integer key already present plus one, or zero if no integer key exists.Most of the functions below exist in multiple versions: values and keys can be manipulated through their native type (like
int
,double
,string
,LSPMap
,LSPFunction
…) or manipulated with anLSPValue
which is a container that can hold any type of value. Using the native type is more convenient and results in less overhead most of the time.LSPValue
should only be used when you don’t know the type of the manipulated value.The enumerators returned by the method
GetEnumerator()
follow the fail-fast convention: if the map is structurally modified after the creation of an enumerator (by using the methods Add, Set, Unset or Clear), the enumerator will throw an exception. In other words, you can’t modify a map while you are iterating over it.- Since
10.0
Summary¶
Returns the number of elements in the map. |
|
Erases all elements from the map. |
|
Adds the given value in the map. |
|
Adds the given integer value in the map. |
|
Adds the given double value in the map. |
|
Adds the given boolean value in the map. |
|
Adds the given expression in the map. |
|
Adds the given string value in the map. |
|
Adds the given map in the map. |
|
Adds the given function in the map. |
|
Adds the given module in the map. |
|
Returns the value associated with the given key as a LSPValue. |
|
Returns the integer value associated with the given key. |
|
Returns the double value associated with the given key. |
|
Returns the boolean value associated with the given key. |
|
Returns the string value associated with the given key. |
|
Returns the LSExpression associated with the given key. |
|
Returns the map associated with the given key. |
|
Returns the function associated with the given key. |
|
Returns the module associated with the given key. |
|
Associates the LSPValue to the given key in the map. |
|
Associates the integer value to the given key in the map. |
|
Associates the double value to the given key in the map. |
|
Associates the boolean value to the given key in the map. |
|
Associates the string value to the given key in the map. |
|
Associates the expression to the given key in the map. |
|
Associates the map to the given key in the map. |
|
Associates the function to the given key in the map. |
|
Associates the module to the given key in the map. |
|
Unsets the given key in the map if present. |
|
Returns true if the given key is defined in the map. |
|
Returns the map as a LSPValue. |
|
Returns an iterator to the elements of this map. |
|
Releases the reference. |
Instance methods¶
- long Count()¶
Returns the number of elements in the map.
- void Clear()¶
Erases all elements from the map. After this call,
LSPMap.Count()
returns zero.
- void AddValue(LSPValue value)¶
Adds the given value in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
value (LSPValue) – Value to add in the map.
- void AddInt(long value)¶
Adds the given integer value in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
value (
long
) – Value to add in the map.
- void AddDouble(double value)¶
Adds the given double value in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
value (
double
) – Value to add in the map.
- void AddBool(bool value)¶
Adds the given boolean value in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
value (
bool
) – Value to add in the map.
- void AddExpression(LSExpression expr)¶
Adds the given expression in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
expr (LSExpression) – Value to add in the map.
- void AddString(string value)¶
Adds the given string value in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
value (
string
) – Value to add in the map.
- void AddMap(LSPMap map)¶
Adds the given map in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
map (LSPMap) – Map to add in the map.
- void AddFunction(LSPFunction function)¶
Adds the given function in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
function (LSPFunction) – Function to add in the map.
- void AddModule(LSPModule module)¶
Adds the given module in the map. The associated key corresponds to the largest integer key present in the map plus one, or zero if no integer key exists.
- Arguments
module (LSPModule) – Module to add in the map.
- LSPValue GetValue(long key)¶
- LSPValue GetValue(string key)
- LSPValue GetValue(LSPValue key)
Returns the value associated with the given key as a
LSPValue
. If no value is associated with the key, an LSPValue representing nil is returned.
- long GetInt(long key)¶
- long GetInt(string key)
- long GetInt(LSPValue key)
Returns the integer value associated with the given key. The value must exist and must be an integer.
- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
Integer value associated with the key.
- Return type
long
- double GetDouble(long key)¶
- double GetDouble(string key)
- double GetDouble(LSPValue key)
Returns the double value associated with the given key. The value must exist and must be a double.
- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
Double value associated with the key.
- Return type
double
- bool GetBool(long key)¶
- bool GetBool(string key)
- bool GetBool(LSPValue key)
Returns the boolean value associated with the given key. The value must exist and must be a boolean.
- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
Boolean value associated with the key.
- Return type
bool
- string GetString(long key)¶
- string GetString(string key)
- string GetString(LSPValue key)
Returns the string value associated with the given key. The value must exist and must be a string.
- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
String value associated with the key.
- Return type
string
- LSExpression GetExpression(long key)¶
- LSExpression GetExpression(string key)
- LSExpression GetExpression(LSPValue key)
Returns the
LSExpression
associated with the given key. The value must exist and must be an expression.- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
Expression associated with the key.
- Return type
- LSPMap GetMap(long key)¶
- LSPMap GetMap(string key)
- LSPMap GetMap(LSPValue key)
Returns the map associated with the given key. The value must exist and must be a map.
- LSPFunction GetFunction(long key)¶
- LSPFunction GetFunction(string key)
- LSPFunction GetFunction(LSPValue key)
Returns the function associated with the given key. The value must exist and must be a function.
- Arguments
key (
long
,string
orLSPValue
) – Key searched.- Returns
Function associated with the key.
- Return type
- LSPModule GetModule(long key)¶
- LSPModule GetModule(string key)
- LSPModule GetModule(LSPValue key)
Returns the module associated with the given key. The value must exist and must be a module.
- void SetValue(long key, LSPValue value)¶
- void SetValue(string key, LSPValue value)
- void SetValue(LSPValue key, LSPValue value)
Associates the
LSPValue
to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect asUnset()
.
- void SetInt(long key, long value)¶
- void SetInt(string key, long value)
- void SetInt(LSPValue key, long value)
Associates the integer value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (long) – Value to set.
- void SetDouble(long key, double value)¶
- void SetDouble(string key, double value)
- void SetDouble(LSPValue key, double value)
Associates the double value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (double) – Value to set.
- void SetBool(long key, bool value)¶
- void SetBool(string key, bool value)
- void SetBool(LSPValue key, bool value)
Associates the boolean value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (bool) – Value to set.
- void SetString(long key, string value)¶
- void SetString(string key, string value)
- void SetString(LSPValue key, string value)
Associates the string value to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (string) – Value to set.
- void SetExpression(long key, LSExpression expr)¶
- void SetExpression(string key, LSExpression expr)
- void SetExpression(LSPValue key, LSExpression expr)
Associates the expression to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (LSExpression) – Expression to set.
- void SetMap(long key, LSPMap map)¶
- void SetMap(string key, LSPMap map)
- void SetMap(LSPValue key, LSPMap map)
Associates the map to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.
- void SetFunction(long key, LSPFunction function)¶
- void SetFunction(string key, LSPFunction function)
- void SetFunction(LSPValue key, LSPFunction function)
Associates the function to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.- Arguments
key (
long
,string
orLSPValue
) – Key to set.value (LSPFunction) – Function to set.
- void SetModule(long key, LSPModule module)¶
- void SetModule(string key, LSPModule module)
- void SetModule(LSPValue key, LSPModule module)
Associates the module to the given key in the map. If the map already contained an association for the key, the previous value is replaced. The key must not be nil. If the value is nil, this has the same effect as
Unset()
.
- void Unset(long key)¶
- void Unset(string key)
- void Unset(LSPValue key)
Unsets the given key in the map if present. If the key doesn’t exist in the map do nothing. The key must not be nil.
- Arguments
key (
long
,string
orLSPValue
) – Key to unset.
- bool IsDefined(long key)¶
- bool IsDefined(string key)
- bool IsDefined(LSPValue key)
Returns true if the given key is defined in the map.
- Arguments
key (
long
,string
orLSPValue
) – Key to search.
- IEnumerator<KeyValuePair<LSPValue, GetEnumerator()¶
Returns an iterator to the elements of this map.
- Returns
Iterator to the elements of this map.
- Return type
IEnumerator
- void Dispose()¶
Releases the reference. If this map was already released, returns immediately and does nothing. Invoking any method on this object after this operation will throw an exception.
Note: Releasing a reference does not necessarily imply that the underlying map object is destroyed. It is only destroyed if no more references point to it.
- Since
11.5