Public Types | Public Member Functions | Private Member Functions | Private Attributes

mln::util::lazy_set_< E > Class Template Reference

An "efficient" mathematical set class. More...

#include <lazy_set.hh>

List of all members.

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.

Detailed Description

template<typename E>
class mln::util::lazy_set_< E >

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.

Invariant:
v_.size() == s_.size()

The parameter E is the element type, which shall not be const-qualified.

Todo:
Add a remove method.

Definition at line 66 of file lazy_set.hh.


Member Typedef Documentation

template<typename E>
typedef E mln::util::lazy_set_< E >::value

Type of the stored value.

Definition at line 71 of file lazy_set.hh.


Constructor & Destructor Documentation

template<typename E >
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_.


Member Function Documentation

template<typename E >
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.

Postcondition:
is_empty() == true

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_.

template<typename E >
const E & mln::util::lazy_set_< E >::element ( unsigned  i  )  const [inline]

Return the i-th element of the set.

Parameters:
[in] i Index of the element to retrieve.
Precondition:
i < nelements()

The element is returned by reference and is constant.

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[]().

template<typename E >
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_.

template<typename E >
bool mln::util::lazy_set_< E >::has ( const E &  elt  )  const [inline]

Test if the object elt belongs to the set.

Parameters:
[in] elt A possible element of the set.
Returns:
True is 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_.

template<typename E >
lazy_set_< E > & mln::util::lazy_set_< E >::insert ( const E &  elt  )  [inline]

Insert an element elt into the set.

Parameters:
[in] elt The element to be inserted.

If elt is already in the set, this method is a no-op.

Returns:
The set itself after insertion.

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_.

template<typename E >
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().

template<typename E >
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().

template<typename E >
const E & mln::util::lazy_set_< E >::operator[] ( unsigned  i  )  const [inline]

Return the i-th element of the set.

Parameters:
[in] i Index of the element to retrieve.
Precondition:
i < nelements()

The element is returned by reference and is constant.

Definition at line 253 of file lazy_set.hh.

References mln::util::lazy_set_< E >::element().

template<typename E >
lazy_set_< E > & mln::util::lazy_set_< E >::remove ( const E &  elt  )  [inline]

Remove an element elt into the set.

Parameters:
[in] elt The element to be inserted.

If elt is already in the set, this method is a no-op.

Returns:
The set itself after suppression.

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_.

template<typename E >
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 :

  • const : The lazy set is as light as a vector but you cannot modify it
  • non-const : The lazy set use a std::set to have lazy manipulation
Parameters:
[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_.

template<typename E >
void mln::util::lazy_set_< E >::update_ (  )  const [inline, private]
template<typename E >
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).

Returns:
An array (std::vector) of elements.

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_.


Member Data Documentation

template<typename E>
bool mln::util::lazy_set_< E >::mode_ [private]
template<typename E>
bool mln::util::lazy_set_< E >::needs_update_ [mutable, private]
template<typename E>
std::set<E> mln::util::lazy_set_< E >::s_ [private]
template<typename E>
std::vector<E> mln::util::lazy_set_< E >::v_ [mutable, private]