queue

package
v0.0.0-...-e30b66f Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrEmpty is returned when the stack or queue is empty.
	ErrEmpty = errors.New("queue is empty")

	// ErrOutOfBounds is returned when the ID used to lookup an item
	// is outside of the range of the stack or queue.
	ErrOutOfBounds = errors.New("ID used is outside range of queue")

	// ErrDBClosed is returned when the Close function has already
	// been called, causing the stack or queue to close, as well as
	// its underlying database.
	ErrDBClosed = errors.New("Database is closed")
)

Functions

This section is empty.

Types

type Item

type Item struct {
	ID    uint64
	Key   []byte
	Value []byte
}

Item represents an entry in either a stack or queue.

func (*Item) ToObject

func (i *Item) ToObject(value interface{}) error

ToObject decodes the item value into the given value type using encoding/gob.

The value passed to this method should be a pointer to a variable of the type you wish to decode into. The variable pointed to will hold the decoded object.

Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you should only use this function to decode simple types.

func (*Item) ToObjectFromJSON

func (i *Item) ToObjectFromJSON(value interface{}) error

ToObjectFromJSON decodes the item value into the given value type using encoding/json.

The value passed to this method should be a pointer to a variable of the type you wish to decode into. The variable pointed to will hold the decoded object.

func (*Item) ToString

func (i *Item) ToString() string

ToString returns the item value as a string.

type PrefixQueue

type PrefixQueue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PrefixQueue is a standard FIFO (first in, first out) queue that separates each given prefix into its own queue.

func OpenPrefixQueue

func OpenPrefixQueue(db *leveldb.DB) (*PrefixQueue, error)

OpenPrefixQueue opens a prefix queue if one exists at the given directory. If one does not already exist, a new prefix queue is created.

func (*PrefixQueue) Close

func (pq *PrefixQueue) Close() error

Close closes the LevelDB database of the prefix queue.

func (*PrefixQueue) Dequeue

func (pq *PrefixQueue) Dequeue(prefix []byte) (*Item, error)

Dequeue removes the next item in the prefix queue and returns it.

func (*PrefixQueue) DequeueString

func (pq *PrefixQueue) DequeueString(prefix string) (*Item, error)

DequeueString is a helper function for Dequeue that accepts the prefix as a string rather than a byte slice.

func (*PrefixQueue) Enqueue

func (pq *PrefixQueue) Enqueue(prefix, value []byte) (*Item, error)

Enqueue adds an item to the queue.

func (*PrefixQueue) EnqueueObject

func (pq *PrefixQueue) EnqueueObject(prefix []byte, value interface{}) (*Item, error)

EnqueueObject is a helper function for Enqueue that accepts any value type, which is then encoded into a byte slice using encoding/gob.

Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you should only use this function to encode simple types.

func (*PrefixQueue) EnqueueObjectAsJSON

func (pq *PrefixQueue) EnqueueObjectAsJSON(prefix []byte, value interface{}) (*Item, error)

EnqueueObjectAsJSON is a helper function for Enqueue that accepts any value type, which is then encoded into a JSON byte slice using encoding/json.

Use this function to handle encoding of complex types.

func (*PrefixQueue) EnqueueString

func (pq *PrefixQueue) EnqueueString(prefix, value string) (*Item, error)

EnqueueString is a helper function for Enqueue that accepts the prefix and value as a string rather than a byte slice.

func (*PrefixQueue) Length

func (pq *PrefixQueue) Length() uint64

Length returns the total number of items in the prefix queue.

func (*PrefixQueue) Peek

func (pq *PrefixQueue) Peek(prefix []byte) (*Item, error)

Peek returns the next item in the given queue without removing it.

func (*PrefixQueue) PeekByID

func (pq *PrefixQueue) PeekByID(prefix []byte, id uint64) (*Item, error)

PeekByID returns the item with the given ID without removing it.

func (*PrefixQueue) PeekByIDString

func (pq *PrefixQueue) PeekByIDString(prefix string, id uint64) (*Item, error)

PeekByIDString is a helper function for Peek that accepts the prefix as a string rather than a byte slice.

func (*PrefixQueue) PeekString

func (pq *PrefixQueue) PeekString(prefix string) (*Item, error)

PeekString is a helper function for Peek that accepts the prefix as a string rather than a byte slice.

func (*PrefixQueue) Update

func (pq *PrefixQueue) Update(prefix []byte, id uint64, newValue []byte) (*Item, error)

Update updates an item in the given queue without changing its position.

func (*PrefixQueue) UpdateObject

func (pq *PrefixQueue) UpdateObject(prefix []byte, id uint64, newValue interface{}) (*Item, error)

UpdateObject is a helper function for Update that accepts any value type, which is then encoded into a byte slice using encoding/gob.

Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you should only use this function to encode simple types.

func (*PrefixQueue) UpdateObjectAsJSON

func (pq *PrefixQueue) UpdateObjectAsJSON(prefix []byte, id uint64, newValue interface{}) (*Item, error)

UpdateObjectAsJSON is a helper function for Update that accepts any value type, which is then encoded into a JSON byte slice using encoding/json.

Use this function to handle encoding of complex types.

func (*PrefixQueue) UpdateString

func (pq *PrefixQueue) UpdateString(prefix string, id uint64, value string) (*Item, error)

UpdateString is a helper function for Update that accepts the prefix and value as a string rather than a byte slice.

type PriorityItem

type PriorityItem struct {
	ID       uint64
	Priority uint8
	Key      []byte
	Value    []byte
}

PriorityItem represents an entry in a priority queue.

func (*PriorityItem) ToObject

func (pi *PriorityItem) ToObject(value interface{}) error

ToObject decodes the item value into the given value type using encoding/gob.

The value passed to this method should be a pointer to a variable of the type you wish to decode into. The variable pointed to will hold the decoded object.

Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you should only use this function to decode simple types.

func (*PriorityItem) ToObjectFromJSON

func (pi *PriorityItem) ToObjectFromJSON(value interface{}) error

ToObjectFromJSON decodes the item value into the given value type using encoding/json.

The value passed to this method should be a pointer to a variable of the type you wish to decode into. The variable pointed to will hold the decoded object.

func (*PriorityItem) ToString

func (pi *PriorityItem) ToString() string

ToString returns the priority item value as a string.

Jump to

Keyboard shortcuts

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