-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.go
More file actions
49 lines (42 loc) · 871 Bytes
/
list.go
File metadata and controls
49 lines (42 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Use of this source code is governed by the LICENSE file in this module's root
// directory.
package kargs
import "fmt"
type kargItem struct {
karg Karg
next *kargItem
prev *kargItem
}
// remove deletes k from the list
func remove(k *kargItem) error {
if k == nil {
return fmt.Errorf("remove: %w", ErrNilPtr)
}
if k.prev != nil {
k.prev.next = k.next
}
if k.next != nil {
k.next.prev = k.prev
}
return nil
}
// replace replaces oldK with newK in the list
func replace(oldK, newK *kargItem) error {
if oldK == nil {
return fmt.Errorf("replace: old item: %w", ErrNilPtr)
}
if newK == nil {
return fmt.Errorf("replace: new item: %w", ErrNilPtr)
}
newK.prev = oldK.prev
newK.next = oldK.next
if oldK.prev != nil {
oldK.prev.next = newK
}
if oldK.next != nil {
oldK.next.prev = newK
}
oldK.prev = nil
oldK.next = nil
return nil
}