forked from kkdai/basiclist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublebasicnode.go
More file actions
45 lines (35 loc) · 951 Bytes
/
doublebasicnode.go
File metadata and controls
45 lines (35 loc) · 951 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
package basiclist
type DoubleBasicNode struct {
key int
val interface{}
prev *DoubleBasicNode
next *DoubleBasicNode
isRoot bool
}
func newDoubleBasicRoot() *DoubleBasicNode {
return &DoubleBasicNode{-1, nil, nil, nil, true}
}
func NewDoubleBasicNode(key uint, val interface{}) *DoubleBasicNode {
return &DoubleBasicNode{int(key), val, nil, nil, false}
}
func (node *DoubleBasicNode) Key() uint {
return uint(node.key)
}
func (node *DoubleBasicNode) Value() *interface{} {
return &node.val
}
func (node *DoubleBasicNode) HasPrevious() bool {
return node != nil && !node.IsRoot() && node.Previous() != nil && !node.Previous().IsRoot()
}
func (node *DoubleBasicNode) Previous() *DoubleBasicNode {
return node.prev
}
func (node *DoubleBasicNode) HasNext() bool {
return node.next != nil
}
func (node *DoubleBasicNode) Next() *DoubleBasicNode {
return node.next
}
func (node *DoubleBasicNode) IsRoot() bool {
return node.isRoot
}