npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
NMCombinationSequencer.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_NMCOMBINATIONSEQUENCER_HH_
2 #define NPSTAT_NMCOMBINATIONSEQUENCER_HH_
3 
4 /*!
5 // \file NMCombinationSequencer.hh
6 //
7 // \brief Iteration over M distinct indices with N possible values
8 //
9 // Author: I. Volobouev
10 //
11 // June 2011
12 */
13 
14 #include <vector>
15 
16 namespace npstat {
17  /**
18  // This class iterates over all possible choices of j1, .., jm from
19  // N possible values for each jk in such a way that all j1, .., jm
20  // are distinct and appear in the sequence in the increasing order,
21  // last index changing most often.
22  //
23  // For the case m = 2 (two-dimensional), this is like going over the
24  // indices of the part of a square N x N matrix which is above the
25  // diagonal. In general, the total number of permutations equals
26  // the binomial coefficient C(N, M).
27  */
29  {
30  public:
31  /**
32  // M is the number of indices and N is the number
33  // of possible values for each index (from 0 to N-1)
34  */
35  NMCombinationSequencer(unsigned M, unsigned N);
36 
37  //@{
38  /** Examine object properties */
39  inline unsigned M() const {return m_;}
40  inline unsigned N() const {return n_;}
41  //@}
42 
43  /** Prefix increment */
45 
46  /** Postfix increment (distinguished by the dummy "int" parameter) */
47  void operator++(int);
48 
49  /** Reset the sequencer */
50  void reset();
51 
52  /** Retrieve the current combination of indices */
53  inline const unsigned* combination() const {return &coeffs_[0];}
54 
55  /** Linear iteration number */
56  inline unsigned long count() const {return count_;}
57 
58  /**
59  // This method returns "false" upon cycling over
60  // the complete sequence of all possible choices
61  */
62  inline bool isValid() const {return valid_;}
63 
64  private:
66 
67  void increment();
68 
69  std::vector<unsigned> coeffs_;
70  unsigned long count_;
71  unsigned m_;
72  unsigned n_;
73  bool valid_;
74  };
75 }
76 
77 #endif // NPSTAT_NMCOMBINATIONSEQUENCER_HH_
Definition: NMCombinationSequencer.hh:29
unsigned long count() const
Definition: NMCombinationSequencer.hh:56
bool isValid() const
Definition: NMCombinationSequencer.hh:62
NMCombinationSequencer(unsigned M, unsigned N)
const unsigned * combination() const
Definition: NMCombinationSequencer.hh:53
unsigned M() const
Definition: NMCombinationSequencer.hh:39
NMCombinationSequencer & operator++()
Definition: AbsArrayProjector.hh:14