eq

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.2.0

type Config struct {
	// TTL specifies the TTL of an item in the queue. While performing
	// Set operation the TTL will be checked for items in the bottom
	// of the queue. CleanN operation also relies on this setting. If
	// zero, no limit will be imposed on the queue.
	TTL time.Duration

	// MaxItems specifies max number of keys to store in the queue. If
	// there is more than MaxItems in a queue, Set operation will
	// expire the item in the bottom of the queue. If zero, no limit
	// will be imposed on the queue. CleanN also respects this
	// setting.
	MaxItems int

	// BackScan specifies maximum items will be scanned from bottom
	// to the top until non-expiring item will be met. All items found
	// are to be removed as expired on Set operation. Zero value is
	// the same as 1.
	BackScan int
}

Config describes various settings of the ExpireQueue.

type Cursor added in v1.2.0

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

Cursor points to specific element of the queue.

func (*Cursor) Delete added in v1.2.0

func (c *Cursor) Delete() Cursor

Delete removes current key/value and returns a cursor right after given one of Nil element if it doesn't exist.

func (*Cursor) Get added in v1.2.0

func (c *Cursor) Get(k interface{}) Cursor

Get jumps to the cursor of the given key.

func (*Cursor) IsExpired added in v1.2.0

func (c *Cursor) IsExpired(now time.Time) bool

IsExpired tells if the cursor has expired key-value relative to given timestamp.

func (*Cursor) IsNil added in v1.2.0

func (c *Cursor) IsNil() bool

IsNil tells if the cursor is a Nil element, i.e. not related to actual key/value in the queue.

func (*Cursor) KeyValue added in v1.2.0

func (c *Cursor) KeyValue() (k, v interface{})

KeyValue returns key-value pair under the cursor.

func (*Cursor) MoveToFront added in v1.2.0

func (c *Cursor) MoveToFront(t time.Time) Cursor

MoveToFront updates timestamp in cursor to specified value and moves it up front.

func (*Cursor) Next added in v1.2.0

func (c *Cursor) Next() Cursor

Next moves cursor to the back of the queue by one step.

func (*Cursor) Prev added in v1.2.0

func (c *Cursor) Prev() Cursor

Prev moves cursor to the top of the queue by one step.

func (*Cursor) Set added in v1.2.0

func (c *Cursor) Set(v interface{})

Set sets new value for the key under the cursor. No timestamp change involved.

type ExpireQueue

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

ExpireQueue implements basic Get/Set map operations in a form of a priority queue.

func New

func New(ttl time.Duration) *ExpireQueue

New is a shortcut for NewWithOpts with BackScan set to 1 and MaxItems set to 0.

func NewWithOpts added in v1.2.0

func NewWithOpts(c *Config) *ExpireQueue

NewWithOpts return new instance of ExpireQueue with specified options.

func (*ExpireQueue) Back added in v1.2.0

func (q *ExpireQueue) Back() Cursor

Back returns rear element of the queue.

func (*ExpireQueue) CleanN

func (q *ExpireQueue) CleanN(n int)

CleanN tries to pop up to n tail elements if they're expired.

func (*ExpireQueue) Count

func (q *ExpireQueue) Count() int

Count returns number of elements in the queue.

func (*ExpireQueue) Delete added in v1.2.0

func (q *ExpireQueue) Delete(k interface{})

Delete removes key and value.

func (*ExpireQueue) Front added in v1.2.0

func (q *ExpireQueue) Front() Cursor

Front returns front element of the queue.

func (*ExpireQueue) Get

func (q *ExpireQueue) Get(k interface{}) (interface{}, bool)

Get retrives value by key.

func (*ExpireQueue) IsFull added in v1.2.0

func (q *ExpireQueue) IsFull() bool

IsFull tells if the queue if full, i.e. its length is at the max.

func (*ExpireQueue) NewCursor added in v1.2.0

func (q *ExpireQueue) NewCursor(k interface{}) Cursor

NewCursor creates a cursor at the specified key. If corresponding element doesn't exist return Nil element.

func (*ExpireQueue) Push added in v1.2.0

func (q *ExpireQueue) Push(k, v interface{}, t time.Time, c *Cursor)

Push inserts new element at the top of the queue with given key/value pair, timestamp and a cursor from this queue which may be substituted. The reusing of the cursor relieves pressure on GC.

func (*ExpireQueue) Set

func (q *ExpireQueue) Set(k, v interface{})

Set sets key and value in a queue.

func (*ExpireQueue) SetTTL added in v1.2.0

func (q *ExpireQueue) SetTTL(ttl time.Duration)

SetTTL specifies new TTL for entries.

type TimeChanSource added in v1.2.0

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

func NewTimeChanSource added in v1.2.0

func NewTimeChanSource(res time.Duration) *TimeChanSource

func (*TimeChanSource) Now added in v1.2.0

func (ts *TimeChanSource) Now() time.Time

type TimeDeferSource added in v1.2.0

type TimeDeferSource struct {
	N int
	// contains filtered or unexported fields
}

func (*TimeDeferSource) Now added in v1.2.0

func (ts *TimeDeferSource) Now() time.Time

type TimeNativeSource added in v1.2.0

type TimeNativeSource struct{}

func (*TimeNativeSource) Now added in v1.2.0

func (ts *TimeNativeSource) Now() time.Time

type TimeSource

type TimeSource interface {
	Now() time.Time
}

Jump to

Keyboard shortcuts

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