|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Convex Hull Trick for minimum queries. More...
#include <DP_Optimizations.H>
Classes | |
| struct | Line |
| Affine line y = m*x + b. More... | |
Public Member Functions | |
| Convex_Hull_Trick ()=default | |
| Construct an empty hull. | |
| Convex_Hull_Trick (const Convex_Hull_Trick &other)=default | |
| Copy the lines and the query cursor of another hull. | |
| Convex_Hull_Trick (Convex_Hull_Trick &&other) noexcept | |
| Take the lines of another hull, which is left empty, as clear() leaves it. | |
| Convex_Hull_Trick & | operator= (const Convex_Hull_Trick &other)=default |
| Copy the lines and the query cursor of another hull. | |
| Convex_Hull_Trick & | operator= (Convex_Hull_Trick &&other) noexcept |
| Exchange this hull with another, which is left with the previous lines and cursor of this one. | |
| void | swap (Convex_Hull_Trick &other) noexcept |
| Exchange in O(1) the lines and the cursors of this hull and another. | |
| size_t | size () const noexcept |
| bool | is_empty () const noexcept |
| void | clear () |
| void | reset_query_cursor () noexcept |
| void | add_line (const T slope, const T intercept) |
| Insert a new line; slopes must be non-increasing. | |
| T | query (const T x) const |
| Query minimum value at arbitrary x (O(log n)). | |
| T | query_monotone (const T x) |
| Query minimum with non-decreasing x (amortized O(1)). | |
Static Private Member Functions | |
| static long double | intersection_x (const Line &a, const Line &b) noexcept |
Private Attributes | |
| Array< Line > | lines_ |
| Array< long double > | starts_ |
| size_t | cursor_ = 0 |
Convex Hull Trick for minimum queries.
Supports insertion of lines with non-increasing slope and minimum queries over x. Query can be done in O(log n) for arbitrary x or amortized O(1) for non-decreasing x via query_monotone().
| T | Numeric type for slopes and coordinates. |
Definition at line 370 of file DP_Optimizations.H.
|
default |
Construct an empty hull.
|
default |
Copy the lines and the query cursor of another hull.
| other | hull to copy. |
|
inlinenoexcept |
Take the lines of another hull, which is left empty, as clear() leaves it.
The implicit move took the lines but copied the cursor of the monotone queries.
| other | hull to move from. |
Definition at line 417 of file DP_Optimizations.H.
|
inline |
Insert a new line; slopes must be non-increasing.
Definition at line 482 of file DP_Optimizations.H.
References ah_domain_error_if, Aleph::Array< T >::append(), Aleph::Convex_Hull_Trick< T >::cursor_, Aleph::intercept(), Aleph::Convex_Hull_Trick< T >::intersection_x(), Aleph::Convex_Hull_Trick< T >::lines_, Aleph::Array< T >::remove_last(), Aleph::Array< T >::size(), and Aleph::Convex_Hull_Trick< T >::starts_.
Referenced by Moved_From_Case< Convex_Hull_Trick< long > >::make(), TEST(), and TEST().
|
inline |
Definition at line 465 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::cursor_, Aleph::Convex_Hull_Trick< T >::lines_, Aleph::Convex_Hull_Trick< T >::starts_, and Aleph::Array< T >::swap().
|
inlinestaticprivatenoexcept |
Definition at line 394 of file DP_Optimizations.H.
Referenced by Aleph::Convex_Hull_Trick< T >::add_line().
|
inlinenoexcept |
Definition at line 460 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::lines_.
|
default |
Copy the lines and the query cursor of another hull.
| other | hull to copy. |
|
inlinenoexcept |
Exchange this hull with another, which is left with the previous lines and cursor of this one.
The implicit assignment exchanged the lines but not the cursors: query_monotone() of the source then read beyond the lines that it got.
| other | hull to move from. |
Definition at line 438 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::swap().
|
inline |
Query minimum value at arbitrary x (O(log n)).
Definition at line 531 of file DP_Optimizations.H.
References ah_runtime_error_if, Aleph::Convex_Hull_Trick< T >::lines_, and Aleph::Convex_Hull_Trick< T >::starts_.
|
inline |
Query minimum with non-decreasing x (amortized O(1)).
Definition at line 549 of file DP_Optimizations.H.
References ah_runtime_error_if, Aleph::and, Aleph::Convex_Hull_Trick< T >::cursor_, Aleph::Convex_Hull_Trick< T >::lines_, and Aleph::Convex_Hull_Trick< T >::starts_.
Referenced by TEST().
|
inlinenoexcept |
Definition at line 476 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::cursor_.
Referenced by TEST().
|
inlinenoexcept |
Definition at line 455 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::lines_.
Referenced by TEST().
|
inlinenoexcept |
Exchange in O(1) the lines and the cursors of this hull and another.
| other | hull to exchange with. |
Definition at line 448 of file DP_Optimizations.H.
References Aleph::Convex_Hull_Trick< T >::cursor_, Aleph::Convex_Hull_Trick< T >::lines_, Aleph::Convex_Hull_Trick< T >::starts_, and Aleph::Array< T >::swap().
Referenced by Aleph::Convex_Hull_Trick< T >::operator=().
|
private |
|
private |
Definition at line 390 of file DP_Optimizations.H.
Referenced by Aleph::Convex_Hull_Trick< T >::add_line(), Aleph::Convex_Hull_Trick< T >::clear(), Aleph::Convex_Hull_Trick< T >::is_empty(), Aleph::Convex_Hull_Trick< T >::query(), Aleph::Convex_Hull_Trick< T >::query_monotone(), Aleph::Convex_Hull_Trick< T >::size(), and Aleph::Convex_Hull_Trick< T >::swap().
|
private |
Definition at line 391 of file DP_Optimizations.H.
Referenced by Aleph::Convex_Hull_Trick< T >::add_line(), Aleph::Convex_Hull_Trick< T >::clear(), Aleph::Convex_Hull_Trick< T >::query(), Aleph::Convex_Hull_Trick< T >::query_monotone(), and Aleph::Convex_Hull_Trick< T >::swap().