queue

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUQueue added in v1.0.1

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

LRUQueue is implementation of LRU.

func NewLRUQueue added in v1.0.1

func NewLRUQueue(capacity int) *LRUQueue

func (*LRUQueue) Delete added in v1.0.1

func (q *LRUQueue) Delete(key string) interface{}

Delete deletes the item by key, return the deleted item if item exists.

func (*LRUQueue) Get added in v1.0.1

func (q *LRUQueue) Get(key string) (interface{}, error)

Get will return the item by key. And it will put the item to front.

func (*LRUQueue) GetFront added in v1.0.1

func (q *LRUQueue) GetFront(count int) []interface{}

GetFront will get several items from front and not poll out them.

func (*LRUQueue) GetItemByKey added in v1.0.1

func (q *LRUQueue) GetItemByKey(key string) (interface{}, error)

GetItemByKey will return the item by key. But it will not put the item to front.

func (*LRUQueue) Put added in v1.0.1

func (q *LRUQueue) Put(key string, data interface{}) (obsoleteKey string, obsoleteData interface{})

Put puts item to front, return the obsolete item

type Queue

type Queue interface {
	// Put puts item into the queue and keeps blocking if the queue is full.
	// It will return immediately and do nothing if the item is nil.
	Put(item interface{})

	// PutTimeout puts item into the queue and waits for timeout if the queue is full.
	// If timeout <= 0, it will return false immediately when queue is full.
	// It will return immediately and do nothing if the item is nil.
	PutTimeout(item interface{}, timeout time.Duration) bool

	// Poll gets an item from the queue and keeps blocking if the queue is empty.
	Poll() interface{}

	// PollTimeout gets an item from the queue and waits for timeout if the queue is empty.
	// If timeout <= 0, it will return (nil, bool) immediately when queue is empty.
	PollTimeout(timeout time.Duration) (interface{}, bool)

	// Len returns the current size of the queue.
	Len() int
}

Queue blocking queue. The items putted into queue mustn't be nil.

func NewQueue

func NewQueue(capacity int) Queue

NewQueue creates a blocking queue. If capacity <= 0, the queue capacity is infinite.

Jump to

Keyboard shortcuts

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