Program Listing for File combination.hpp

Return to documentation for file (include/bitbots_splines/combination.hpp)

/*
This code is largely based on the original code by Quentin "Leph" Rouxel and Team Rhoban.
The original files can be found at:
https://github.com/Rhoban/model/
*/
#ifndef BITBOTS_SPLINES_INCLUDE_BITBOTS_SPLINES_COMBINATION_H_
#define BITBOTS_SPLINES_INCLUDE_BITBOTS_SPLINES_COMBINATION_H_

#include <stddef.h>

#include <map>
#include <vector>

namespace bitbots_splines {

class Combination {
 public:
  unsigned long binomialCoefficient(size_t k, size_t n);

  void startCombination(size_t k, size_t n);

  std::vector<size_t> nextCombination();

 private:
  typedef std::pair<unsigned long, unsigned long> Pair;
  typedef std::vector<size_t> Comb;

  std::map<Pair, unsigned long> pascal_triangle_;

  std::vector<size_t> indexes_;
  size_t n_ = 0;
  size_t k_ = 0;

  bool incrIndexes(size_t i);
};

}  // namespace bitbots_splines

#endif