Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Crystal::DisjointElement Class Reference

DisjointElement : Cluster item used in a disjoint-set data structure. More...

#include <DisjointElement.h>

Public Member Functions

 DisjointElement ()
 Default constructor. More...
 
 DisjointElement (const DisjointElement &other)
 Copy constructor. More...
 
 DisjointElement (const int id)
 Constructor. More...
 
int getId () const
 Get Id. More...
 
DisjointElementgetParent () const
 Get parent element. More...
 
int getRank () const
 Get the current rank. More...
 
int getRoot () const
 Get root id. More...
 
int incrementRank ()
 Increment the rank. More...
 
bool isEmpty () const
 Is empty. More...
 
bool operator< (const DisjointElement &other) const
 Less than. More...
 
DisjointElementoperator= (const DisjointElement &other)
 Assignment operator. More...
 
bool operator> (const DisjointElement &other) const
 Greater than. More...
 
void setId (int id)
 Set the id. More...
 
void unionWith (DisjointElement *other)
 Union with other. More...
 
virtual ~DisjointElement ()=default
 Destructor. More...
 

Private Member Functions

int compress ()
 Compress the tree such that element's parent becomes it's root parent. More...
 
bool hasParent () const
 Determine if this instance really has a parent or whether it is a singleton. More...
 
void setParent (DisjointElement *other)
 Setter for the parent element. More...
 

Private Attributes

int m_id
 Identifier. More...
 
DisjointElementm_parent
 Parent element. More...
 
int m_rank
 Current rank. More...
 

Detailed Description

DisjointElement : Cluster item used in a disjoint-set data structure.

Definition at line 16 of file DisjointElement.h.

Constructor & Destructor Documentation

◆ DisjointElement() [1/3]

Mantid::Crystal::DisjointElement::DisjointElement ( )

Default constructor.

Creates an 'empty' disjoint element.

Definition at line 14 of file DisjointElement.cpp.

◆ DisjointElement() [2/3]

Mantid::Crystal::DisjointElement::DisjointElement ( const int  id)

Constructor.

Parameters
id: Element id

Definition at line 20 of file DisjointElement.cpp.

◆ ~DisjointElement()

virtual Mantid::Crystal::DisjointElement::~DisjointElement ( )
virtualdefault

Destructor.

◆ DisjointElement() [3/3]

Mantid::Crystal::DisjointElement::DisjointElement ( const DisjointElement other)

Copy constructor.

Parameters
other: Other disjoint element to copy.

Definition at line 26 of file DisjointElement.cpp.

References m_parent.

Member Function Documentation

◆ compress()

int Mantid::Crystal::DisjointElement::compress ( )
private

Compress the tree such that element's parent becomes it's root parent.

Note that compression does NOT alter ranks.

Returns
root id of new parent.

Definition at line 67 of file DisjointElement.cpp.

References getParent(), getRoot(), hasParent(), and m_parent.

Referenced by unionWith().

◆ getId()

int Mantid::Crystal::DisjointElement::getId ( ) const

Get Id.

Getter for the id.

Returns
return the numeric id.

Definition at line 53 of file DisjointElement.cpp.

References m_id.

Referenced by Mantid::Crystal::ClusterRegister::merge().

◆ getParent()

DisjointElement * Mantid::Crystal::DisjointElement::getParent ( ) const

Get parent element.

Getter for the parent element.

Returns
pointer to parent element

Definition at line 59 of file DisjointElement.cpp.

References m_parent.

Referenced by compress(), and unionWith().

◆ getRank()

int Mantid::Crystal::DisjointElement::getRank ( ) const

Get the current rank.

Getter for the rank.

Returns
the current rank

Definition at line 110 of file DisjointElement.cpp.

References m_rank.

◆ getRoot()

int Mantid::Crystal::DisjointElement::getRoot ( ) const

Get root id.

Getter for the root id.

Returns
Root element id.

Definition at line 86 of file DisjointElement.cpp.

References getRoot(), m_id, and m_parent.

Referenced by compress(), getRoot(), and Mantid::Crystal::ImplClusterRegister::insert().

◆ hasParent()

bool Mantid::Crystal::DisjointElement::hasParent ( ) const
private

Determine if this instance really has a parent or whether it is a singleton.

Returns
False if singleton, otherwise true.

Definition at line 80 of file DisjointElement.cpp.

References m_parent.

Referenced by compress().

◆ incrementRank()

int Mantid::Crystal::DisjointElement::incrementRank ( )

Increment the rank.

Returns
the new rank.

Definition at line 104 of file DisjointElement.cpp.

References m_rank.

◆ isEmpty()

bool Mantid::Crystal::DisjointElement::isEmpty ( ) const

Is empty.

Determine if the disjoint element is empty.

Empty corresponds to an unassigned element.

Returns
True if empty.

Definition at line 117 of file DisjointElement.cpp.

References m_id.

Referenced by Mantid::Crystal::ClusterRegister::merge().

◆ operator<()

bool Mantid::Crystal::DisjointElement::operator< ( const DisjointElement other) const
inline

Less than.

Definition at line 45 of file DisjointElement.h.

◆ operator=()

DisjointElement & Mantid::Crystal::DisjointElement::operator= ( const DisjointElement other)

Assignment operator.

Parameters
otherElement to assign from
Returns
this

Definition at line 40 of file DisjointElement.cpp.

References m_id, m_parent, and m_rank.

◆ operator>()

bool Mantid::Crystal::DisjointElement::operator> ( const DisjointElement other) const
inline

Greater than.

Definition at line 47 of file DisjointElement.h.

◆ setId()

void Mantid::Crystal::DisjointElement::setId ( int  id)

Set the id.

Set the id for the element.

Parameters
idId to use

Definition at line 160 of file DisjointElement.cpp.

References m_id.

◆ setParent()

void Mantid::Crystal::DisjointElement::setParent ( DisjointElement other)
private

Setter for the parent element.

Parameters
other: New parent

Definition at line 98 of file DisjointElement.cpp.

References m_parent.

◆ unionWith()

void Mantid::Crystal::DisjointElement::unionWith ( DisjointElement other)

Union with other.

Union disjoint sets.

Union happens w.r.t the parent of on or the other sets. Early exit if both have the same root node already. Generally, the set with the highest rank becomes the parent. If ranks are equal, then one is chosen to be the parent, and that's sets rank is incremented.

Parameters
other

Definition at line 127 of file DisjointElement.cpp.

References compress(), getParent(), Mantid::Geometry::x, and Mantid::Geometry::y.

Referenced by Mantid::Crystal::unionElements().

Member Data Documentation

◆ m_id

int Mantid::Crystal::DisjointElement::m_id
private

Identifier.

Definition at line 60 of file DisjointElement.h.

Referenced by getId(), getRoot(), isEmpty(), operator=(), and setId().

◆ m_parent

DisjointElement* Mantid::Crystal::DisjointElement::m_parent
private

Parent element.

Definition at line 56 of file DisjointElement.h.

Referenced by compress(), DisjointElement(), getParent(), getRoot(), hasParent(), operator=(), and setParent().

◆ m_rank

int Mantid::Crystal::DisjointElement::m_rank
private

Current rank.

Definition at line 58 of file DisjointElement.h.

Referenced by getRank(), incrementRank(), and operator=().


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