cpp/include/raft/common/detail/nvtx.hpp
inline auto generate_next_color(const std::string& tag) -> uint32_t
{
  // std::unordered_map<std::string, uint32_t> color_gen_state::all_colors_;
  // std::mutex color_gen_state::map_mutex_;

  std::lock_guard<std::mutex> guard(color_gen_state::map_mutex_);
  if (!tag.empty()) {
    auto itr = color_gen_state::all_colors_.find(tag);
    if (itr != color_gen_state::all_colors_.end()) { return itr->second; }
  }
  auto h = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
  h += color_gen_state::kInvPhi;
  if (h >= 1.f) h -= 1.f;
  auto rgb = hsv2rgb(h, color_gen_state::kS, color_gen_state::kV);
  if (!tag.empty()) { color_gen_state::all_colors_[tag] = rgb; }
  return rgb;
}
/**
 * @brief Helper method to generate 'visually distinct' colors.
 * Inspired from https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
 * However, if an associated tag is passed, it will look up in its history for
 * any generated color against this tag and if found, just returns it, else
 * generates a new color, assigns a tag to it and stores it for future usage.
 * Such a thing is very useful for nvtx markers where the ranges associated
 * with a specific tag should ideally get the same color for the purpose of
 * visualizing it on nsight-systems timeline.
 * @param tag look for any previously generated colors with this tag or
 * associate the currently generated color with it
 * @return returns 32b RGB integer with alpha channel set of 0xff
 */
@brief Helper method to generate 'visually distinct' colors.
@brief Helper method to generate ' visually distinct ' colors .
inline auto generate_next_color(const std::string& tag) -> uint32_t
{
  std::lock_guard<std::mutex> guard(color_gen_state::map_mutex_);
  if (!tag.empty()) {
    auto itr = color_gen_state::all_colors_.find(tag);
    if (itr != color_gen_state::all_colors_.end()) { return itr->second; }
  }
  auto h = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
  h += color_gen_state::kInvPhi;
  if (h >= 1.f) h -= 1.f;
  auto rgb = hsv2rgb(h, color_gen_state::kS, color_gen_state::kV);
  if (!tag.empty()) { color_gen_state::all_colors_[tag] = rgb; }
  return rgb;
}
inline auto generate_next_color ( const std :: string & tag ) -> uint32_t { std :: lock_guard < std :: mutex > guard ( color_gen_state :: map_mutex_ ) ; if ( ! tag . empty ( ) ) { auto itr = color_gen_state :: all_colors_ . find ( tag ) ; if ( itr != color_gen_state :: all_colors_ . end ( ) ) { return itr -> second ; } } auto h = static_cast < float > ( rand ( ) ) / static_cast < float > ( RAND_MAX ) ; h += color_gen_state :: kInvPhi ; if ( h >= 1.f ) h -= 1.f ; auto rgb = hsv2rgb ( h , color_gen_state :: kS , color_gen_state :: kV ) ; if ( ! tag . empty ( ) ) { color_gen_state :: all_colors_ [ tag ] = rgb ; } return rgb ; }
@brief Helper method to generate 'visually distinct' colors.
@brief Helper method to generate ' visually distinct ' colors .
// std::unordered_map<std::string, uint32_t> color_gen_state::all_colors_; // std::mutex color_gen_state::map_mutex_;