initial commit

This commit is contained in:
filifa
2025-03-30 14:41:08 -04:00
commit c313758b2c
7 changed files with 1008 additions and 0 deletions

View 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
}