From 4f42a45b5d0454cd1ca5cae2e7ed897bd63f708e Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 8 Jan 2024 20:20:20 +0100 Subject: fix --- c_lhosts.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'c_lhosts.go') diff --git a/c_lhosts.go b/c_lhosts.go index fde5881..791e885 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -96,30 +96,28 @@ func (lhost *HostList) add_back(node *HostNode) { lhost.last = last.next } -func (lhost *HostList) reset_id() { - curr := lhost.head - for i := 0; curr != nil; i++ { - curr.ID = i - curr = curr.next - } -} - // removes a host node from the list -func (lhost *HostList) del(id int) { +func (lhost *HostList) del(host *HostNode) { if lhost.head == nil { return } - if lhost.head.ID == id { + if lhost.head == host { lhost.head = lhost.head.next + for curr:= lhost.head; curr != nil; curr = curr.next { + curr.ID -= 1 + } return } curr := lhost.head - for curr.next != nil && curr.next.ID != id { + for curr.next != nil && curr.next != host { curr = curr.next } - if curr.next.ID == id { + if curr.next == host { curr.next = curr.next.next } + for curr := curr.next; curr != nil; curr = curr.next { + curr.ID -= 1 + } } // return the list node with the according id -- cgit v1.2.3