Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/dominikbraun/graph
/ functions
Functions
245 in github.com/dominikbraun/graph
⨍
Functions
245
◇
Types & classes
24
↓ 87 callers
Method
AddEdge
AddEdge should add an edge between the vertices with the given source and target hashes. If either vertex doesn't exit, ErrVertexNotFound should be r
store.go:39
↓ 65 callers
Method
AddVertex
AddVertex should add the given vertex with the given hash value and vertex properties to the graph. If the vertex already exists, it is up to you whet
store.go:17
↓ 52 callers
Function
New
New creates a new graph with vertices of type T, identified by hash values of type K. These hash values will be obtained using the provided hash funct
graph.go:255
↓ 30 callers
Function
Directed
Directed creates a directed graph. This has implications on graph traversal and the order of arguments of the Edge and AddEdge functions.
traits.go:20
↓ 24 callers
Function
EdgeWeight
EdgeWeight returns a function that sets the weight of an edge to the given weight. This is a functional option for the [graph.Graph.Edge] and [graph.G
graph.go:318
↓ 24 callers
Function
newMemoryStore
()
store.go:78
↓ 21 callers
Method
AdjacencyMap
AdjacencyMap computes an adjacency map with all vertices in the graph. There is an entry for each vertex. Each of those entries is another map whose
graph.go:174
↓ 20 callers
Method
Traits
Traits returns the graph's traits. Those traits must be set when creating a graph using New.
graph.go:68
↓ 20 callers
Method
Vertex
Vertex should return the vertex and vertex properties with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned.
store.go:21
↓ 18 callers
Function
copyEdge
copyEdge returns an argument list suitable for the Graph.AddEdge method. This argument list is derived from the given edge, hence the name copyEdge.
directed.go:315
↓ 14 callers
Method
Edge
Edge should return the edge joining the vertices with the given hash values. It should exclusively look for an edge between the source and the target
store.go:61
↓ 11 callers
Method
Len
()
collection.go:82
↓ 11 callers
Function
edgesAreEqual
(a, b Edge[K], directed bool)
directed_test.go:1391
↓ 11 callers
Function
newDirected
(hash Hash[K, T], traits *Traits, store Store[K, T])
directed.go:14
↓ 11 callers
Function
newUndirected
(hash Hash[K, T], traits *Traits, store Store[K, T])
undirected.go:14
↓ 11 callers
Function
traitsAreEqual
(a, b *Traits)
traits_test.go:139
↓ 8 callers
Method
RemoveEdge
RemoveEdge should remove the edge between the vertices with the given source and target hashes. If either vertex doesn't exist, it is up to you wheth
store.go:51
↓ 8 callers
Function
copyVertexProperties
(source VertexProperties)
sets.go:117
↓ 7 callers
Method
RemoveVertex
RemoveVertex should remove the vertex with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned. If the vertex has
store.go:26
↓ 7 callers
Method
VertexWithProperties
VertexWithProperties returns the vertex with the given hash along with its properties or ErrVertexNotFound if it doesn't exist.
graph.go:93
↓ 7 callers
Method
isEmpty
()
collection.go:114
↓ 6 callers
Function
EdgeData
EdgeData returns a function that sets the data of an edge to the given value. This is a functional option for the [graph.Graph.Edge] and [graph.Graph.
graph.go:345
↓ 6 callers
Method
PredecessorMap
PredecessorMap computes a predecessor map with all vertices in the graph. It has the same map layout and does the same thing as AdjacencyMap, but for
graph.go:197
↓ 6 callers
Method
Push
(item interface{})
collection.go:96
↓ 6 callers
Function
VertexAttribute
VertexAttribute returns a function that adds the given key-value pair to the vertex attributes. This is a functional option for the [graph.Graph.Verte
graph.go:375
↓ 6 callers
Method
top
()
collection.go:113
↓ 5 callers
Method
ListEdges
ListEdges should return all edges in the graph in a slice.
store.go:64
↓ 5 callers
Method
Order
Order returns the number of vertices in the graph.
graph.go:207
↓ 5 callers
Method
Pop
()
collection.go:102
↓ 5 callers
Method
UpdateEdge
UpdateEdge should update the edge between the given vertices with the data of the given Edge instance. If the edge doesn't exist, ErrEdgeNotFound shou
store.go:43
↓ 5 callers
Function
VertexWeight
VertexWeight returns a function that sets the weight of a vertex to the given weight. This is a functional option for the [graph.Graph.Vertex] and [gr
graph.go:366
↓ 5 callers
Function
adjacencyMapsAreEqual
(a, b map[K]map[K]Edge[K], edgesAreEqual func(a, b Edge[K]) bool)
sets_test.go:288
↓ 5 callers
Method
find
(vertex K)
sets.go:98
↓ 4 callers
Method
AddEdgesFrom
AddEdgesFrom adds all edges along with their properties from the given graph to the receiving graph. All vertices that the edges are joining have to
graph.go:122
↓ 4 callers
Method
AddVerticesFrom
AddVerticesFrom adds all vertices along with their properties from the given graph to the receiving graph. All vertices will be added until an error
graph.go:85
↓ 4 callers
Method
Clone
Clone creates a deep copy of the graph and returns that cloned graph. The cloned graph will use the default in-memory store for storing the vertices
graph.go:204
↓ 4 callers
Function
CreatesCycle
CreatesCycle determines whether adding an edge between the two given vertices would introduce a cycle in the graph. CreatesCycle will not create an ed
paths.go:16
↓ 4 callers
Function
EdgeAttribute
EdgeAttribute returns a function that adds the given key-value pair to the attributes of an edge. This is a functional option for the [graph.Graph.Edg
graph.go:327
↓ 4 callers
Method
Edges
Edges returns a slice of all edges in the graph. These edges are of type Edge[K] and hence will contain the vertex hashes, not the vertex values.
graph.go:131
↓ 4 callers
Function
Weighted
Weighted creates a weighted graph. To set weights, use the Edge and AddEdge functions.
traits.go:35
↓ 4 callers
Method
pop
()
collection.go:112
↓ 4 callers
Method
push
(T)
collection.go:111
↓ 3 callers
Function
Acyclic
Acyclic creates an acyclic graph. Note that creating edges that form a cycle will still be possible. To prevent this explicitly, use PreventCycles.
traits.go:28
↓ 3 callers
Method
ListVertices
ListVertices should return all vertices in the graph in a slice.
store.go:29
↓ 3 callers
Method
addEdge
(sourceHash, targetHash K, edge Edge[K])
directed.go:241
↓ 3 callers
Method
forEach
forEach iterate the stack from bottom to top
collection.go:116
↓ 3 callers
Function
slicesAreEqual
(a, b []T)
directed_test.go:1350
↓ 2 callers
Method
AdjacencyMap
()
undirected.go:256
↓ 2 callers
Function
BFS
BFS performs a breadth-first search on the graph, starting from the given vertex. The visit function will be invoked with the hash of the vertex curre
traversal.go:101
↓ 2 callers
Function
BFSWithDepth
BFSWithDepth works just as BFS and performs a breadth-first search on the graph, but its visit function is passed the current depth level as a second
traversal.go:119
↓ 2 callers
Function
DFS
DFS performs a depth-first search on the graph, starting from the given vertex. The visit function will be invoked with the hash of the vertex current
traversal.go:35
↓ 2 callers
Method
Edge
(sourceHash, targetHash K)
directed.go:134
↓ 2 callers
Method
Edge
(sourceHash, targetHash K)
undirected.go:138
↓ 2 callers
Function
MaximumSpanningTree
MaximumSpanningTree returns a minimum spanning tree within the given graph. The MST contains all vertices from the given graph as well as the require
trees.go:21
↓ 2 callers
Function
MinimumSpanningTree
MinimumSpanningTree returns a minimum spanning tree within the given graph. The MST contains all vertices from the given graph as well as the require
trees.go:13
↓ 2 callers
Function
NewLike
NewLike creates a graph that is "like" the given graph: It has the same type, the same hashing function, and the same traits. The new graph is indepen
graph.go:283
↓ 2 callers
Function
Rooted
Rooted creates a rooted graph. This is particularly common for building tree data structures.
traits.go:42
↓ 2 callers
Function
ShortestPath
ShortestPath computes the shortest path between a source and a target vertex under consideration of the edge weights. It returns a slice of hash value
paths.go:70
↓ 2 callers
Method
Size
Size returns the number of edges in the graph.
graph.go:210
↓ 2 callers
Function
StronglyConnectedComponents
StronglyConnectedComponents detects all strongly connected components within the graph and returns the hashes of the vertices shaping these components
paths.go:155
↓ 2 callers
Function
TopologicalSort
TopologicalSort runs a topological sort on a given directed graph and returns the vertex hashes in topological order. The topological order is a non-u
dag.go:20
↓ 2 callers
Function
TransitiveReduction
TransitiveReduction returns a new graph with the same vertices and the same reachability as the given graph, but with as few edges as possible. The gr
dag.go:155
↓ 2 callers
Method
UpdatePriority
UpdatePriority updates the priority of a given item and sets it to the given priority. If the item doesn't exist, nothing happens. This operation may
collection.go:69
↓ 2 callers
Method
Vertex
(k K)
store.go:120
↓ 2 callers
Method
VertexCount
VertexCount should return the number of vertices in the graph. This should be equal to the length of the slice returned by ListVertices.
store.go:33
↓ 2 callers
Method
add
(vertex K)
sets.go:83
↓ 2 callers
Method
edgesAreEqual
(a, b Edge[T])
directed.go:289
↓ 2 callers
Function
generateDOT
(g graph.Graph[K, T], options ...func(*description))
draw/draw.go:89
↓ 2 callers
Function
mapsAreEqual
(a, b map[K]K)
sets_test.go:330
↓ 2 callers
Function
mapsAreEqual
(a, b map[K]V, equals func(a, b V) bool)
draw/draw_test.go:420
↓ 2 callers
Function
normalizeOutput
(output string)
draw/draw_test.go:438
↓ 2 callers
Function
renderDOT
(w io.Writer, d description)
draw/draw.go:138
↓ 2 callers
Function
spanningTree
(g Graph[K, T], maximum bool)
trees.go:25
↓ 2 callers
Method
union
(vertex1, vertex2 K)
sets.go:87
↓ 2 callers
Function
vertexPropertiesAreEqual
(a, b VertexProperties)
directed_test.go:1370
↓ 1 callers
Method
AddEdge
(sourceHash, targetHash K, options ...func(*EdgeProperties))
directed.go:78
↓ 1 callers
Method
AddEdge
(sourceHash, targetHash K, options ...func(*EdgeProperties))
undirected.go:59
↓ 1 callers
Method
AddVertex
(value T, options ...func(*VertexProperties))
directed.go:26
↓ 1 callers
Method
AddVertex
(value T, options ...func(*VertexProperties))
undirected.go:26
↓ 1 callers
Method
AdjacencyMap
()
directed.go:190
↓ 1 callers
Function
AllPathsBetween
AllPathsBetween computes and returns all paths between two given vertices. A path is represented as a slice of vertex hashes. The returned slice conta
paths.go:242
↓ 1 callers
Method
CreatesCycle
CreatesCycle is a fastpath version of [CreatesCycle] that avoids calling [PredecessorMap], which generates large amounts of garbage to collect. Becau
store.go:239
↓ 1 callers
Method
Edge
(sourceHash, targetHash K)
store.go:204
↓ 1 callers
Function
EdgeAttributes
EdgeAttributes returns a function that sets the given map as the attributes of an edge. This is a functional option for the [graph.Graph.AddEdge] and
graph.go:336
↓ 1 callers
Function
GraphAttribute
GraphAttribute is a functional option for the [DOT] method.
draw/draw.go:83
↓ 1 callers
Function
IntHash
IntHash is a hashing function that accepts an integer and uses that exact integer as a hash value. Using it as Hash will yield a Graph[int, int].
graph.go:311
↓ 1 callers
Function
NewWithStore
NewWithStore creates a new graph same as [New] but uses the provided store instead of the default memory store.
graph.go:261
↓ 1 callers
Function
PreventCycles
PreventCycles creates an acyclic graph that prevents and proactively prevents the creation of cycles. These cycle checks affect the performance and co
traits.go:58
↓ 1 callers
Function
StableTopologicalSort
StableTopologicalSort does the same as [TopologicalSort], but takes a function for comparing (and then ordering) two given vertices. This allows for a
dag.go:76
↓ 1 callers
Function
StringHash
StringHash is a hashing function that accepts a string and uses that exact string as a hash value. Using it as Hash will yield a Graph[string, string]
graph.go:305
↓ 1 callers
Function
Tree
Tree is an alias for Acyclic and Rooted, since most trees in Computer Science are rooted trees.
traits.go:49
↓ 1 callers
Function
Union
Union combines two given graphs into a new graph. The vertex hashes in both graphs are expected to be unique. The two input graphs will remain unchang
sets.go:12
↓ 1 callers
Function
VertexAttributes
VertexAttributes returns a function that sets the given map as the attributes of a vertex. This is a functional option for the [graph.Graph.AddVertex]
graph.go:383
↓ 1 callers
Method
addEdge
(sourceHash, targetHash K, edge Edge[K])
undirected.go:347
↓ 1 callers
Function
adjacencyList
(store Store[K, T], vertexHash K)
undirected_test.go:1399
↓ 1 callers
Method
createsCycle
(source, target K)
directed.go:298
↓ 1 callers
Function
findSCC
(vertexHash K, state *sccState[K])
paths.go:184
↓ 1 callers
Method
isEmpty
()
collection.go:153
↓ 1 callers
Function
newStack
()
collection.go:119
↓ 1 callers
Function
newUnionFind
(vertices ...K)
sets.go:71
next →
1–100 of 245, ranked by callers