Lines Matching full:vertex
46 // A weighted undirected graph templated over the vertex ids. Vertex
48 template <typename Vertex>
53 // Add a weighted vertex. If the vertex already exists in the graph,
55 void AddVertex(const Vertex& vertex, double weight) {
56 if (vertices_.find(vertex) == vertices_.end()) {
57 vertices_.insert(vertex);
58 edges_[vertex] = HashSet<Vertex>();
60 vertex_weights_[vertex] = weight;
63 // Uses weight = 1.0. If vertex already exists, its weight is set to
65 void AddVertex(const Vertex& vertex) {
66 AddVertex(vertex, 1.0);
69 bool RemoveVertex(const Vertex& vertex) {
70 if (vertices_.find(vertex) == vertices_.end()) {
74 vertices_.erase(vertex);
75 vertex_weights_.erase(vertex);
76 const HashSet<Vertex>& sinks = edges_[vertex];
77 for (typename HashSet<Vertex>::const_iterator it = sinks.begin();
79 if (vertex < *it) {
80 edge_weights_.erase(make_pair(vertex, *it));
82 edge_weights_.erase(make_pair(*it, vertex));
84 edges_[*it].erase(vertex);
87 edges_.erase(vertex);
97 void AddEdge(const Vertex& vertex1, const Vertex& vertex2, double weight) {
113 void AddEdge(const Vertex& vertex1, const Vertex& vertex2) {
117 // Calling VertexWeight on a vertex not in the graph will result in
119 double VertexWeight(const Vertex& vertex) const {
120 return FindOrDie(vertex_weights_, vertex);
127 double EdgeWeight(const Vertex& vertex1, const Vertex& vertex2) const {
135 // Calling Neighbors on a vertex not in the graph will result in
137 const HashSet<Vertex>& Neighbors(const Vertex& vertex) const {
138 return FindOrDie(edges_, vertex);
141 const HashSet<Vertex>& vertices() const {
150 HashSet<Vertex> vertices_;
151 HashMap<Vertex, double> vertex_weights_;
152 HashMap<Vertex, HashSet<Vertex> > edges_;
153 HashMap<pair<Vertex, Vertex>, double> edge_weights_;