|
|
delpi
0.0.1
DElta-complete LP solver
|
Map from variables to an arbitrary type T optimised for fast access at the cost of memory. More...
#include <VariableMap.h>
Public Member Functions | |
| template<TypedIterable< value_type > Items> | |
| VariableMap (const Items &items) | |
| Construct a new variable map from a range of items. | |
| bool | empty () const |
| @checked{empty, variable map} | |
| mapped_type | At (const Variable var) const |
| Use the var to get the value it is mapped to, if it exists. | |
| bool | Contains (const Variable &var) const |
| Check if the var is in the map. | |
| bool | Insert (const Variable &var, const mapped_type &value) |
| Insert a var to the map and set it to the value. | |
| template<TypedIterable< value_type > I> | |
| void | Insert (const I &items) |
| Insert a range of key-value pairs to the map. | |
| bool | Remove (const Variable &var) |
| Remove a var from the map. | |
| template<TypedIterable< Variable > V> | |
| void | Remove (const V &vars) |
| Remove a range of vars from the map. | |
| void | Clear () |
| Clear the map of all variables. | |
Private Member Functions | |
| bool | Contains (const Id id) const |
| Check if the variable with the given id is in the map. | |
| bool | Insert (const Id id, const T &value) |
| Insert a variable with the given id to the map and set it to the value. | |
| bool | Remove (const Id id) |
| Remove a variable with the given id from the map. | |
Private Attributes | |
| Id | min_id_ |
| Minimum id of the variables in the map. | |
| std::vector< std::optional< T > > | vars_ |
| Vector tracking the value each variable is mapped to. | |
Map from variables to an arbitrary type T optimised for fast access at the cost of memory.
Instead of using a hash map, it uses a vector of std::optional values to track the value each variable maps to. The vector contains \( m \) elements, where \( m \) is the number obtained by subtracting the minimum id of the variables in the map from the maximum id plus 1, i.e. \( m = \text{max_id} - \text{min_id} + 1 \). Hence, the structure will be most efficient, both in terms of memory and speed, when the variables are contiguous and have a small range of ids, but it will be extremely inefficient in terms of space when the variables are sparse with respect to their ids. This also effects computing properties over the whole map of variables. For instance, checking if the map is empty or iterating over all the entries is linear in \( m \), not in the number of entries. @tip If you know the variable indexes are sparse, use a standard map instead.
Definition at line 35 of file VariableMap.h.
|
inlineexplicit |
Construct a new variable map from a range of items.
| Items | key-value pairs to add to the map |
| items | range of key-value pairs to add to the map |
Definition at line 52 of file VariableMap.h.
|
inlinenodiscard |
Use the var to get the value it is mapped to, if it exists.
| var | variable whose value to get |
| DelpiOutOfRangeException | if the var is not in the map |
Definition at line 84 of file VariableMap.h.
|
inlinenodiscardprivate |
Check if the variable with the given id is in the map.
| id | id of the variable to check |
Definition at line 168 of file VariableMap.h.
|
inlinenodiscard |
Check if the var is in the map.
| var | variable to check |
Definition at line 94 of file VariableMap.h.
|
inline |
Insert a range of key-value pairs to the map.
Existing variables will be updated with the new values.
| I | generic iterable containing variables |
| items | range of key-value pairs to add |
Definition at line 111 of file VariableMap.h.
|
inlineprivate |
Insert a variable with the given id to the map and set it to the value.
| id | id of the variable to add |
| value | value to set the variable to |
Definition at line 178 of file VariableMap.h.
|
inline |
Insert a var to the map and set it to the value.
Existing variables will be updated with the new value.
| var | variable to add |
| value | value to set the variable to |
Definition at line 103 of file VariableMap.h.
|
inlineprivate |
Remove a variable with the given id from the map.
| id | id of the variable to remove |
Definition at line 205 of file VariableMap.h.
|
inline |
Remove a range of vars from the map.
Only variables in the map will be removed.
| vars | range of variables to remove |
Definition at line 152 of file VariableMap.h.
|
inline |
Remove a var from the map.
If the variable is not in the map, nothing happens.
| var | variable to remove |
Definition at line 145 of file VariableMap.h.