-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.go
More file actions
40 lines (35 loc) · 847 Bytes
/
node.go
File metadata and controls
40 lines (35 loc) · 847 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
package skiplist
// Node for a skiplist which is a linked list
// node containing a slice of forward referencing nodes,
// the previous node and the key and value of the node
type Node struct {
forward []*Node
backward *Node
key int
val interface{}
}
// NewNode takes a level used for the forward slice
// referencing linked nodes as well as the key and
// value of the node
func NewNode(level, key int, val interface{}) *Node {
return &Node{
forward: make([]*Node, level),
key: key,
val: val,
}
}
// Value returns val of node
func (n *Node) Value() interface{} {
return n.val
}
// Returns next node or nil if next node is not present
func (n *Node) next() *Node {
if len(n.forward) == 0 {
return nil
}
return n.forward[0]
}
// Returns the previous node
func (n *Node) prev() *Node {
return n.backward
}