gitee.com/lh-her-team/common@v1.5.1/birdsnest/interface.go (about)

     1  // Package birdsnest interface
     2  package birdsnest
     3  
     4  type Serializer interface {
     5  	Serialize() error
     6  	Deserialize() error
     7  }
     8  
     9  // BirdsNest Bird's Nest
    10  type BirdsNest interface {
    11  	GetHeight() uint64
    12  	SetHeight(height uint64)
    13  	// Add the key
    14  	Add(key Key) error
    15  	// Adds adding Multiple Keys
    16  	Adds(keys []Key) (result error)
    17  	// AddsAndSetHeight Adds and SetHeight
    18  	AddsAndSetHeight(keys []Key, height uint64) (result error)
    19  	// Contains the key
    20  	Contains(key Key, rules ...RuleType) (bool, error)
    21  	ValidateRule(key Key, rules ...RuleType) error
    22  	// Info Current cuckoos nest information and status
    23  	Info() []uint64
    24  	Start()
    25  }
    26  
    27  type CuckooFilter interface {
    28  	IsFull() bool
    29  	Add(key Key) (bool, error)
    30  	Contains(key Key) (bool, error)
    31  	Encode() (FilterEncoder, error)
    32  	Extension() FilterExtension
    33  	Info() []uint64
    34  }
    35  
    36  // FilterExtension filter extension
    37  type FilterExtension interface {
    38  	// Validate validate key
    39  	Validate(key Key, full bool) error
    40  	Store(key Key) error
    41  	Serialize() []byte
    42  }
    43  
    44  type Snapshot interface {
    45  	Write(data []byte) error
    46  	Read() ([]byte, error)
    47  }
    48  
    49  type Logger interface {
    50  	Debugf(format string, args ...interface{})
    51  	Errorf(format string, args ...interface{})
    52  	Infof(format string, args ...interface{})
    53  	Warnf(format string, args ...interface{})
    54  }
    55  
    56  // BirdsNestSerialize Bird's nest serialize
    57  type BirdsNestSerialize struct {
    58  	// Bird's Nest config
    59  	Config *BirdsNestConfig `protobuf:"bytes,1,opt,name=config,proto3" json:"config,omitempty"`
    60  	// The final height
    61  	Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"`
    62  	// current index
    63  	CurrentIndex uint32 `protobuf:"varint,3,opt,name=currentIndex,proto3" json:"currentIndex,omitempty"`
    64  	// A group of cuckoos filter
    65  	Filters []*CuckooFilterSerialize `protobuf:"bytes,4,rep,name=filters,proto3" json:"filters,omitempty"`
    66  }
    67  
    68  type CuckooFilterSerialize struct {
    69  	// The field "cuckoo" is used to hold the serialized data of the cuckoo
    70  	// Pb limit: The size of bytes cannot be larger than 4 GB
    71  	Cuckoo []byte `protobuf:"bytes,1,opt,name=cuckoo,proto3" json:"cuckoo,omitempty"`
    72  	// Carries the ID of the time
    73  	Extension []byte `protobuf:"bytes,2,opt,name=extension,proto3" json:"extension,omitempty"`
    74  	// cuckoo configuration
    75  	Config []byte `protobuf:"bytes,3,opt,name=config,proto3" json:"config,omitempty"`
    76  }