Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Li_Chao_Tree< T > Class Template Reference

Li Chao tree for min line queries on an integral x-domain. More...

#include <DP_Optimizations.H>

Collaboration diagram for Aleph::Li_Chao_Tree< T >:
[legend]

Classes

struct  Line
 Affine line y = m*x + b. More...
 
struct  Node
 

Public Member Functions

 Li_Chao_Tree (const T x_left, const T x_right)
 
 Li_Chao_Tree (const Li_Chao_Tree &other)=default
 Copy the domain and the lines of another tree.
 
 Li_Chao_Tree (Li_Chao_Tree &&other) noexcept
 Take the lines of another tree, which is left empty over the same domain.
 
Li_Chao_Tree & operator= (const Li_Chao_Tree &other)=default
 Copy the domain and the lines of another tree.
 
Li_Chao_Tree & operator= (Li_Chao_Tree &&other) noexcept
 Exchange this tree with another, which is left with the previous domain and lines of this one.
 
void swap (Li_Chao_Tree &other) noexcept
 Exchange in O(1) the domains and the lines of this tree and another.
 
bool is_empty () const noexcept
 
size_t node_count () const noexcept
 
void clear ()
 
void add_line (const T slope, const T intercept)
 
T query (const T x) const
 

Private Member Functions

size_t new_node (const Line &line)
 
void add_line_impl (const size_t idx, const T l, const T r, Line line)
 
T query_impl (const size_t idx, const T l, const T r, const T x) const
 

Private Attributes

T x_left_
 
T x_right_
 
Array< Node > nodes_
 
size_t root_ = NIL
 

Static Private Attributes

static constexpr size_t NIL = std::numeric_limits<size_t>::max()
 

Detailed Description

template<typename T>
class Aleph::Li_Chao_Tree< T >

Li Chao tree for min line queries on an integral x-domain.

Supports arbitrary line insertion order and O(log X) min queries where X is the domain length.

Template Parameters
TSigned integral numeric type for coordinates.

Definition at line 569 of file DP_Optimizations.H.

Constructor & Destructor Documentation

◆ Li_Chao_Tree() [1/3]

template<typename T >
Aleph::Li_Chao_Tree< T >::Li_Chao_Tree ( const T  x_left,
const T  x_right 
)
inline

◆ Li_Chao_Tree() [2/3]

template<typename T >
Aleph::Li_Chao_Tree< T >::Li_Chao_Tree ( const Li_Chao_Tree< T > &  other)
default

Copy the domain and the lines of another tree.

Parameters
othertree to copy.

◆ Li_Chao_Tree() [3/3]

template<typename T >
Aleph::Li_Chao_Tree< T >::Li_Chao_Tree ( Li_Chao_Tree< T > &&  other)
inlinenoexcept

Take the lines of another tree, which is left empty over the same domain.

The implicit move took the nodes but copied the index of the root: the moved-from tree was not empty without nodes, and its add_line() and query() threw out_of_range.

Parameters
othertree to move from.

Definition at line 679 of file DP_Optimizations.H.

Member Function Documentation

◆ add_line()

◆ add_line_impl()

◆ clear()

◆ is_empty()

template<typename T >
bool Aleph::Li_Chao_Tree< T >::is_empty ( ) const
inlinenoexcept

◆ new_node()

template<typename T >
size_t Aleph::Li_Chao_Tree< T >::new_node ( const Line &  line)
inlineprivate

◆ node_count()

template<typename T >
size_t Aleph::Li_Chao_Tree< T >::node_count ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename T >
Li_Chao_Tree & Aleph::Li_Chao_Tree< T >::operator= ( const Li_Chao_Tree< T > &  other)
default

Copy the domain and the lines of another tree.

Parameters
othertree to copy.
Returns
this tree.

◆ operator=() [2/2]

template<typename T >
Li_Chao_Tree & Aleph::Li_Chao_Tree< T >::operator= ( Li_Chao_Tree< T > &&  other)
inlinenoexcept

Exchange this tree with another, which is left with the previous domain and lines of this one.

Parameters
othertree to move from.
Returns
this tree.

Definition at line 695 of file DP_Optimizations.H.

References Aleph::Li_Chao_Tree< T >::swap().

◆ query()

◆ query_impl()

template<typename T >
T Aleph::Li_Chao_Tree< T >::query_impl ( const size_t  idx,
const T  l,
const T  r,
const T  x 
) const
inlineprivate

◆ swap()

template<typename T >
void Aleph::Li_Chao_Tree< T >::swap ( Li_Chao_Tree< T > &  other)
inlinenoexcept

Exchange in O(1) the domains and the lines of this tree and another.

Parameters
othertree to exchange with.

Definition at line 705 of file DP_Optimizations.H.

References Aleph::Li_Chao_Tree< T >::nodes_, Aleph::Li_Chao_Tree< T >::root_, Aleph::Li_Chao_Tree< T >::x_left_, and Aleph::Li_Chao_Tree< T >::x_right_.

Referenced by Aleph::Li_Chao_Tree< T >::operator=().

Member Data Documentation

◆ NIL

◆ nodes_

◆ root_

◆ x_left_

◆ x_right_


The documentation for this class was generated from the following file: