Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

mln::internal::set_of_< E > Class Template Reference

#include <set_of.hh>

List of all members.

Public Member Functions

void clear ()
 Make the set empty.
const E & element (unsigned i) const
 Return the i-th element of the set.
bool has (const E &elt) const
 Test if the object elt belongs to the set.
set_of_< E > & insert (const E &elt)
 Insert an element elt into the set.
bool is_empty () const
 Test if the set is empty.
unsigned nelements () const
 Return the number of elements of the set.
set_of_< E > & remove (const E &elt)
 Remove an element elt into the set.
const std::vector< E > & vect () const
 Give access to the set elements.

Protected Member Functions

 set_of_ ()
 Constructor without arguments.

Protected Attributes

std::set< E > s_
 Set of elements.

Private Member Functions

void update_ () const
 Update v_ from s_.

Private Attributes

bool needs_update_
 Tell if v_ needs to be updated.
std::vector< E > v_
 Array of elements.

Detailed Description

template<typename E>
class mln::internal::set_of_< 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 59 of file set_of.hh.


Constructor & Destructor Documentation

template<typename E>
set_of_ (  )  [inline, protected]

Constructor without arguments.

Print a set s into the output stream ostr.

Parameters:
[in,out] ostr An output stream.
[in] s A set.
Returns:
The modified output stream ostr.

Definition at line 187 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_.


Member Function Documentation

template<typename E >
void mln::internal::set_of_< E >::clear (  )  [inline]

Make the set empty.

All elements contained in the set are destroyed so the set is emptied.

Postcondition:
is_empty() == true

Definition at line 254 of file set_of.hh.

References mln::internal::set_of_< E >::is_empty(), mln::internal::set_of_< E >::needs_update_, mln::internal::set_of_< E >::s_, and mln::internal::set_of_< E >::v_.

template<typename E >
const E & mln::internal::set_of_< 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 217 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_, mln::internal::set_of_< E >::update_(), and mln::internal::set_of_< E >::v_.

template<typename E >
bool mln::internal::set_of_< 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 238 of file set_of.hh.

References mln::internal::set_of_< E >::s_.

template<typename E >
set_of_< E > & mln::internal::set_of_< 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 195 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_, and mln::internal::set_of_< E >::s_.

template<typename E >
bool mln::internal::set_of_< E >::is_empty (  )  const [inline]

Test if the set is empty.

Definition at line 246 of file set_of.hh.

References mln::internal::set_of_< E >::nelements().

Referenced by mln::internal::set_of_< E >::clear().

template<typename E >
unsigned mln::internal::set_of_< E >::nelements (  )  const [inline]

Return the number of elements of the set.

Definition at line 228 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_, mln::internal::set_of_< E >::update_(), and mln::internal::set_of_< E >::v_.

Referenced by mln::internal::set_of_< E >::is_empty().

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

Remove an element elt into the set.

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

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

Returns:
The set itself after suppression.

Definition at line 206 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_, and mln::internal::set_of_< E >::s_.

template<typename E >
void mln::internal::set_of_< E >::update_ (  )  const [inline, private]
template<typename E >
const std::vector< E > & mln::internal::set_of_< 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 265 of file set_of.hh.

References mln::internal::set_of_< E >::needs_update_, mln::internal::set_of_< E >::update_(), and mln::internal::set_of_< E >::v_.


Member Data Documentation

template<typename E>
bool mln::internal::set_of_< E >::needs_update_ [mutable, private]
template<typename E>
std::set<E> mln::internal::set_of_< E >::s_ [protected]

Set of elements.

This structure is always up-to-date w.r.t. the set contents.

Definition at line 153 of file set_of.hh.

Referenced by mln::internal::set_of_< E >::clear(), mln::internal::set_of_< E >::has(), mln::internal::set_of_< E >::insert(), mln::internal::set_of_< E >::remove(), and mln::internal::set_of_< E >::update_().

template<typename E>
std::vector<E> mln::internal::set_of_< E >::v_ [mutable, private]

Array of elements.

This structure is only updated (if required) when elements are accessed.

Definition at line 146 of file set_of.hh.

Referenced by mln::internal::set_of_< E >::clear(), mln::internal::set_of_< E >::element(), mln::internal::set_of_< E >::nelements(), mln::internal::set_of_< E >::update_(), and mln::internal::set_of_< E >::vect().