#include <lazy_set.hh>
Public Types | |
typedef E | value |
Type of the stored value. | |
Public Member Functions | |
void | clear () |
Make the set empty. | |
const E & | element (unsigned i) const |
Return the i-th element of the set. | |
bool | get_mode () const |
Get the mode of the lazy set. | |
bool | has (const E &elt) const |
Test if the object elt belongs to the set. | |
lazy_set_< E > & | insert (const E &elt) |
Insert an element elt into the set. | |
bool | is_empty () const |
Test if the set is empty. | |
lazy_set_ () | |
Constructor without arguments. | |
unsigned | nelements () const |
Return the number of elements of the set. | |
const E & | operator[] (unsigned i) const |
Return the i-th element of the set. | |
lazy_set_< E > & | remove (const E &elt) |
Remove an element elt into the set. | |
void | set_const_mode (bool mode) |
Set the mode of the lazy_set. | |
const std::vector< E > & | vect () const |
Give access to the set elements. | |
Private Member Functions | |
void | update_ () const |
Update v_ from s_. | |
Private Attributes | |
bool | mode_ |
Tell what the lazy set mode is. | |
bool | needs_update_ |
Tell if v_ needs to be updated. | |
std::set< E > | s_ |
Set of elements. | |
std::vector< E > | v_ |
Array of elements. |
This set class is designed to store a mathematical set and to present it to the user as a linear array (std::vector).
Elements are stored by copy. Implementation is lazy.
E
is the element type, which shall not be const-qualified.
Definition at line 66 of file lazy_set.hh.
typedef E mln::util::lazy_set_< E >::value |
mln::util::lazy_set_< E >::lazy_set_ | ( | ) | [inline] |
Constructor without arguments.
Definition at line 206 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, and mln::util::lazy_set_< E >::needs_update_.
void mln::util::lazy_set_< E >::clear | ( | ) | [inline] |
Make the set empty.
All elements contained in the set are destroyed so the set is emptied. The lazy set can be cleared even if it is in const mode and then it is set in non-const mode.
Definition at line 291 of file lazy_set.hh.
References mln::util::lazy_set_< E >::is_empty(), mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, mln::util::lazy_set_< E >::s_, and mln::util::lazy_set_< E >::v_.
const E & mln::util::lazy_set_< E >::element | ( | unsigned | i | ) | const [inline] |
Return the i-th element of the set.
[in] | i | Index of the element to retrieve. |
Definition at line 240 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, mln::util::lazy_set_< E >::s_, mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::v_.
Referenced by mln::util::lazy_set_< E >::operator[]().
bool mln::util::lazy_set_< E >::get_mode | ( | ) | const [inline] |
Get the mode of the lazy set.
Definition at line 339 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_.
bool mln::util::lazy_set_< E >::has | ( | const E & | elt | ) | const [inline] |
Test if the object elt
belongs to the set.
[in] | elt | A possible element of the set. |
elt
is in the set. Definition at line 272 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::s_, and mln::util::lazy_set_< E >::v_.
lazy_set_< E > & mln::util::lazy_set_< E >::insert | ( | const E & | elt | ) | [inline] |
Insert an element elt
into the set.
[in] | elt | The element to be inserted. |
elt
is already in the set, this method is a no-op.
Definition at line 215 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, and mln::util::lazy_set_< E >::s_.
bool mln::util::lazy_set_< E >::is_empty | ( | ) | const [inline] |
Test if the set is empty.
Definition at line 283 of file lazy_set.hh.
References mln::util::lazy_set_< E >::nelements().
Referenced by mln::util::lazy_set_< E >::clear().
unsigned mln::util::lazy_set_< E >::nelements | ( | ) | const [inline] |
Return the number of elements of the set.
Definition at line 261 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::s_, and mln::util::lazy_set_< E >::v_.
Referenced by mln::util::lazy_set_< E >::is_empty().
const E & mln::util::lazy_set_< E >::operator[] | ( | unsigned | i | ) | const [inline] |
Return the i-th element of the set.
[in] | i | Index of the element to retrieve. |
Definition at line 253 of file lazy_set.hh.
References mln::util::lazy_set_< E >::element().
lazy_set_< E > & mln::util::lazy_set_< E >::remove | ( | const E & | elt | ) | [inline] |
Remove an element elt
into the set.
[in] | elt | The element to be inserted. |
elt
is already in the set, this method is a no-op.
Definition at line 227 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, and mln::util::lazy_set_< E >::s_.
void mln::util::lazy_set_< E >::set_const_mode | ( | bool | mode | ) | [inline] |
Set the mode of the lazy_set.
The lazy set can have two modes :
[in] | mode | True for const mode, false for non-const. |
Definition at line 314 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, mln::util::lazy_set_< E >::s_, mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::v_.
void mln::util::lazy_set_< E >::update_ | ( | ) | const [inline, private] |
Update v_ from s_.
Make the vector contains the same element than the sorted set..
Definition at line 347 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, mln::util::lazy_set_< E >::s_, and mln::util::lazy_set_< E >::v_.
Referenced by mln::util::lazy_set_< E >::element(), mln::util::lazy_set_< E >::set_const_mode(), and mln::util::lazy_set_< E >::vect().
const std::vector< E > & mln::util::lazy_set_< E >::vect | ( | ) | const [inline] |
Give access to the set elements.
The complexity of this method is O(1).
Definition at line 303 of file lazy_set.hh.
References mln::util::lazy_set_< E >::mode_, mln::util::lazy_set_< E >::needs_update_, mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::v_.
bool mln::util::lazy_set_< E >::mode_ [private] |
Tell what the lazy set mode is.
Definition at line 198 of file lazy_set.hh.
Referenced by mln::util::lazy_set_< E >::clear(), mln::util::lazy_set_< E >::element(), mln::util::lazy_set_< E >::get_mode(), mln::util::lazy_set_< E >::has(), mln::util::lazy_set_< E >::insert(), mln::util::lazy_set_< E >::lazy_set_(), mln::util::lazy_set_< E >::nelements(), mln::util::lazy_set_< E >::remove(), mln::util::lazy_set_< E >::set_const_mode(), mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::vect().
bool mln::util::lazy_set_< E >::needs_update_ [mutable, private] |
Tell if v_ needs to be updated.
Definition at line 195 of file lazy_set.hh.
Referenced by mln::util::lazy_set_< E >::clear(), mln::util::lazy_set_< E >::element(), mln::util::lazy_set_< E >::insert(), mln::util::lazy_set_< E >::lazy_set_(), mln::util::lazy_set_< E >::remove(), mln::util::lazy_set_< E >::set_const_mode(), mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::vect().
std::set<E> mln::util::lazy_set_< E >::s_ [private] |
Set of elements.
This structure is always up-to-date w.r.t. the set contents.
Definition at line 185 of file lazy_set.hh.
Referenced by mln::util::lazy_set_< E >::clear(), mln::util::lazy_set_< E >::element(), mln::util::lazy_set_< E >::has(), mln::util::lazy_set_< E >::insert(), mln::util::lazy_set_< E >::nelements(), mln::util::lazy_set_< E >::remove(), mln::util::lazy_set_< E >::set_const_mode(), and mln::util::lazy_set_< E >::update_().
std::vector<E> mln::util::lazy_set_< E >::v_ [mutable, private] |
Array of elements.
This structure is only updated (if required) when elements are accessed.
Definition at line 179 of file lazy_set.hh.
Referenced by mln::util::lazy_set_< E >::clear(), mln::util::lazy_set_< E >::element(), mln::util::lazy_set_< E >::has(), mln::util::lazy_set_< E >::nelements(), mln::util::lazy_set_< E >::set_const_mode(), mln::util::lazy_set_< E >::update_(), and mln::util::lazy_set_< E >::vect().