2021-10-09 11:01:31 -06:00
|
|
|
package main
|
|
|
|
|
2021-10-09 13:59:22 -06:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-10-09 11:01:31 -06:00
|
|
|
type FileNode struct{
|
|
|
|
children [] FileNode
|
|
|
|
path string
|
|
|
|
parent *FileNode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FileNode) addChildren(path string){
|
|
|
|
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f})
|
|
|
|
}
|
2021-10-09 13:59:22 -06:00
|
|
|
|
|
|
|
func (f *FileNode) addChildNode(m FileNode){
|
|
|
|
m.parent = f
|
|
|
|
f.children = append(f.children, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func mapGenerator(fileList [] string) map[string][]string {
|
|
|
|
var a map[string][]string = make(map[string][]string)
|
|
|
|
for i := range(fileList){
|
|
|
|
a[strings.Split(fileList[i] , "/")[0]] = append(a[strings.Split(fileList[i] , "/")[0]], strings.Split(fileList[i] , "/")[1])
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateDirectoryTree(fileList [] string) *FileNode{
|
|
|
|
var head *FileNode = new(FileNode)
|
|
|
|
for i:=0; i<len(fileList) ; i++ {
|
|
|
|
separatedPaths := strings.Split(fileList [i] , "/")
|
|
|
|
var currentNode *FileNode = new(FileNode)
|
|
|
|
tempNode := currentNode
|
|
|
|
for j := range(separatedPaths) {
|
|
|
|
if j != (len(separatedPaths)-1) {
|
|
|
|
tempNode.addChildren(separatedPaths[j])
|
|
|
|
tempNode = &tempNode.children[0]
|
|
|
|
} else{
|
|
|
|
tempNode.addChildren(separatedPaths[j])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
head.addChildNode(*currentNode)
|
|
|
|
}
|
|
|
|
return head;
|
|
|
|
}
|