diff --git a/internal/entropy/graph.go b/internal/entropy/graph.go index 1a0f1c1..389a4d0 100644 --- a/internal/entropy/graph.go +++ b/internal/entropy/graph.go @@ -4,6 +4,7 @@ import ( "path" "github.com/gabotechs/dep-tree/internal/dep_tree" + "github.com/gabotechs/dep-tree/internal/graph" "github.com/gabotechs/dep-tree/internal/language" "github.com/gabotechs/dep-tree/internal/utils" ) @@ -13,7 +14,7 @@ const ( ) type Node struct { - Id string `json:"id"` + Id int64 `json:"id"` FileName string `json:"fileName"` DirName string `json:"dirName"` Loc int `json:"loc"` @@ -23,10 +24,10 @@ type Node struct { } type Link struct { - From string `json:"from"` - To string `json:"to"` - IsDir bool `json:"isDir"` - IsCyclic bool `json:"isCyclic"` + From int64 `json:"from"` + To int64 `json:"to"` + IsDir bool `json:"isDir"` + IsCyclic bool `json:"isCyclic"` } type Graph struct { @@ -58,7 +59,7 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars filepath := parser.Display(node) dirName := path.Dir(filepath) out.Nodes = append(out.Nodes, Node{ - Id: utils.Hash(node.Id), + Id: node.ID(), FileName: path.Base(filepath), DirName: dirName + "/", Loc: node.Data.Loc, @@ -68,15 +69,16 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars for _, to := range dt.Graph.FromId(node.Id) { out.Links = append(out.Links, Link{ - From: utils.Hash(node.Id), - To: utils.Hash(to.Id), + From: node.ID(), + To: to.ID(), }) } for _, parentFolder := range splitFullPaths(dirName) { + folderNode := graph.MakeNode(parentFolder, 0) out.Links = append(out.Links, Link{ - From: utils.Hash(node.Id), - To: utils.Hash(parentFolder), + From: node.ID(), + To: folderNode.ID(), IsDir: true, }) if _, ok := addedFolders[parentFolder]; ok { @@ -84,7 +86,7 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars } else { addedFolders[parentFolder] = true out.Nodes = append(out.Nodes, Node{ - Id: utils.Hash(parentFolder), + Id: folderNode.ID(), IsDir: true, }) } @@ -93,8 +95,8 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars for el := dt.Cycles.Front(); el != nil; el = el.Next() { out.Links = append(out.Links, Link{ - From: utils.Hash(el.Key[0]), - To: utils.Hash(el.Key[1]), + From: graph.MakeNode(el.Key[0], 0).ID(), + To: graph.MakeNode(el.Key[1], 0).ID(), IsCyclic: true, }) } diff --git a/internal/graph/node.go b/internal/graph/node.go index 7e773be..87b9170 100644 --- a/internal/graph/node.go +++ b/internal/graph/node.go @@ -3,8 +3,9 @@ package graph import ( "hash/fnv" - "github.com/gabotechs/dep-tree/internal/utils" "gonum.org/v1/gonum/graph" + + "github.com/gabotechs/dep-tree/internal/utils" ) type Node[T any] struct { diff --git a/internal/utils/hash.go b/internal/utils/hash.go deleted file mode 100644 index 2783876..0000000 --- a/internal/utils/hash.go +++ /dev/null @@ -1,12 +0,0 @@ -package utils - -import ( - "crypto/md5" //nolint:gosec - "fmt" -) - -func hash(text string) string { - return fmt.Sprintf("%x", md5.Sum([]byte(text))) //nolint:gosec -} - -var Hash = Cached(hash)