|
dlinear
0.0.1
Delta-complete SMT solver for linear programming
|
Vector that maintains its elements sorted. More...
#include <SortedVector.hpp>
Public Member Functions | |
SortedVector ()=default | |
Construct a new SortedVector object. | |
SortedVector (size_t size) | |
Construct a new SortedVector object with the giver size . | |
SortedVector (std::initializer_list< T > list) | |
Construct a new SortedVector object using an initializer list . | |
template<typename V > | |
iterator | insert (V &&value) |
Insert an element with the provided value into the sorted list. | |
template<typename V > | |
iterator | insert (V &&value, bool insert_lower) |
Insert an element with the provided value into the sorted list. | |
template<typename... Args> | |
iterator | emplace (Args &&... args) |
Emplace a new element into the sorted list. | |
template<typename... Args> | |
iterator | emplace (bool insert_lower, Args &&... args) |
Emplace a new element into the sorted list. | |
size_t | size () const |
Get read-only access to the size of the vector. | |
bool | empty () const |
Check whether the vector is emtpy. | |
const T & | at (size_t i) const |
Access element at index i with bounds checking. | |
const T & | at (int i) const |
Access element at index i with bounds checking. | |
const T & | operator[] (size_t i) const |
Direct access to the underlying vector. | |
const T & | front () const |
Reference to the first element in the sorted list. | |
const T & | back () const |
Reference to the last element in the sorted list. | |
bool | erase (const const_iterator &it) |
Remove the element at position it from the sorted list. | |
bool | erase (size_t i) |
Remove the element at index i from the sorted list. | |
bool | erase (int i) |
Remove the element at index i from the sorted list. | |
bool | erase_value (const T &value) |
Remove an element with the provided value from the sorted list. | |
const_iterator | find (const T &value) const |
Find the index of an element with the provided value in the sorted list. | |
const_iterator | lower_bound (const T &value) const |
Find the first position in which an element with the provided value could be inserted without changing the ordering. | |
const_iterator | upper_bound (const T &value) const |
Find the last position in which an element with the provided value could be inserted without changing the ordering. | |
size_t | count (const T &value) const |
Count the number of occurrences of an element with the provided value in the sorted list. | |
bool | contains (const T &value) const |
Check if the element with the provided value is contained in the vector. | |
const_iterator | lesser_end (const T &value) const |
Find the last element in the vector with a value lesser than value and return an iterator to the position after that one. | |
const_iterator | greater_begin (const T &value) const |
Find the first element in the vector with a value greater than value and return an iterator to its position. | |
void | clear () |
Clear the sorted list, removing all elements. | |
Private Member Functions | |
bool | is_equal (const T &lhs, const T &rhs) const |
Use the compare_ function to check if two elements are equal. | |
Private Attributes | |
std::vector< T > | vector_ |
Underlying vector to store the sorted list. | |
Compare | compare_ |
Comparison function to maintain the sorted order. | |
Vector that maintains its elements sorted.
This class is implemented as a wrapper around std::vector to provide a sorted list of elements. Each time an element is inserted, it is placed in the correct position to maintain the sorted order.
Using a custom comparison function is also supported:
T | type of the elements in the sorted list |
Compare | comparison function to maintain the sorted order |
Definition at line 49 of file SortedVector.hpp.
|
inlineexplicit |
Construct a new SortedVector object with the giver size
.
size | size of the sorted list. |
Definition at line 71 of file SortedVector.hpp.
|
inline |
Construct a new SortedVector object using an initializer list
.
The elements are placed in the correct position to maintain the sorted order.
list | initializer list of elements |
Definition at line 78 of file SortedVector.hpp.
|
inline |
Access element at index i
with bounds checking.
It also supports negative indices, where -1 is the last element, -2 is the second to last, and so on.
i | position of the element to access (negative indices are supported) |
std::out_of_range | if i is out of range |
Definition at line 167 of file SortedVector.hpp.
|
inline |
Access element at index i
with bounds checking.
i | position of the element to access |
std::out_of_range | if i is out of range |
Definition at line 154 of file SortedVector.hpp.
|
inline |
Reference to the last element in the sorted list.
Definition at line 190 of file SortedVector.hpp.
|
inlinenodiscard |
Check if the element with the provided value
is contained in the vector.
value | value of the element to search |
Definition at line 307 of file SortedVector.hpp.
|
inlinenodiscard |
Count the number of occurrences of an element with the provided value
in the sorted list.
If the element is not found, 0 is returned.
value | value of the element to count |
Definition at line 293 of file SortedVector.hpp.
|
inline |
Emplace a new element into the sorted list.
The arguments are forwarded to the constructor of the element type. The element is placed in the correct position to maintain the sorted order.
args | arguments to forward to the constructor of the element type |
Definition at line 124 of file SortedVector.hpp.
|
inline |
Emplace a new element into the sorted list.
The arguments are forwarded to the constructor of the element type. The element is placed in the correct position to maintain the sorted order. This version allows to specify if the element should be inserted in the lower or upper bound.
insert_lower | if true, the element is inserted in the lower bound, otherwise in the upper bound |
args | arguments to forward to the constructor of the element type |
Definition at line 138 of file SortedVector.hpp.
|
inlinenodiscard |
Check whether the vector is emtpy.
Definition at line 146 of file SortedVector.hpp.
|
inline |
Remove the element at position it
from the sorted list.
If the iterator is out of range, false is returned.
it | iterator to the element to remove |
Definition at line 200 of file SortedVector.hpp.
|
inline |
Remove the element at index i
from the sorted list.
It also supports negative indices, where -1 is the last element, -2 is the second to last, and so on. If the index is out of range, false is returned.
i | index of the element to remove |
Definition at line 226 of file SortedVector.hpp.
|
inline |
Remove the element at index i
from the sorted list.
If the index is out of range, false is returned.
i | index of the element to remove |
Definition at line 212 of file SortedVector.hpp.
|
inline |
Remove an element with the provided value
from the sorted list.
If multiple elements have the same value
, only the first one is removed. If the element is not found, false is returned.
value | value of the element to remove |
Definition at line 241 of file SortedVector.hpp.
|
inline |
Find the index of an element with the provided value
in the sorted list.
If the element is not found, the end iterator is returned.
value | value of the element to find |
Definition at line 256 of file SortedVector.hpp.
|
inline |
Reference to the first element in the sorted list.
Definition at line 184 of file SortedVector.hpp.
|
inlinenodiscard |
Find the first element in the vector with a value greater than value
and return an iterator to its position.
value | lower bound for the search |
value
Definition at line 325 of file SortedVector.hpp.
|
inline |
Insert an element with the provided value
into the sorted list.
The element is placed in the correct position to maintain the sorted order. It returns an iterator to the inserted element.
V | type of the element to insert |
value | value of the element to insert |
Definition at line 93 of file SortedVector.hpp.
|
inline |
Insert an element with the provided value
into the sorted list.
The element is placed in the correct position to maintain the sorted order. It returns an iterator to the inserted element. This version allows to specify if the element should be inserted in the lower or upper bound.
V | type of the element to insert |
value | value of the element to insert |
insert_lower | if true, the element is inserted in the lower bound, otherwise in the upper bound |
Definition at line 110 of file SortedVector.hpp.
|
inlinenodiscardprivate |
Use the compare_ function to check if two elements are equal.
Since the function only checks ordering, to make sure two elements are equal compare_ must be used twice.
lhs | left-hand side element |
rhs | right-hand side element |
Definition at line 357 of file SortedVector.hpp.
|
inlinenodiscard |
Find the last element in the vector with a value lesser than value
and return an iterator to the position after that one.
value | upper bound for the search |
value
Definition at line 315 of file SortedVector.hpp.
|
inline |
Find the first position in which an element with the provided value
could be inserted without changing the ordering.
It is equivalent to using std::lower_bound with the Compare
function.
value | value of the element to find |
Definition at line 270 of file SortedVector.hpp.
|
inline |
Direct access to the underlying vector.
i | position of the element to access |
Definition at line 178 of file SortedVector.hpp.
|
inlinenodiscard |
Get read-only access to the size of the vector.
Definition at line 143 of file SortedVector.hpp.
|
inline |
Find the last position in which an element with the provided value
could be inserted without changing the ordering.
It is equivalent to using std::upper_bound with the Compare
function.
value | value of the element to find |
Definition at line 282 of file SortedVector.hpp.