Muster
 All Classes Namespaces Files Functions Variables Typedefs Macros
binomial.h
Go to the documentation of this file.
1 #ifndef MUSTER_BINOMIAL_H
2 #define MUSTER_BINOMIAL_H
3 
4 #include <cstdlib>
5 #include <vector>
6 
7 namespace cluster {
8 
10  private:
11  const int _size;
12  const int _root;
13 
14  public:
15  /// Construct a binomial rank embedding with size nodes, rooted at root.
16  binomial_embedding(int size, int root = 0);
17 
18  int relative_rank(int rank) const; ///< This permutes ranks in case the root is not zero
19  int reverse_relative_rank(int rank) const; ///< Reverse rank permutation
20  std::vector<int> children(int rank) const; ///< Same as get_children, but returns vector.
21  int parent(int rank) const; ///< Get the parent of a particular rank.
22 
23  int size() const { return _size; }
24  int root() const { return _root; }
25 
26  /// This allows you to putting children into any structure that supports output iterators
27  template <class OutputIterator>
28  void get_children(int rank, OutputIterator o) const {
29  int relrank = relative_rank(rank);
30  for (int mask = 0x1; mask < _size; mask <<= 1) {
31  if ((mask & relrank) != 0) {
32  break;
33  }
34 
35  int child = (relrank | mask);
36  if (child < _size) {
37  *o++ = (child + _root) % _size;
38  }
39  }
40  }
41  };
42 
43 } // namespace cluster
44 
45 #endif // MUSTER_BINOMIAL_H
46 
binomial_embedding(int size, int root=0)
Construct a binomial rank embedding with size nodes, rooted at root.
Definition: binomial.cpp:9
int reverse_relative_rank(int rank) const
Reverse rank permutation.
Definition: binomial.cpp:17
std::vector< int > children(int rank) const
Same as get_children, but returns vector.
Definition: binomial.cpp:21
int parent(int rank) const
Get the parent of a particular rank.
Definition: binomial.cpp:27
int relative_rank(int rank) const
This permutes ranks in case the root is not zero.
Definition: binomial.cpp:13
void get_children(int rank, OutputIterator o) const
This allows you to putting children into any structure that supports output iterators.
Definition: binomial.h:28
Muster. Copyright © 2010, Lawrence Livermore National Laboratory, LLNL-CODE-433662.
Distribution of Muster and its documentation is subject to terms of the Muster LICENSE.
Generated on Thu Sep 1 2016 using Doxygen 1.8.5