|
|
delpi
0.0.1
DElta-complete LP solver
|
Set of variables optimised for fast access at the cost of memory. More...
#include <VariableSet.h>
Public Member Functions | |
| template<TypedIterable< Variable > T> | |
| VariableSet (const T &vars) | |
| Construct a new variable set from a range of vars. | |
| template<std::same_as< Variable >... Vars> | |
| VariableSet (const Variable &var, const Vars &... vars) | |
| Construct a new variable set from a sequence of variables. | |
| bool | empty () const |
| @checked{empty, variable set} | |
| Variable | Get (Id id) const |
| Use the id to get the variable in the set, if it exists. | |
| bool | Contains (const Variable &var) const |
| Check if the var is in the set. | |
| bool | Insert (const Variable &var) |
| Insert a var to the set. | |
| template<TypedIterable< Variable > T> | |
| void | Insert (const T &vars) |
| Insert a range of vars to the set. | |
| template<std::same_as< Variable >... Vars> | |
| void | Insert (const Variable &var, const Vars &... vars) |
| Insert a sequence of variables to the set. | |
| bool | Remove (const Variable &var) |
| Remove a var from the set. | |
| template<TypedIterable< Variable > T> | |
| void | Remove (const T &vars) |
| Remove a range of vars from the set. | |
| template<std::same_as< Variable >... Vars> | |
| void | Remove (const Variable &var, const Vars &... vars) |
| Remove a sequence of variables from the set. | |
| void | Clear () |
| Clear the set of all variables. | |
Private Member Functions | |
| bool | Contains (Id id) const |
| Check if the variable with the given id is in the set. | |
| bool | Insert (Id id) |
| Insert a variable with the given id to the set. | |
| bool | Remove (Id id) |
| Remove a variable with the given id from the set. | |
Private Attributes | |
| Id | min_id_ |
| Minimum id of the variables in the set. | |
| std::vector< bool > | vars_ |
| Vector tracking the presence of each variable in the set. | |
Set of variables optimised for fast access at the cost of memory.
Instead of using a hash set, it uses a vector of booleans to track the presence of each variable. The vector contains \( m \) elements, where \( m \) is the number obtained by subtracting the minimum id of the variables in the set 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 set of variables. For instance, checking if the set is empty or iterating over all the variables is linear in \( m \), not in the number of variables. @tip If you know the variable indexes are sparse, use a standard set instead.
Definition at line 33 of file VariableSet.h.
|
inlineexplicit |
Construct a new variable set from a range of vars.
| T | generic iterable containing variables |
| vars | range of variables to add to the set |
Definition at line 45 of file VariableSet.h.
|
inlineexplicit |
Construct a new variable set from a sequence of variables.
@tip This method will add the variables in the set one by one. Using VariableSet(T) can be more efficient for large sets.
| Vars | sequence of variables to add to the set |
| var | first variable to add to the set |
| vars | remaining variables to add to the set |
Definition at line 57 of file VariableSet.h.
|
inlinenodiscard |
Check if the var is in the set.
| var | variable to check |
Definition at line 87 of file VariableSet.h.
|
nodiscardprivate |
Check if the variable with the given id is in the set.
| id | id of the variable to check |
Definition at line 59 of file VariableSet.cpp.
|
nodiscard |
Use the id to get the variable in the set, if it exists.
| id | id of the variable to get |
| DelpiOutOfRangeException | if the id is not in the set |
Definition at line 55 of file VariableSet.cpp.
|
inline |
Insert a range of vars to the set.
Only variables not already in the set will be added.
| T | generic iterable containing variables |
| vars | range of variables to add |
Definition at line 103 of file VariableSet.h.
|
inline |
Insert a var to the set.
If the variable is already in the set, nothing happens.
| var | variable to add |
Definition at line 95 of file VariableSet.h.
|
inline |
Insert a sequence of variables to the set.
Only variables not already in the set will be added. @tip This method will add the variables in the set one by one. Using Insert(T) can be more efficient for large sets.
| Vars | sequence of variables to add |
| var | first variable to add |
| vars | remaining variables to add |
Definition at line 138 of file VariableSet.h.
|
private |
Insert a variable with the given id to the set.
| id | id of the variable to add |
Definition at line 20 of file VariableSet.cpp.
|
inline |
Remove a range of vars from the set.
Only variables in the set will be removed.
| T | generic iterable containing variables |
| vars | range of variables to remove |
Definition at line 157 of file VariableSet.h.
|
inline |
Remove a var from the set.
If the variable is not in the set, nothing happens.
| var | variable to remove |
Definition at line 149 of file VariableSet.h.
|
inline |
Remove a sequence of variables from the set.
Only variables in the set will be removed.
| Vars | sequence of variables to remove |
| var | first variable to remove |
| vars | remaining variables to remove |
Definition at line 168 of file VariableSet.h.
|
private |
Remove a variable with the given id from the set.
| id | id of the variable to remove |
Definition at line 62 of file VariableSet.cpp.