github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/tree/tree_intf.go (about)

     1  package tree
     2  
     3  import "github.com/benz9527/xboot/lib/infra"
     4  
     5  // go install golang.org/x/tools/cmd/stringer@latest
     6  
     7  //go:generate stringer -type=RBColor
     8  type RBColor uint8
     9  
    10  const (
    11  	Black RBColor = iota
    12  	Red
    13  )
    14  
    15  //go:generate stringer -type=RBDirection
    16  type RBDirection int8
    17  
    18  const (
    19  	Left RBDirection = -1 + iota
    20  	Root
    21  	Right
    22  )
    23  
    24  type RBNode[K infra.OrderedKey, V any] interface {
    25  	Key() K
    26  	Val() V
    27  	HasKeyVal() bool
    28  	Color() RBColor
    29  	Left() RBNode[K, V]
    30  	Right() RBNode[K, V]
    31  	Parent() RBNode[K, V]
    32  }
    33  
    34  type RBTree[K infra.OrderedKey, V any] interface {
    35  	Len() int64
    36  	Root() RBNode[K, V]
    37  	Insert(key K, val V, ifNotPresent ...bool) error
    38  	Remove(key K) (RBNode[K, V], error)
    39  	RemoveMin() (RBNode[K, V], error)
    40  	Foreach(action func(idx int64, color RBColor, key K, val V) bool)
    41  	Release()
    42  }