Source File
traits.go
Belonging Package
github.com/dominikbraun/graph
package graph// Traits represents a set of graph traits and types, such as directedness or acyclicness. These// traits can be set when creating a graph by passing the corresponding functional options, for// example://// g := graph.New(graph.IntHash, graph.Directed())//// This will set the IsDirected field to true.type Traits struct {IsDirected boolIsAcyclic boolIsWeighted boolIsRooted boolPreventCycles bool}// Directed creates a directed graph. This has implications on graph traversal and the order of// arguments of the Edge and AddEdge functions.func () func(*Traits) {return func( *Traits) {.IsDirected = true}}// Acyclic creates an acyclic graph. Note that creating edges that form a cycle will still be// possible. To prevent this explicitly, use PreventCycles.func () func(*Traits) {return func( *Traits) {.IsAcyclic = true}}// Weighted creates a weighted graph. To set weights, use the Edge and AddEdge functions.func () func(*Traits) {return func( *Traits) {.IsWeighted = true}}// Rooted creates a rooted graph. This is particularly common for building tree data structures.func () func(*Traits) {return func( *Traits) {.IsRooted = true}}// Tree is an alias for Acyclic and Rooted, since most trees in Computer Science are rooted trees.func () func(*Traits) {return func( *Traits) {Acyclic()()Rooted()()}}// PreventCycles creates an acyclic graph that prevents and proactively prevents the creation of// cycles. These cycle checks affect the performance and complexity of operations such as AddEdge.func () func(*Traits) {return func( *Traits) {Acyclic()().PreventCycles = true}}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |