diff options
author | Joe <rbo@gmx.us> | 2023-12-21 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2023-12-21 20:20:20 +0100 |
commit | 803ea382f7ccbf3df0604974858f0213a2a27ef9 (patch) | |
tree | 70defc7c7d84171b5ecbf64473e245d674760013 /c_lhosts.go | |
parent | yesno (diff) | |
download | hardflip-803ea382f7ccbf3df0604974858f0213a2a27ef9.tar.gz hardflip-803ea382f7ccbf3df0604974858f0213a2a27ef9.tar.bz2 hardflip-803ea382f7ccbf3df0604974858f0213a2a27ef9.tar.xz hardflip-803ea382f7ccbf3df0604974858f0213a2a27ef9.tar.zst hardflip-803ea382f7ccbf3df0604974858f0213a2a27ef9.zip |
clean list delete
Diffstat (limited to '')
-rw-r--r-- | c_lhosts.go | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/c_lhosts.go b/c_lhosts.go index ac5cfcd..9425231 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_lhosts.go - * Tue Dec 19 18:51:12 2023 + * Thu, 21 Dec 2023 11:51:44 +0100 * Joe * * the hosts linked list @@ -94,23 +94,31 @@ func (lhost *HostList) add_back(node *HostNode) { curr.next = new_node } -// not used - removes a host node from the list -// func (lhost *HostList) del(id uint64) { -// if lhost.head == nil { -// return -// } -// if lhost.head.ID == id { -// lhost.head = lhost.head.next -// return -// } -// curr := lhost.head -// for curr.next != nil && curr.next.ID != id { -// curr = curr.next -// } -// if curr.next != nil { -// curr.next = curr.next.next -// } -// } +func (lhost *HostList) reset_id() { + curr := lhost.head + for i := 0; curr != nil; i++ { + curr.ID = uint64(i) + curr = curr.next + } +} + +// removes a host node from the list +func (lhost *HostList) del(id uint64) { + if lhost.head == nil { + return + } + if lhost.head.ID == id { + lhost.head = lhost.head.next + return + } + curr := lhost.head + for curr.next != nil && curr.next.ID != id { + curr = curr.next + } + if curr.next.ID == id { + curr.next = curr.next.next + } +} // return the list node with the according id func (lhost *HostList) sel(id uint64) *HostNode { |