queue

package
v0.0.0-...-a8cc34e Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: LGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpireQueue

type ExpireQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ExpireQueue provides sequential expirations by groups

func NewExpireQueue

func NewExpireQueue() *ExpireQueue

NewExpireQueue returns ExpireQueue

func (*ExpireQueue) AddGroup

func (q *ExpireQueue) AddGroup(interval time.Duration)

AddGroup adds and runs a expire gruop

func (*ExpireQueue) AddHandler

func (q *ExpireQueue) AddHandler(handler ItemExpireHandler)

AddHandler adds a item expire handler

func (*ExpireQueue) Push

func (q *ExpireQueue) Push(key string, item interface{})

Push adds a item to the expiration flow

func (*ExpireQueue) Remove

func (q *ExpireQueue) Remove(key string)

Remove removes a item from the expiration flow

func (*ExpireQueue) Size

func (q *ExpireQueue) Size() int

Size returns a queue size

type ItemExpireHandler

type ItemExpireHandler interface {
	// OnItemExpired is called when the item is expired
	OnItemExpired(interval time.Duration, key string, item interface{}, IsLast bool)
}

ItemExpireHandler handles a group expire event

type LinkedQueue

type LinkedQueue struct {
	sync.Mutex
	Head *linkedItem
	Tail *linkedItem
	// contains filtered or unexported fields
}

LinkedQueue is designed to allow users to remove the item by the key

func NewLinkedQueue

func NewLinkedQueue() *LinkedQueue

NewLinkedQueue make a LinkedQueue

func (*LinkedQueue) Has

func (q *LinkedQueue) Has(Key hash.Hash256) bool

Has returns the key is exist of not

func (*LinkedQueue) Iter

func (q *LinkedQueue) Iter(fn func(keyMap hash.Hash256, v interface{}))

Iter iterates queue items

func (*LinkedQueue) Pop

func (q *LinkedQueue) Pop() interface{}

Pop returns a item at the top of the queue

func (*LinkedQueue) Push

func (q *LinkedQueue) Push(Key hash.Hash256, item interface{}) bool

Push inserts the item with the key at the bottom of the queue

func (*LinkedQueue) Remove

func (q *LinkedQueue) Remove(Key hash.Hash256) interface{}

Remove deletes a item by the key

func (*LinkedQueue) Size

func (q *LinkedQueue) Size() int

Size returns the number of items

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue provides a basic queue ability with the peek method

func NewQueue

func NewQueue() *Queue

NewQueue returns a Queue

func (*Queue) Iter

func (q *Queue) Iter(fn func(v interface{}))

Iter iterates queue items

func (*Queue) Peek

func (q *Queue) Peek() interface{}

Peek fetch the top item without removing it

func (*Queue) Pop

func (q *Queue) Pop() interface{}

Pop returns a item at the top of the queue

func (*Queue) Push

func (q *Queue) Push(item interface{})

Push inserts a item at the bottom of the queue

func (*Queue) Size

func (q *Queue) Size() int

Size returns the number of items

type SortedQueue

type SortedQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SortedQueue sorts items by the priority

func NewSortedQueue

func NewSortedQueue() *SortedQueue

NewSortedQueue returns a SortedQueue

func (*SortedQueue) Find

func (q *SortedQueue) Find(Priority uint64) interface{}

Find fetch the target priority item without removing it

func (*SortedQueue) FindOrInsert

func (q *SortedQueue) FindOrInsert(value interface{}, Priority uint64) interface{}

FindOrInsert finds the item of the priority if it exists or inserts the item by the priority

func (*SortedQueue) Insert

func (q *SortedQueue) Insert(value interface{}, Priority uint64)

Insert inserts the item by the priority

func (*SortedQueue) Iter

func (q *SortedQueue) Iter(fn func(v interface{}, priority uint64))

Iter iterates queue items

func (*SortedQueue) Peek

func (q *SortedQueue) Peek() (interface{}, uint64)

Peek fetch the top item without removing it

func (*SortedQueue) Pop

func (q *SortedQueue) Pop() interface{}

Pop returns a item at the top of the queue

func (*SortedQueue) PopUntil

func (q *SortedQueue) PopUntil(Priority uint64) interface{}

PopUntil returns a item at the top of the queue

func (*SortedQueue) Size

func (q *SortedQueue) Size() int

Size returns the number of items

Jump to

Keyboard shortcuts

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