代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package graph
// Vertex defines a vertex of a graph
type Vertex struct {
Id string
Data interface{}
neighbors map[string]*Vertex
}
// NewVertex creates a new vertex with given id and data
func NewVertex(id string, data interface{}) *Vertex {
return &Vertex{
Id: id,
Data: data,
neighbors: make(map[string]*Vertex),
}
}
// NeighborById returns a neighbor vertex with the given id,
// or nil if no vertex with such an id is a neighbor
func (v *Vertex) NeighborById(id string) *Vertex {
return v.neighbors[id]
}
// Neighbors returns the neighbors of the vertex
func (v *Vertex) Neighbors() []*Vertex {
var res []*Vertex
for _, u := range v.neighbors {
res = append(res, u)
}
return res
}
// AddNeighbor adds the given vertex as a neighbor
// of the vertex
func (v *Vertex) AddNeighbor(u *Vertex) {
v.neighbors[u.Id] = u
u.neighbors[v.Id] = v
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。