NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Protected Attributes | Private Member Functions | List of all members
CLinks Class Reference

Search Toolkit Book for CLinks

Set of edges with weights between nodes represented by zero-based positive integers. More...

#include <algo/cobalt/links.hpp>

+ Inheritance diagram for CLinks:
+ Collaboration diagram for CLinks:

Classes

struct  SLink
 Single link. More...
 

Public Types

typedef list< SLink >::const_iterator SLink_CI
 
- Public Types inherited from CObject
enum  EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern }
 Control filling of newly allocated memory. More...
 
typedef CObjectCounterLocker TLockerType
 Default locker type for CRef. More...
 
typedef atomic< Uint8TCounter
 Counter type is CAtomiCounter. More...
 
typedef Uint8 TCount
 Alias for value type of counter. More...
 

Public Member Functions

 CLinks (Uint4 num_elements)
 Constructor. More...
 
 ~CLinks ()
 Destructor. More...
 
void AddLink (int first, int second, double weight)
 Add link. More...
 
bool IsLink (int first, int second) const
 Check if link exists between given two nodes. More...
 
bool IsLink (const vector< int > &first, const vector< int > &second, double &dist) const
 Check if links exist between all pairs of elemens from two sets. More...
 
bool IsSorted (void) const
 Check whether the links are sorted according to weights. More...
 
void Sort (void)
 Sort links according to weights in ascending order. More...
 
Uint4 GetNumElements (void) const
 Get number of nodes. More...
 
Uint4 GetNumLinks (void) const
 Get number of links. More...
 
double GetMaxWeight (void) const
 Get maximum weight over all links. More...
 
SLink_CI begin (void) const
 Get iterator pointing to the first link. More...
 
SLink_CI end (void) const
 Get iterator pointing behind the last link. More...
 
- Public Member Functions inherited from CObject
 CObject (void)
 Constructor. More...
 
 CObject (const CObject &src)
 Copy constructor. More...
 
virtual ~CObject (void)
 Destructor. More...
 
CObjectoperator= (const CObject &src) THROWS_NONE
 Assignment operator. More...
 
bool CanBeDeleted (void) const THROWS_NONE
 Check if object can be deleted. More...
 
bool IsAllocatedInPool (void) const THROWS_NONE
 Check if object is allocated in memory pool (not system heap) More...
 
bool Referenced (void) const THROWS_NONE
 Check if object is referenced. More...
 
bool ReferencedOnlyOnce (void) const THROWS_NONE
 Check if object is referenced only once. More...
 
void AddReference (void) const
 Add reference to object. More...
 
void RemoveReference (void) const
 Remove reference to object. More...
 
void ReleaseReference (void) const
 Remove reference without deleting object. More...
 
virtual void DoNotDeleteThisObject (void)
 Mark this object as not allocated in heap – do not delete this object. More...
 
virtual void DoDeleteThisObject (void)
 Mark this object as allocated in heap – object can be deleted. More...
 
void * operator new (size_t size)
 Define new operator for memory allocation. More...
 
void * operator new[] (size_t size)
 Define new[] operator for 'array' memory allocation. More...
 
void operator delete (void *ptr)
 Define delete operator for memory deallocation. More...
 
void operator delete[] (void *ptr)
 Define delete[] operator for memory deallocation. More...
 
void * operator new (size_t size, void *place)
 Define new operator. More...
 
void operator delete (void *ptr, void *place)
 Define delete operator. More...
 
void * operator new (size_t size, CObjectMemoryPool *place)
 Define new operator using memory pool. More...
 
void operator delete (void *ptr, CObjectMemoryPool *place)
 Define delete operator. More...
 
virtual void DebugDump (CDebugDumpContext ddc, unsigned int depth) const
 Define method for dumping debug information. More...
 
- Public Member Functions inherited from CDebugDumpable
 CDebugDumpable (void)
 
virtual ~CDebugDumpable (void)
 
void DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const
 
void DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const
 
void DumpToConsole (void) const
 

Protected Attributes

list< SLinkm_Links
 Links. More...
 
vector< SLink * > m_LinkPtrs
 Pointers to links in m_Links sorted according to node indexes; used for checks whether a link exists. More...
 
Uint4 m_NumElements
 Number of nodes. More...
 
Uint4 m_NumLinks
 Number of links. More...
 
bool m_IsSorted
 Is list of links sorted. More...
 
double m_MaxWeight
 Maximym weight in the list. More...
 

Private Member Functions

 CLinks (const CLinks &links)
 Forbid copy constructor. More...
 
CLinksoperator= (const CLinks &links)
 Forbid assignment operator. More...
 
void x_InitLinkPtrs (void)
 Initialize secondary list of link pointers. More...
 
bool x_IsLinkPtr (int first, int second) const
 Check if link exists by searching list of link pointers sorted by node indexes. More...
 
const CLinks::SLinkx_GetLink (int first, int second) const
 Get link by node ids. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CObject
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (void)
 Define method to throw null pointer exception. More...
 
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (const type_info &type)
 
static EAllocFillMode GetAllocFillMode (void)
 
static void SetAllocFillMode (EAllocFillMode mode)
 
static void SetAllocFillMode (const string &value)
 Set mode from configuration parameter value. More...
 
- Static Public Member Functions inherited from CDebugDumpable
static void EnableDebugDump (bool on)
 
- Static Public Attributes inherited from CObject
static const TCount eCounterBitsCanBeDeleted = 1 << 0
 Define possible object states. More...
 
static const TCount eCounterBitsInPlainHeap = 1 << 1
 Heap signature was found. More...
 
static const TCount eCounterBitsPlaceMask
 Mask for 'in heap' state flags. More...
 
static const int eCounterStep = 1 << 2
 Skip over the "in heap" bits. More...
 
static const TCount eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2)
 Minimal value for valid objects (reference counter is zero) Must be a single bit value. More...
 
static const TCount eCounterStateMask
 Valid object, and object in heap. More...
 
- Protected Member Functions inherited from CObject
virtual void DeleteThis (void)
 Virtual method "deleting" this object. More...
 

Detailed Description

Set of edges with weights between nodes represented by zero-based positive integers.

Definition at line 52 of file links.hpp.

Member Typedef Documentation

◆ SLink_CI

typedef list<SLink>::const_iterator CLinks::SLink_CI

Definition at line 69 of file links.hpp.

Constructor & Destructor Documentation

◆ CLinks() [1/2]

CLinks::CLinks ( Uint4  num_elements)
inline

Constructor.

Parameters
num_elementsNumber of nodes (not necessary connected) [in] [in] table

Definition at line 77 of file links.hpp.

◆ ~CLinks()

CLinks::~CLinks ( )

Destructor.

Definition at line 57 of file links.cpp.

◆ CLinks() [2/2]

CLinks::CLinks ( const CLinks links)
private

Forbid copy constructor.

Member Function Documentation

◆ AddLink()

void CLinks::AddLink ( int  first,
int  second,
double  weight 
)

Add link.

Parameters
firstNode number [in]
secondNode number [in]
weightLink weight [in]

The links are assumed to be undirected. All nodes are stored such that first < second, if the inputs are different the nodes will be swaped. The method does not check whether given link already exists. Adding two links between the same nodes may cause unexpected results.

Definition at line 60 of file links.cpp.

References first(), m_IsSorted, m_Links, m_MaxWeight, m_NumElements, m_NumLinks, NCBI_THROW, swap(), and weight.

Referenced by BOOST_AUTO_TEST_CASE(), TKmerMethods< TKmerCounts >::ComputeDistLinks(), and CMultiAligner::x_FindQueryClusters().

◆ begin()

SLink_CI CLinks::begin ( void  ) const
inline

Get iterator pointing to the first link.

Returns
Link iterator

Definition at line 144 of file links.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), and CClusterer::ComputeClustersFromLinks().

◆ end()

SLink_CI CLinks::end ( void  ) const
inline

Get iterator pointing behind the last link.

Returns
Link iterator

Definition at line 149 of file links.hpp.

Referenced by CClusterer::ComputeClustersFromLinks().

◆ GetMaxWeight()

double CLinks::GetMaxWeight ( void  ) const
inline

Get maximum weight over all links.

Returns
Maxium weight

Definition at line 139 of file links.hpp.

◆ GetNumElements()

Uint4 CLinks::GetNumElements ( void  ) const
inline

Get number of nodes.

Returns
Number of nodes

Definition at line 129 of file links.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), and CClusterer::ComputeClustersFromLinks().

◆ GetNumLinks()

Uint4 CLinks::GetNumLinks ( void  ) const
inline

Get number of links.

Returns
Number of links

Definition at line 134 of file links.hpp.

◆ IsLink() [1/2]

bool CLinks::IsLink ( const vector< int > &  first,
const vector< int > &  second,
double &  dist 
) const

Check if links exist between all pairs of elemens from two sets.

Existence of links whithin the sets is not checked.

Parameters
firstList of elements for the first set [in]
secondList of elements for the second set [in]
distAverage distance between elements of the two sets [out]
Returns
true if links between all pairs exist, false otherwise

The existance of a link is checked by doing binary search in sorted list of links

Definition at line 99 of file links.cpp.

References ITERATE, m_IsSorted, NCBI_THROW, CLinks::SLink::weight, and x_GetLink().

◆ IsLink() [2/2]

bool CLinks::IsLink ( int  first,
int  second 
) const

Check if link exists between given two nodes.

Parameters
firstNode number [in]
secondNode number [in]
Returns
True if link exists, false otherwise

The link is checked by doing binary search in sorted list of links

Definition at line 81 of file links.cpp.

References first(), m_IsSorted, m_NumElements, NCBI_THROW, swap(), and x_IsLinkPtr().

Referenced by BOOST_AUTO_TEST_CASE(), CClusterer::x_CanAddElem(), and CClusterer::x_CanJoinClusters().

◆ IsSorted()

bool CLinks::IsSorted ( void  ) const
inline

Check whether the links are sorted according to weights.

Returns
True if links are sorted, false otherwise

Definition at line 120 of file links.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), and CClusterer::ComputeClustersFromLinks().

◆ operator=()

CLinks& CLinks::operator= ( const CLinks links)
private

Forbid assignment operator.

◆ Sort()

void CLinks::Sort ( void  )

Sort links according to weights in ascending order.

Definition at line 124 of file links.cpp.

References m_IsSorted, m_Links, and x_InitLinkPtrs().

Referenced by BOOST_AUTO_TEST_CASE(), CClusterer::ComputeClustersFromLinks(), and CMultiAligner::x_FindQueryClusters().

◆ x_GetLink()

const CLinks::SLink * CLinks::x_GetLink ( int  first,
int  second 
) const
private

Get link by node ids.

Parameters
firstFirst node
secondSecond node
Returns
Pointer to the link or NULL if link does not exist

Definition at line 158 of file links.cpp.

References _ASSERT, compare_links_by_nodes(), first(), m_LinkPtrs, NULL, and swap().

Referenced by IsLink().

◆ x_InitLinkPtrs()

void CLinks::x_InitLinkPtrs ( void  )
private

Initialize secondary list of link pointers.

Definition at line 135 of file links.cpp.

References compare_links_by_nodes(), m_LinkPtrs, m_Links, NON_CONST_ITERATE, and ct::sort().

Referenced by Sort().

◆ x_IsLinkPtr()

bool CLinks::x_IsLinkPtr ( int  first,
int  second 
) const
private

Check if link exists by searching list of link pointers sorted by node indexes.

Parameters
firstNode number [in]
secondNode number [in]
Returns
True if link exists, false otherwise

Definition at line 148 of file links.cpp.

References _ASSERT, compare_links_by_nodes(), first(), and m_LinkPtrs.

Referenced by IsLink().

Member Data Documentation

◆ m_IsSorted

bool CLinks::m_IsSorted
protected

Is list of links sorted.

Definition at line 190 of file links.hpp.

Referenced by AddLink(), IsLink(), and Sort().

◆ m_LinkPtrs

vector<SLink*> CLinks::m_LinkPtrs
protected

Pointers to links in m_Links sorted according to node indexes; used for checks whether a link exists.

Definition at line 181 of file links.hpp.

Referenced by x_GetLink(), x_InitLinkPtrs(), and x_IsLinkPtr().

◆ m_Links

list<SLink> CLinks::m_Links
protected

Links.

Definition at line 177 of file links.hpp.

Referenced by AddLink(), Sort(), and x_InitLinkPtrs().

◆ m_MaxWeight

double CLinks::m_MaxWeight
protected

Maximym weight in the list.

Definition at line 193 of file links.hpp.

Referenced by AddLink().

◆ m_NumElements

Uint4 CLinks::m_NumElements
protected

Number of nodes.

Definition at line 184 of file links.hpp.

Referenced by AddLink(), and IsLink().

◆ m_NumLinks

Uint4 CLinks::m_NumLinks
protected

Number of links.

Definition at line 187 of file links.hpp.

Referenced by AddLink().


The documentation for this class was generated from the following files:
Modified on Wed Jul 17 13:20:59 2024 by modify_doxy.py rev. 669887