add comments on public methods

This commit is contained in:
filifa 2025-04-05 18:14:01 -04:00
parent f6cb65ce82
commit 47494fa849
1 changed files with 9 additions and 0 deletions

View File

@ -23,36 +23,45 @@ import (
"gonum.org/v1/gonum/graph/simple"
)
// DependencyGraph represents dependencies between files in a Go package.
type DependencyGraph struct {
*simple.DirectedGraph
}
// NewDependencyGraph returns an empty DependencyGraph.
func NewDependencyGraph() *DependencyGraph {
return &DependencyGraph{DirectedGraph: simple.NewDirectedGraph()}
}
// NewNode returns a new Sourcefile node.
func (g *DependencyGraph) NewNode() graph.Node {
return &Sourcefile{Node: g.DirectedGraph.NewNode()}
}
// Sourcefile represents a given source file in a Go package.
type Sourcefile struct {
graph.Node
name string
}
// String returns the name attribute of Sourcefile.
func (s *Sourcefile) String() string {
return s.name
}
// NewSourcefile returns a Sourcefile node with ID determined by the CRC32 hash
// of the name of the source file.
func NewSourcefile(name string) *Sourcefile {
hash := crc32.ChecksumIEEE([]byte(name))
return &Sourcefile{Node: simple.Node(hash), name: name}
}
// DOTID returns the name attribute of the source file.
func (s *Sourcefile) DOTID() string {
return s.name
}
// SetDOTID sets the name attribute of a Sourcefile to the given id.
func (s *Sourcefile) SetDOTID(id string) {
s.name = id
}