1 | class DistFunc; |
---|
2 | |
---|
3 | class ClusterNode |
---|
4 | { |
---|
5 | friend class ClusterTree; |
---|
6 | public: |
---|
7 | ClusterNode() |
---|
8 | { |
---|
9 | m_dWeight = 0.0; |
---|
10 | m_dWeight2 = 0.0; |
---|
11 | m_ptrLeft = 0; |
---|
12 | m_ptrRight = 0; |
---|
13 | m_ptrParent = 0; |
---|
14 | m_uIndex = 0; |
---|
15 | m_ptrPrevDisjoint = 0; |
---|
16 | m_ptrNextDisjoint = 0; |
---|
17 | } |
---|
18 | ~ClusterNode() {} |
---|
19 | |
---|
20 | public: |
---|
21 | unsigned GetIndex() const { return m_uIndex; } |
---|
22 | ClusterNode *GetLeft() const { return m_ptrLeft; } |
---|
23 | ClusterNode *GetRight() const { return m_ptrRight; } |
---|
24 | ClusterNode *GetParent() const { return m_ptrParent; } |
---|
25 | double GetWeight() const { return m_dWeight; } |
---|
26 | |
---|
27 | const ClusterNode *GetClusterLeaf(unsigned uLeafIndex) const; |
---|
28 | unsigned GetClusterSize() const; |
---|
29 | double GetClusterWeight() const; |
---|
30 | double GetLeftBranchWeight() const; |
---|
31 | double GetRightBranchWeight() const; |
---|
32 | double GetLeftWeight() const; |
---|
33 | double GetRightWeight() const; |
---|
34 | |
---|
35 | void LogMe() const; |
---|
36 | |
---|
37 | double GetWeight2() const { return m_dWeight2; } |
---|
38 | void SetWeight2(double dWeight2) { m_dWeight2 = dWeight2; } |
---|
39 | |
---|
40 | protected: |
---|
41 | void SetIndex(unsigned uIndex) { m_uIndex = uIndex; } |
---|
42 | void SetWeight(double dWeight) { m_dWeight = dWeight; } |
---|
43 | void SetLeft(ClusterNode *ptrLeft) { m_ptrLeft = ptrLeft; } |
---|
44 | void SetRight(ClusterNode *ptrRight) { m_ptrRight = ptrRight; } |
---|
45 | void SetParent(ClusterNode *ptrParent) { m_ptrParent = ptrParent; } |
---|
46 | void SetNextDisjoint(ClusterNode *ptrNode) { m_ptrNextDisjoint = ptrNode; } |
---|
47 | void SetPrevDisjoint(ClusterNode *ptrNode) { m_ptrPrevDisjoint = ptrNode; } |
---|
48 | |
---|
49 | ClusterNode *GetNextDisjoint() { return m_ptrNextDisjoint; } |
---|
50 | ClusterNode *GetPrevDisjoint() { return m_ptrPrevDisjoint; } |
---|
51 | |
---|
52 | private: |
---|
53 | double m_dWeight; |
---|
54 | double m_dWeight2; |
---|
55 | unsigned m_uIndex; |
---|
56 | ClusterNode *m_ptrLeft; |
---|
57 | ClusterNode *m_ptrRight; |
---|
58 | ClusterNode *m_ptrParent; |
---|
59 | ClusterNode *m_ptrNextDisjoint; |
---|
60 | ClusterNode *m_ptrPrevDisjoint; |
---|
61 | }; |
---|
62 | |
---|
63 | class ClusterTree |
---|
64 | { |
---|
65 | public: |
---|
66 | ClusterTree(); |
---|
67 | virtual ~ClusterTree(); |
---|
68 | |
---|
69 | void Create(const DistFunc &DF); |
---|
70 | |
---|
71 | ClusterNode *GetRoot() const; |
---|
72 | void LogMe() const; |
---|
73 | |
---|
74 | protected: |
---|
75 | void Join(ClusterNode *ptrNode1, ClusterNode *ptrNode2, |
---|
76 | ClusterNode *ptrJoin); |
---|
77 | void AddToDisjoints(ClusterNode *ptrNode); |
---|
78 | void DeleteFromDisjoints(ClusterNode *ptrNode); |
---|
79 | void Validate(unsigned uNodeCount); |
---|
80 | |
---|
81 | private: |
---|
82 | ClusterNode *m_ptrDisjoints; |
---|
83 | ClusterNode *m_Nodes; |
---|
84 | unsigned m_uNodeCount; |
---|
85 | unsigned m_uLeafCount; |
---|
86 | }; |
---|