-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnode.go
More file actions
42 lines (35 loc) · 712 Bytes
/
node.go
File metadata and controls
42 lines (35 loc) · 712 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
package avltree
// Balance factor
const (
equal = iota
leftHigh
rightHigh
)
// treeNode is a node in the tree
type treeNode[T any] struct {
// Left and right nodes.
left, right *treeNode[T]
// The number of nodes in the left and right subtrees
// (excludes this node).
size int
// The contents of this node.
value T
// The balance factor of this node.
bal byte
}
// leftSize returns the size of the left subtree
// of the node
func (n *treeNode[T]) leftSize() int {
if n.left != nil {
return n.left.size + 1
}
return 0
}
// rightSize returns the size of the right subtree
// of the node
func (n treeNode[T]) rightSize() int {
if n.right != nil {
return n.right.size + 1
}
return 0
}