CMergeBookKeeper.h
Go to the documentation of this file.
1 /**
2  * \file CMergeBookKeeper.h
3  *
4  * \ingroup CMTool
5  *
6  * \brief Class def header for a class CMergeBookKeeper
7  *
8  * @author kazuhiro
9  */
10 
11 /** \addtogroup CMTool
12 
13  @{*/
14 #ifndef RECOTOOL_CMERGEBOOKKEEPER_H
15 #define RECOTOOL_CMERGEBOOKKEEPER_H
16 
17 #include <vector>
18 
19 namespace cmtool {
20 
21  /**
22  \class CMergeBookKeeper
23  A utility class for CMergeManager which merge clusters using merging algorithms.
24  One of major task for CMergeManager is to keep track of which clusters to be merged
25  in the original input. CMergeBookKeeper handles this part. It works with indexes. The user
26  (primarily CMergeManager) provides number of clusters to CMergeBookKeeper's constructor.
27  Then it can ask CMergeBookKeeper to merge two specific clusters by specifying index number
28  of the cluster which has to be smaller than the previously specified number of clusters.
29  CMergeBookKeeper keeps track of which clusters are asked to merge together, and it can be
30  asked to return a vector of merged cluster indexes.
31  */
32  class CMergeBookKeeper : public std::vector<unsigned short>{
33 
34  public:
35 
36  /// Default constructor
37  CMergeBookKeeper(unsigned short nclusters=0);
38 
39  /// Reset method
40  void Reset(unsigned short nclusters=0);
41 
42  /// Method to set a pair of clusters to prohibit from merging
43  void ProhibitMerge(unsigned short index1, unsigned short index2);
44 
45  /// Method to inqury if a combination is prohibited to merge
46  bool MergeAllowed(unsigned short index1, unsigned short index2);
47 
48  /// Method to merge 2 clusters via index numbers
49  void Merge(unsigned short index1, unsigned short index2);
50 
51  /**
52  Method to retrieve a vector of cluster indexes which
53  is merged with the input cluster index. All indexes here
54  are regarding the original cluster index.
55  */
56  std::vector<unsigned short> GetMergedSet(unsigned short index1) const;
57 
58  /**
59  Method to ask if a given 2 clusters are already merged.
60  This method is expected to be much faster than obtaining
61  a merged cluster sets from GetMergedIndexes and check if
62  two clusters are merged.
63  */
64  bool IsMerged(unsigned short index1, unsigned short index2) const;
65 
66  /**
67  A method to get the full result. The return is a vector
68  of merged cluster indexes (which is a vector of original cluster indexes).
69  */
70  void PassResult(std::vector<std::vector<unsigned short> > &result) const;
71 
72 
73  std::vector<std::vector<unsigned short> > GetResult() const
74  {
75  std::vector<std::vector<unsigned short> > result;
76  PassResult(result);
77  return result;
78  }
79 
80  /**
81  Method to combine with another CMergeBookKeeper instance.
82  */
83 
84  void Combine(const CMergeBookKeeper &another);
85 
86  void Report() const;
87 
88  protected:
89 
90  /**
91  A 2D-map vector that stores pair of clusters for which merging is prohibited
92  */
93  std::vector<std::vector<bool> > _prohibit_merge;
94 
95  /// Number of output clusters
97 
98  };
99 
100 }
101 
102 #endif
103 /** @} */ // end of doxygen group
static QCString result
void ProhibitMerge(unsigned short index1, unsigned short index2)
Method to set a pair of clusters to prohibit from merging.
std::vector< std::vector< unsigned short > > GetResult() const
struct vector vector
std::vector< unsigned short > GetMergedSet(unsigned short index1) const
CMergeBookKeeper(unsigned short nclusters=0)
Default constructor.
size_t _out_cluster_count
Number of output clusters.
std::vector< std::vector< bool > > _prohibit_merge
void Combine(const CMergeBookKeeper &another)
void Merge(unsigned short index1, unsigned short index2)
Method to merge 2 clusters via index numbers.
bool MergeAllowed(unsigned short index1, unsigned short index2)
Method to inqury if a combination is prohibited to merge.
void PassResult(std::vector< std::vector< unsigned short > > &result) const
bool IsMerged(unsigned short index1, unsigned short index2) const
void Reset(unsigned short nclusters=0)
Reset method.