dlr::computerVision::privateCode::DisjointSet< Type > Class Template Reference

This class implements one tree in the "forest of disjoint sets" data structure first described by Bernard Galler and Michael Fischer[1]. More...

#include <disjointSet.h>

Collaboration diagram for dlr::computerVision::privateCode::DisjointSet< Type >:
[legend]

List of all members.

Public Member Functions

 DisjointSet ()
 The default creates a leaf in a disjoint set tree.
 DisjointSet (const Type &payload)
 This constructor allows you to explicitly set the payload values.
virtual ~DisjointSet ()
 Destructor.
DisjointSetfind ()
 This member function returns a reference to the head of the set to which *this belongs.
void merge (DisjointSet &other)
 This member function merges two sets.
const Type & getPayload () const
size_t getSize ()
 This member function returns the number of member in the set of which *this is a member.
void setPayload (const Type &payload)

Protected Attributes

DisjointSetm_parentPtr
size_t m_rank
size_t m_size
Type m_payload


Detailed Description

template<class Type>
class dlr::computerVision::privateCode::DisjointSet< Type >

This class implements one tree in the "forest of disjoint sets" data structure first described by Bernard Galler and Michael Fischer[1].

This implementation includes union by rank and path compression, yielding "nearly" constant time amortized complexity for find/merge operations.

Our implementation includes a size member that allows the calling context to easily see how many members belong to the set. This adds a small constant to the execution time of the merge() operation.

To make a forest of disjoint sets, you'll need to put a bunch of DisjointSet instances in some kind of container, such as an Array1D instance (dlr::numeric::Array1D<DisjointSet>). Unfortunately, most of the C++ standard library con, such as std::vector, use the copy constructor to fill in the array, which breaks the parent pointers. So don't use a std::vector (or std::list, or...).

An Improved Equivalence Algorithm. Galler, Bernard, and Fischer, Michael. Communnications of the ACM, Volume 7, pages 301-303, 1964.

Definition at line 55 of file disjointSet.h.


Constructor & Destructor Documentation

template<class Type >
dlr::computerVision::privateCode::DisjointSet< Type >::DisjointSet (  )  [inline]

The default creates a leaf in a disjoint set tree.

Definition at line 61 of file disjointSet.h.

template<class Type >
dlr::computerVision::privateCode::DisjointSet< Type >::DisjointSet ( const Type &  payload  )  [inline]

This constructor allows you to explicitly set the payload values.

Parameters:
payload This argument will be copied into the payload, and then ignored until you call this->getPayload().

Definition at line 77 of file disjointSet.h.

template<class Type >
virtual dlr::computerVision::privateCode::DisjointSet< Type >::~DisjointSet (  )  [inline, virtual]

Destructor.

Definition at line 85 of file disjointSet.h.


Member Function Documentation

template<class Type >
DisjointSet& dlr::computerVision::privateCode::DisjointSet< Type >::find (  )  [inline]

This member function returns a reference to the head of the set to which *this belongs.

Although which member of a set gets to be "head" is a little arbitrary, all members of the set will report the same head (until the set is merged with another set, when the head may change). This implementation does not use recursion, and may be faster...

Returns:
The return value is the head of the set.

Definition at line 122 of file disjointSet.h.

References dlr::computerVision::privateCode::DisjointSet< Type >::m_parentPtr.

Referenced by dlr::computerVision::privateCode::DisjointSet< Type >::getSize(), and dlr::computerVision::privateCode::DisjointSet< Type >::merge().

template<class Type >
size_t dlr::computerVision::privateCode::DisjointSet< Type >::getSize (  )  [inline]

This member function returns the number of member in the set of which *this is a member.

Returns:
The return value is a count of the number of members in the set.

Definition at line 212 of file disjointSet.h.

References dlr::computerVision::privateCode::DisjointSet< Type >::find().

template<class Type >
void dlr::computerVision::privateCode::DisjointSet< Type >::merge ( DisjointSet< Type > &  other  )  [inline]

This member function merges two sets.

It doesn't matter whether you call x.merge(y), or y.merge(x); both will get the job done. After merging, all members of both sets will report the same head, which will be the head reported one of the two sets before merging. The head reported by the other of the two sets before merging will stop being a head.

Parameters:
other This argument is the set with which to merge.

Definition at line 180 of file disjointSet.h.

References dlr::computerVision::privateCode::DisjointSet< Type >::find(), dlr::computerVision::privateCode::DisjointSet< Type >::m_parentPtr, dlr::computerVision::privateCode::DisjointSet< Type >::m_rank, and dlr::computerVision::privateCode::DisjointSet< Type >::m_size.


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

Generated on Wed Nov 25 12:15:10 2009 for dlrComputerVision Utility Library by  doxygen 1.5.8