/**
  * Returns the data of vertex with vid. Return NULL if there is no vertex 
  * data associated with vid in this shard.
  */
 inline graph_row* vertex_data_by_id (const graph_vid_t& vid) {
   if (has_vertex(vid)) {
     return vertex_data(shard_impl.vertex_index.get_index(vid));
   } else {
     return NULL;
   }
 }
Пример #2
0
void graph::add_edge(const std::string& v1, const std::string& v2, double c, bool r)
{
    if (!has_vertex(v1)) {
        add_vertex(v1);
    }
    if (!has_vertex(v2)) {
        add_vertex(v2);
    }
    unsigned i1 = get_index(v1);
    unsigned i2 = get_index(v2);
    if (i2 < i1) {
        std::swap(i1, i2);
    }
    m_adjacent_vertices[i1].push_back(i2);
    m_adjacent_vertices[i2].push_back(i1);
    m_edges[std::make_pair(i1, i2)] = std::make_pair(c, r);
}
Пример #3
0
void graph::add_vertex(const std::string& v)
{
    assert(!has_vertex(v));
    unsigned i = m_names.size();
    assert(i == m_indices.size());
    m_names.push_back(v);
    m_indices[v] = i;
    m_adjacent_vertices.push_back(std::vector<unsigned>());
}
std::list<Edge> Graph::get_edges_to(Vertex vertex) {
  // Create the predicate functor, todo make efficient.
  struct has_vertex {
    Vertex& vertex;
    has_vertex(Vertex& vertex) : vertex(vertex) {}
    bool operator()(const Edge& edge) {
      return edge.dest != vertex.uid;
    }
  };
  // Retrieve the edges.
  std::list<Edge> edges = get_edges();
  // Remove the components of the edge we don't.
  edges.remove_if(has_vertex(vertex));
  // Rteturn the edge.
  return edges;
}
     // Update the index by adding a vertex
     inline bool add_vertex(graph_vid_t vid, graph_row* value, size_t pos) {
       if (has_vertex(vid)) {
         return false;
       }

       // Add vertex to primary index
       index_map[vid] = pos;

       // Add vertex to all existing index
       // typedef boost::unordered_map<std::string, size_t>::iterator indexiterator;
       // indexiterator iter;
       // while (iter != field_name_map.end()) {
       //   graph_int_t key = -1;
       //   if (value->get_field(iter->first.c_str())->get_integer(&key)) {
       //     (int_key_map[iter->second])[key] = vid;
       //   }
       //   iter++;
       // } 
       return true;
     }