Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
type Vertex struct{
Id int
Label string
Neighbours map[*Vertex]bool
}
type Graph []*Vertex
struct Vertex
{
float x, y, z;
Vertex* [] adjacentVertices;
}
datatype Node = Int
datatype Adjacencies = [ Node ]
datatype Graph = [ Adjacencies ]
class Vertex(set): pass
class Graph(defaultdict):
def __init__(self, *paths):
self.default_factory = Vertex
for path in paths:
self.make_path(path)
def make_path(self, labels):
for l1, l2 in zip(labels, labels[1:]):
self[l1].add(l2)
self[l2].add(l1)
G = Graph((0, 1, 2, 3), (1, 4, 2))
inline class VertexId(val id: Int)
data class Vertex(val id: VertexId, val neighbours: Set<VertexId>)
data class Graph(val vertices: Set<Vertex>)
type Graph[L any] []*Vertex[L]
type Vertex[L any] struct {
Label L
Neighbours map[*Vertex[L]]bool
}