An "efficient" mathematical set class. More...
#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. |
An "efficient" mathematical set class.
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.
The parameter E
is the element type, which shall not be const-qualified.
typedef E mln::util::lazy_set_< E >::value |
Type of the stored value.
mln::util::lazy_set_< E >::lazy_set_ | ( | ) | [inline] |
Constructor without arguments.
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.
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. |
The element is returned by reference and is constant.
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.
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. 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. |
If elt
is already in the set, this method is a no-op.
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.
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.
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. |
The element is returned by reference and is constant.
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. |
If elt
is already in the set, this method is a no-op.
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. |
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..
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).
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.
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.
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.
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.
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().