Muster
 All Classes Namespaces Files Functions Variables Typedefs Macros
binomial.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <vector>
3 #include <iostream>
4 #include "binomial.h"
5 using namespace std;
6 
7 namespace cluster {
8 
9  binomial_embedding::binomial_embedding(int size, int root)
10  : _size(size), _root(root) { }
11 
12  /// This permutes ranks in case the root is not zero
13  int binomial_embedding::relative_rank(int rank) const {
14  return (rank - _root + _size) % _size;
15  }
16 
18  return (rank + _root) % _size;
19  }
20 
21  vector<int> binomial_embedding::children(int rank) const {
22  vector<int> childvec;
23  get_children(rank, back_inserter(childvec));
24  return childvec;
25  }
26 
27  int binomial_embedding::parent(int rank) const {
28  int relrank = relative_rank(rank);
29  for (int mask = 0x1; mask < _size; mask <<= 1) {
30  if ((mask & relrank) != 0) {
31  return ((relrank & (~ mask)) + _root) % _size;
32  }
33  }
34  return -1;
35  }
36 
37 } // namespace cluster
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