Skip to content

Commit 44b727c

Browse files
committed
feat: add weight handling documentation for graph generation functions
1 parent 1e85fdd commit 44b727c

8 files changed

Lines changed: 16 additions & 0 deletions

File tree

v2/graph/standard/barabasi_albert.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
// BarabasiAlbertGraph generates a graph based on the Barabási-Albert preferential attachment model.
1010
// The graph starts with m fully connected nodes, and new nodes are added one by one, each connecting
1111
// to m existing nodes with a probability proportional to their degree.
12+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
13+
// each new edge with the new node and the target node as arguments.
1214
func BarabasiAlbertGraph(seed int, directed bool, weightFunc WeightedFunc, n int, m int) (*graph.Graph, error) {
1315
if n < 0 {
1416
return nil, fmt.Errorf("invalid number of nodes: n must be non-negative")

v2/graph/standard/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func generateRand(seed int) *rand.Rand {
4545
}
4646

4747
// StandardGraph generates a graph based on the provided configuration. It supports various graph types and parameters.
48+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
49+
// each new edge with the new node and the target node as arguments.
4850
func StandardGraph(seed int, directed bool, weightFunc WeightedFunc, config GraphConfig) (*graph.Graph, error) {
4951
switch config.Type {
5052
case Grid:

v2/graph/standard/erdos_renyi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
// ErdosRenyiGraph generates a random graph based on the Erdős-Rényi model.
1010
// Nodes are added first, and then edges are created between nodes with a probability p.
11+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
12+
// each new edge with the new node and the target node as arguments.
1113
func ErdosRenyiGraph(seed int, directed bool, weightFunc WeightedFunc, n int, p float64) (*graph.Graph, error) {
1214
if p < 0 || p > 1 {
1315
return nil, fmt.Errorf("invalid probability: p must be between 0 and 1")

v2/graph/standard/grid.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
// GridGraph generates a grid graph with the specified number of rows and columns.
1010
// If torus is true, the graph will wrap around at the edges, creating a toroidal structure.
11+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
12+
// each new edge with the new node and the target node as arguments.
1113
func GridGraph(seed int, directed bool, weightFunc WeightedFunc, rows, cols int, torus bool) (*graph.Graph, error) {
1214
if rows < 0 || cols < 0 {
1315
return nil, fmt.Errorf("rows and cols must be non-negative")

v2/graph/standard/random_geometric.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
// RandomGeometricGraph generates a random geometric graph (RGG).
1111
// Nodes are placed uniformly at random in the unit square, and edges
1212
// are added between nodes that are within a specified radius r.
13+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
14+
// each new edge with the new node and the target node as arguments.
1315
func RandomGeometricGraph(seed int, directed bool, weightFunc WeightedFunc, n int, r float64) (*graph.Graph, error) {
1416
if r < 0 || r > 1 {
1517
return nil, fmt.Errorf("invalid radius: r must be between 0 and 1")

v2/graph/standard/random_regular.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
// RandomRegularGraph generates a random k-regular graph with n nodes.
1010
// Each node has exactly degree k. Returns nil if impossible.
1111
// This implementation requires n*k to be even.
12+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
13+
// each new edge with the new node and the target node as arguments.
1214
func RandomRegularGraph(seed int, directed bool, weightFunc WeightedFunc, n, k int) (*graph.Graph, error) {
1315
if k < 0 || k >= n {
1416
// degree must be between 0 and n-1

v2/graph/standard/triangle_hex.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
// TriangleHexGraph generates a hexagonal lattice graph with a specified edge length.
10+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
11+
// each new edge with the new node and the target node as arguments.
1012
func TriangleHexGraph(seed int, directed bool, weightFunc WeightedFunc, edge int) (*graph.Graph, error) {
1113

1214
if edge < 0 {

v2/graph/standard/watts_strogatz.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
// WattsStrogatzGraph generates a small-world graph based on the Watts-Strogatz model.
10+
// If weightFunc is nil, all edges will have no weight (unweighted graph). Otherwise, weightFunc will be called for
11+
// each new edge with the new node and the target node as arguments.
1012
func WattsStrogatzGraph(seed int, directed bool, weightFunc WeightedFunc, n, k int, beta float64) (*graph.Graph, error) {
1113
if k < 0 || k >= n {
1214
// degree must be between 0 and n-1

0 commit comments

Comments
 (0)