
#ifndef PLS_DATAFLOW_INTERNAL_TOKEN_H_
#define PLS_DATAFLOW_INTERNAL_TOKEN_H_

namespace pls {
namespace dataflow {
namespace internal {

/**
 * Parallel invocations of the same sub-graph are usually working with some kind of coloring
 * for tokens to distinguishe different invocations. As this concept is abstract and we could
 * change it in the future (for e.g. more advanced features/dataflows) we encapsulate it.
 */
struct token_color {
  unsigned int clock_;
  unsigned int depth_;

  int get_index(int parallel_limit) const {
    return clock_ % parallel_limit;
  }

  bool operator==(const token_color &other) {
    return other.clock_ == clock_ && other.depth_ == depth_;
  }
};

template<typename T>
class token {
  T value_;
  token_color color_;

 public:
  token() : color_{} {}; // Default Constructor Stays uninitialized
  token(T value, token_color color) : value_{value}, color_{color} {};

  T value() const { return value_; }
  token_color color() const { return color_; }
};

}
}
}

#endif //PLS_DATAFLOW_INTERNAL_TOKEN_H_
