static void breadth_first_search(const GraphType& graph, 
                                 const VertexIndexType& source,
                                 const int& k_steps,
                                 AssociativeContainer& visited_vertices) {
  /* CHECK: AssociativeContainer::value_type == VertexIndexType */

  std::queue<VertexIndexType> even_epoch_queue;
  std::queue<VertexIndexType> odd_epoch_queue;
  std::queue<VertexIndexType>& current_queue = even_epoch_queue;
  std::queue<VertexIndexType>& next_queue = odd_epoch_queue;

  current_queue.push (source);
  int step_number = 0;
  while (step_number<k_steps) {
    while (!current_queue.empty ()) {
      const int vertex = current_queue.front ();
      current_queue.pop ();
      visited_vertices.insert (vertex);
      for (int target_index=graph.begin(vertex); 
           target_index<graph.end(vertex);
           ++target_index) {
        const int target = graph.get_target (target_index);
        if (visited_vertices.end()==visited_vertices.find (target)) {
          next_queue.push (target);
        }
      }
    }
    ++step_number;
    current_queue = (step_number&0x10)?even_epoch_queue:odd_epoch_queue;
    next_queue = (step_number&0x01)?even_epoch_queue:odd_epoch_queue;
  }
}
Exemplo n.º 2
0
 std::pair<typename AssociativeContainer::iterator, bool>
 push_dispatch(AssociativeContainer& c, const T& v,
               multiple_associative_container_tag)
 {
   return std::make_pair(c.insert(v), true);
 }
Exemplo n.º 3
0
 std::pair<typename AssociativeContainer::iterator, bool>
 push_dispatch(AssociativeContainer& c, const T& v, 
               unique_associative_container_tag)
 {
   return c.insert(v);
 }