collection

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDuration = errors.New("duration must greater than interval")
	ErrInvalidTask     = errors.New("invalid task")
)

Functions

This section is empty.

Types

type Execute

type Execute func(ID string)

type Option

type Option func(tw *TimingWheel)

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

A Queue is a FIFO queue.

func NewQueue

func NewQueue[T any](size int) *Queue[T]

NewQueue returns a Queue object.

func (*Queue[T]) Empty

func (q *Queue[T]) Empty() bool

Empty checks if q is empty.

func (*Queue[T]) Put

func (q *Queue[T]) Put(element T)

Put puts element into q at the last position.

func (*Queue[T]) Take

func (q *Queue[T]) Take() (T, bool)

Take takes the first element out of q if not empty.

type Ring

type Ring[T any] struct {
	// contains filtered or unexported fields
}

A Ring can be used as fixed size ring.

func NewRing

func NewRing[T any](n int) *Ring[T]

NewRing returns a Ring object with the given size n.

func (*Ring[T]) Add

func (r *Ring[T]) Add(v T)

Add adds v into r.

func (*Ring[T]) Take

func (r *Ring[T]) Take() []T

Take takes all items from r.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable]() *Set[T]

NewSet init Set

func (*Set[T]) Add

func (s *Set[T]) Add(key ...T)

Add a new key

func (*Set[T]) Count

func (s *Set[T]) Count() int

Count returns element count

func (*Set[T]) Del

func (s *Set[T]) Del(key T)

Del key

func (*Set[T]) Has

func (s *Set[T]) Has(key T) bool

Has returns has key

func (*Set[T]) Values

func (s *Set[T]) Values() []T

Values returns unique keys

type Task

type Task struct {
	ID          string
	ExecuteTime time.Time
	Execute     Execute
	Next        *Task
}

type TimingWheel

type TimingWheel struct {
	// contains filtered or unexported fields
}

func NewTimingWheel

func NewTimingWheel(slots int, tickInterval time.Duration) *TimingWheel

NewTimingWheel creates new TimingWheel

func (*TimingWheel) AddTask

func (tw *TimingWheel) AddTask(ID string, duration time.Duration, execute Execute) error

AddTask adds tasks

func (*TimingWheel) Stop

func (tw *TimingWheel) Stop()

Stop timing wheel

func (*TimingWheel) Wait

func (tw *TimingWheel) Wait() bool

Wait until tw stop

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL