From 7e595f4ba400b32ece930de0847d994f6f2fbe24 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jan 2024 20:20:20 +0100 Subject: unique id maybe? --- c_hardflip.go | 23 ++++++++++++++++++----- c_init.go | 23 ++++++++++++++--------- c_ldirs.go | 2 +- c_lhosts.go | 4 ++-- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/c_hardflip.go b/c_hardflip.go index 4fd2b9f..f11cf19 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -51,7 +51,7 @@ package main -// import "fmt" +import "fmt" // the main data structure, holds up everything important type HardData struct { @@ -73,12 +73,24 @@ func main() { opts, data_dir, } - // for dir := ldirs.head; dir != nil ; dir = dir.next { - // fmt.Println(dir.ID, dir.Name) - // } + for dir := ldirs.head; dir != nil ; dir = dir.next { + spaces := "" + for i := 0; i < int(dir.Depth - 1) * 2; i++ { + spaces += " " + } + fmt.Println(dir.ID, spaces, dir.Name, "DIR") + for host := dir.lhost.head; host != nil; host = host.next { + spaces := "" + for i := 0; i < int(host.Parent.Depth - 1) * 2; i++ { + spaces += " " + } + spaces += " " + fmt.Println(host.ID, spaces, host.Name, "HOST") + } + } // for dir := ldirs.head; dir != nil ; dir = dir.next { // for host := dir.lhost.head; host != nil; host = host.next { - // fmt.Println(host.ID, host.Name) + // fmt.Println(host.ID, host.Name, "HOST") // } // } // for item := litems.head; item != nil ; item = item.next { @@ -90,5 +102,6 @@ func main() { // } // PERF: test performance over a large amount of hosts with litems + return i_ui(&data) } diff --git a/c_init.go b/c_init.go index dc42774..3c22e2b 100644 --- a/c_init.go +++ b/c_init.go @@ -62,6 +62,9 @@ type HardOpts struct { FoldAll bool } + +var global_id uint64 + // this function recurses into the specified root directory in order to load // every yaml file into memory func c_recurse_data_dir(dir, root string, opts HardOpts, @@ -80,11 +83,12 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, opts.FoldAll, nil, } - item_node := ItemsNode{} - item_node.Dirs = &dir_node - item_node.Host = nil + // item_node := ItemsNode{} + // item_node.Dirs = &dir_node + // item_node.Host = nil ldirs.add_back(&dir_node) - litems.add_back(&item_node) + global_id++ + // litems.add_back(&item_node) for _, file := range files { filename := file.Name() if file.IsDir() == true { @@ -95,13 +99,14 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, if host_node == nil { return } - item_node := ItemsNode{} - item_node.Dirs = nil - item_node.Host = host_node - litems.add_back(&item_node) + // item_node := ItemsNode{} + // item_node.Dirs = nil + // item_node.Host = host_node + // litems.add_back(&item_node) host_node.Filename = filename - host_node.Dir = &dir_node + host_node.Parent = &dir_node dir_node.lhost.add_back(host_node) + global_id++ } } } diff --git a/c_ldirs.go b/c_ldirs.go index 185d2a0..b647944 100644 --- a/c_ldirs.go +++ b/c_ldirs.go @@ -70,6 +70,7 @@ type DirsList struct { func (ldirs *DirsList) add_back(node *DirsNode) { new_node := node + new_node.ID = global_id if ldirs.head == nil { ldirs.head = new_node ldirs.last = ldirs.head @@ -79,7 +80,6 @@ func (ldirs *DirsList) add_back(node *DirsNode) { // for curr.next != nil { // curr = curr.next // } - new_node.ID = curr.ID + 1 curr.next = new_node ldirs.last = curr.next } diff --git a/c_lhosts.go b/c_lhosts.go index df26d25..6e7ea77 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -74,7 +74,7 @@ type HostNode struct { Dynamic bool `yaml:"dynamic"` Note string `yaml:"note"` Filename string - Dir *DirsNode + Parent *DirsNode next *HostNode } @@ -87,6 +87,7 @@ type HostList struct { func (lhost *HostList) add_back(node *HostNode) { new_node := node + new_node.ID = global_id if lhost.head == nil { lhost.head = new_node lhost.last = lhost.head @@ -96,7 +97,6 @@ func (lhost *HostList) add_back(node *HostNode) { // for curr.next != nil { // curr = curr.next // } - new_node.ID = curr.ID + 1 curr.next = new_node lhost.last = curr.next } -- cgit v1.2.3