initial commit
This commit is contained in:
58
cmd/internal/depgraph/dependencygraph.go
Normal file
58
cmd/internal/depgraph/dependencygraph.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright © 2025 filifa
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package depgraph
|
||||
|
||||
import (
|
||||
"hash/crc32"
|
||||
|
||||
"gonum.org/v1/gonum/graph"
|
||||
"gonum.org/v1/gonum/graph/simple"
|
||||
)
|
||||
|
||||
type DependencyGraph struct {
|
||||
*simple.DirectedGraph
|
||||
}
|
||||
|
||||
func NewDependencyGraph() *DependencyGraph {
|
||||
return &DependencyGraph{DirectedGraph: simple.NewDirectedGraph()}
|
||||
}
|
||||
|
||||
func (g *DependencyGraph) NewNode() graph.Node {
|
||||
return &Sourcefile{Node: g.DirectedGraph.NewNode()}
|
||||
}
|
||||
|
||||
type Sourcefile struct {
|
||||
graph.Node
|
||||
name string
|
||||
}
|
||||
|
||||
func (s *Sourcefile) String() string {
|
||||
return s.name
|
||||
}
|
||||
|
||||
func NewSourcefile(name string) *Sourcefile {
|
||||
hash := crc32.ChecksumIEEE([]byte(name))
|
||||
return &Sourcefile{Node: simple.Node(hash), name: name}
|
||||
}
|
||||
|
||||
func (s *Sourcefile) DOTID() string {
|
||||
return s.name
|
||||
}
|
||||
|
||||
func (s *Sourcefile) SetDOTID(id string) {
|
||||
s.name = id
|
||||
}
|
||||
Reference in New Issue
Block a user