github.com/cilium/statedb@v0.3.2/part/ops.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package part
     5  
     6  // Ops is the common operations that can be performed with a Tree
     7  // or Txn.
     8  type Ops[T any] interface {
     9  	// Len returns the number of objects in the tree.
    10  	Len() int
    11  
    12  	// Get fetches the value associated with the given key.
    13  	// Returns the value, a watch channel (which is closed on
    14  	// modification to the key) and boolean which is true if
    15  	// value was found.
    16  	Get(key []byte) (T, <-chan struct{}, bool)
    17  
    18  	// Prefix returns an iterator for all objects that starts with the
    19  	// given prefix, and a channel that closes when any objects matching
    20  	// the given prefix are upserted or deleted.
    21  	Prefix(key []byte) (*Iterator[T], <-chan struct{})
    22  
    23  	// LowerBound returns an iterator for all objects that have a
    24  	// key equal or higher than the given 'key'.
    25  	LowerBound(key []byte) *Iterator[T]
    26  
    27  	// RootWatch returns a watch channel for the root of the tree.
    28  	// Since this is the channel associated with the root, this closes
    29  	// when there are any changes to the tree.
    30  	RootWatch() <-chan struct{}
    31  
    32  	// Iterator returns an iterator for all objects.
    33  	Iterator() *Iterator[T]
    34  
    35  	// PrintTree to the standard output. For debugging.
    36  	PrintTree()
    37  }
    38  
    39  var (
    40  	_ Ops[int] = &Tree[int]{}
    41  	_ Ops[int] = &Txn[int]{}
    42  )