Documentation ¶
Index ¶
- Constants
- Variables
- func MatchLevel(level *Level, tokens []string, ret *sublistResult)
- func SplitSubject(subject string, cache []string) ([]string, bool)
- func ValidSubject(subject string) bool
- type ICall
- type ISet
- type ISublist
- type ITransformSet
- type Level
- type LevelCache
- type MixSet
- type MultiSublist
- type Node
- type Opt
- type Set
- type SliceSet
- func (s *SliceSet[T]) Add(e ...T)
- func (s *SliceSet[T]) AppendToSlice(slice []T) []T
- func (s *SliceSet[T]) Clear()
- func (s *SliceSet[T]) Contains(e T) bool
- func (s *SliceSet[T]) Len() int
- func (s *SliceSet[T]) Range(f func(e T) bool)
- func (s *SliceSet[T]) Remove(e ...T)
- func (s *SliceSet[T]) Transform() ITransformSet[T]
- type Snmp
- type Sublist
- type Subscription
- type Var
Constants ¶
const ( TSep = "." BtSep = '.' )
const ( PListCacheMin = 128 // build a quick cache when the number of subscriptions is greater than this value StackCacheSize = 32 // normal stack cache size )
const ( InitNodeSubCache = 16 InitLevelNodeCache = 16 )
Variables ¶
var ( ErrInvalidSubject = errors.New("sublist: invalid subject") ErrSublistNil = errors.New("sublist: sublist is nil") ErrNotFound = errors.New("sublist: not found") ErrSlowConsumer = errors.New("subjection: slow consumer") )
var Default = NewMultiBus(32)
Default is the default multi-sublist.
Functions ¶
func SplitSubject ¶
SplitSubject splits the subject into tokens.
func ValidSubject ¶
ValidSubject returns true if the subject is valid.
Types ¶
type ICall ¶
type ICall interface {
// contains filtered or unexported methods
}
type ISet ¶
type ISet[T comparable] interface { Add(e ...T) Remove(e ...T) Contains(e T) bool Len() int AppendToSlice(slice []T) []T Clear() Range(f func(e T) bool) }
ISet is a set interface.
type ISublist ¶
type ISublist interface { Subscribe(sub *Subscription) error Publish(subject string, param any) error Unsubscribe(sub *Subscription) error UnsubscribeBatch(subs []*Subscription) error SnmpInfo() *Snmp }
type ITransformSet ¶
type ITransformSet[T comparable] interface { ISet[T] Transform() ITransformSet[T] }
ITransformSet is a set interface that can transform to another set.
type LevelCache ¶
type MixSet ¶
type MixSet[T comparable] struct{ ITransformSet[T] }
MixSet is a set that uses a slice for small sets and a map for large sets.
func InitMixSet ¶
func InitMixSet[T comparable]() MixSet[T]
InitMixSet creates a new set with an initial capacity.
func (*MixSet[T]) Remove ¶
func (s *MixSet[T]) Remove(e ...T)
Remove removes an element from the set.
func (*MixSet[T]) Transform ¶
func (s *MixSet[T]) Transform() ITransformSet[T]
Transform transforms the set to a map if the size is greater than mixSetMaxSliceSize. or to a slice if the size is less than mixSetMinMapSize.
type MultiSublist ¶
type MultiSublist struct {
// contains filtered or unexported fields
}
func NewMultiBus ¶
func NewMultiBus(length uint) *MultiSublist
func (*MultiSublist) Publish ¶
func (m *MultiSublist) Publish(subject string, param any) error
Publish
func (*MultiSublist) Subscribe ¶
func (m *MultiSublist) Subscribe(sub *Subscription) error
Subscribe
func (*MultiSublist) Unsubscribe ¶
func (m *MultiSublist) Unsubscribe(subs *Subscription) error
Unsubscribe
func (*MultiSublist) UnsubscribeBatch ¶
func (m *MultiSublist) UnsubscribeBatch(subs []*Subscription) error
UnsubscribeBatch
type Node ¶
type Node struct { Next *Level // next level Psubs ISet[*Subscription] // original set Plist []*Subscription // cache list }
type Set ¶
type Set[T comparable] map[T]struct{}
func NewSet ¶
func NewSet[T comparable](cache uint) Set[T]
func NewSetNoCache ¶
func NewSetNoCache[T comparable]() Set[T]
func (Set[T]) AppendToSlice ¶
func (s Set[T]) AppendToSlice(slice []T) []T
AppendToSlice appends the elements in the set to a slice.
func (Set[T]) Transform ¶
func (s Set[T]) Transform() ITransformSet[T]
Transform transforms the set to a slice if the size is less than mixSetMinMapSize.
type SliceSet ¶
type SliceSet[T comparable] struct { // contains filtered or unexported fields }
func (*SliceSet[T]) AppendToSlice ¶
func (s *SliceSet[T]) AppendToSlice(slice []T) []T
AppendToSlice appends the elements in the set to a slice.
func (*SliceSet[T]) Remove ¶
func (s *SliceSet[T]) Remove(e ...T)
Remove removes an element from the set.
func (*SliceSet[T]) Transform ¶
func (s *SliceSet[T]) Transform() ITransformSet[T]
transform transforms the set to a map if the size is greater than mixSetMaxSliceSize.
type Sublist ¶
type Sublist struct { Snmp // contains filtered or unexported fields }
func (*Sublist) Subscribe ¶
func (s *Sublist) Subscribe(sub *Subscription) error
Subscribe adds the subscription into the sublist.
func (*Sublist) Unsubscribe ¶
func (s *Sublist) Unsubscribe(sub *Subscription) error
func (*Sublist) UnsubscribeBatch ¶
func (s *Sublist) UnsubscribeBatch(subs []*Subscription) error
UnsubscribeBatch
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}