From 4f42a45b5d0454cd1ca5cae2e7ed897bd63f708e Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 8 Jan 2024 20:20:20 +0100 Subject: fix --- c_litems.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'c_litems.go') diff --git a/c_litems.go b/c_litems.go index 0a1acf0..df20520 100644 --- a/c_litems.go +++ b/c_litems.go @@ -80,6 +80,32 @@ func (litems *ItemsList) add_back(node *ItemsNode) { litems.last = last.next } +// removes an item node from the list and resets the ids +func (litems *ItemsList) del(item *ItemsNode) { + if litems.head == nil { + return + } + if litems.head == item { + litems.head = litems.head.next + litems.head.prev = nil + for curr := litems.head; curr != nil; curr = curr.next { + curr.ID -= 1 + } + return + } + curr := litems.head + for curr.next != nil && curr.next != item { + curr = curr.next + } + if curr.next == item { + curr.next = curr.next.next + curr.next.prev = curr + } + for curr := curr.next; curr != nil; curr = curr.next { + curr.ID -= 1 + } +} + // sets litems.curr to be used func (litems *ItemsList) sel(id int) { curr := litems.head -- cgit v1.2.3