Added addChild and addChildNode functions (WIP)
This commit is contained in:
parent
0c107c3a72
commit
94e86335b2
@ -1,5 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type FileNode struct{
|
type FileNode struct{
|
||||||
children [] FileNode
|
children [] FileNode
|
||||||
path string
|
path string
|
||||||
@ -9,3 +13,35 @@ type FileNode struct{
|
|||||||
func (f *FileNode) addChildren(path string){
|
func (f *FileNode) addChildren(path string){
|
||||||
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f})
|
f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user