diff options
author | Joe <rbo@gmx.us> | 2024-01-05 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-05 20:20:20 +0100 |
commit | 133c9834756328c4314dc74e341bf9589251b947 (patch) | |
tree | 551225eb8b198927747e30361bc9a4edb4a3a59a | |
parent | awy (diff) | |
download | hardflip-133c9834756328c4314dc74e341bf9589251b947.tar.gz hardflip-133c9834756328c4314dc74e341bf9589251b947.tar.bz2 hardflip-133c9834756328c4314dc74e341bf9589251b947.tar.xz hardflip-133c9834756328c4314dc74e341bf9589251b947.tar.zst hardflip-133c9834756328c4314dc74e341bf9589251b947.zip |
turns out we need litems in the end
-rw-r--r-- | c_init.go | 2 | ||||
-rw-r--r-- | c_ldirs.go | 15 | ||||
-rw-r--r-- | c_lhosts.go | 16 | ||||
-rw-r--r-- | c_litems.go | 44 |
4 files changed, 45 insertions, 32 deletions
@@ -104,7 +104,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, // item_node.Host = host_node // litems.add_back(&item_node) host_node.Filename = filename - host_node.Parent = &dir_node + // host_node.Parent = &dir_node dir_node.lhost.add_back(host_node) global_id++ } @@ -68,20 +68,15 @@ type DirsList struct { // adds a directory node to the list func (ldirs *DirsList) add_back(node *DirsNode) { - new_node := node - - new_node.ID = global_id + node.ID = global_id if ldirs.head == nil { - ldirs.head = new_node + ldirs.head = node ldirs.last = ldirs.head return } - curr := ldirs.last - // for curr.next != nil { - // curr = curr.next - // } - curr.next = new_node - ldirs.last = curr.next + last := ldirs.last + last.next = node + ldirs.last = last.next } // return the list node with the according id diff --git a/c_lhosts.go b/c_lhosts.go index c3d2c77..bddc1c0 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -74,7 +74,6 @@ type HostNode struct { Dynamic bool `yaml:"dynamic"` Note string `yaml:"note"` Filename string - Parent *DirsNode next *HostNode } @@ -85,20 +84,15 @@ type HostList struct { // adds a host node to the list func (lhost *HostList) add_back(node *HostNode) { - new_node := node - - new_node.ID = global_id + node.ID = global_id if lhost.head == nil { - lhost.head = new_node + lhost.head = node lhost.last = lhost.head return } - curr := lhost.last - // for curr.next != nil { - // curr = curr.next - // } - curr.next = new_node - lhost.last = curr.next + last := lhost.last + last.next = node + lhost.last = last.next } func (lhost *HostList) reset_id() { diff --git a/c_litems.go b/c_litems.go index a104e6c..7183ea5 100644 --- a/c_litems.go +++ b/c_litems.go @@ -55,6 +55,7 @@ type ItemsNode struct { ID int Dirs *DirsNode Host *HostNode + prev *ItemsNode next *ItemsNode } @@ -82,19 +83,42 @@ func (litems *ItemsList) is_dir(id int) bool { } func (litems *ItemsList) add_back(node *ItemsNode) { - new_node := node - if litems.head == nil { - litems.head = new_node + litems.head = node litems.last = litems.head return } - curr := litems.last - // for curr.next != nil { - // curr = curr.next - // } - new_node.ID = curr.ID + 1 - curr.next = new_node - litems.last = curr.next + last := litems.last + node.ID = last.ID + 1 + node.prev = last + last.next = node + litems.last = last.next +} + +func (item *ItemsNode) is_dir() bool { + if item.Dirs == nil { + return false + } + return true } +func (item *ItemsNode) inc(jump int) *ItemsNode { + if jump == 0 { + return item + } else if jump == 1 { + return item.next + } else if jump == -1 { + return item.prev + } + new_item := item + if jump > 0 { + for i := 0; new_item != nil && i < jump; i++ { + new_item = new_item.next + } + return new_item + } + for i := 0; new_item != nil && i > jump; i-- { + new_item = new_item.prev + } + return new_item +} |