queue

package
v0.0.0-...-ddc1a4a Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorQueueEmpty

type ErrorQueueEmpty string

ErrorQueueEmpty represents the error that the queue is empty.

func (ErrorQueueEmpty) Error

func (err ErrorQueueEmpty) Error() string

type MultiLevelList

type MultiLevelList interface {
	// Push method adds taskItem to MultiLevel List
	// it takes input as the level and value as interface{}
	Push(level int, element interface{}) error
	// PushList method adds list to MultiLevel List
	// it takes input as the level and list
	PushList(level int, newlist *list.List) error
	// Pop method removes the Front Item for the given Level
	Pop(level int) (interface{}, error)
	// PeekItem method returns the the Front Item for the given Level
	// It will not remove the item from the list
	PeekItem(level int) (interface{}, error)
	// PeekItems returns a list of items from a given level.
	// The number of items returns is min(limit, number of items in a given level).
	// Its returns an error if there are no items in the level.
	// It does not remove the items from the list.
	PeekItems(level int, limit int) ([]interface{}, error)
	// Remove method removes the specified item from multilevel list
	// It takes level and the value as the input parameter
	// If we have duplicate entry added we will be removing the first entry in the list
	// return value is error if there is any error in removing
	Remove(level int, value interface{}) error
	// RemoveItems method removes the specified items from multilevel list
	// First return value is true/false -> Success/failure
	// Second return value is item list not able to be deleted
	// error is third return value
	// This function returns false if only subset of the items being deleted
	RemoveItems(
		values map[interface{}]bool,
		level int) (bool, map[interface{}]bool, error)
	// IsEmpty method checks if the list for specified level is empty in multilevel list
	IsEmpty(level int) bool
	// Levels returns all the current levels in the list.
	Levels() []int
	// Len returns the number of items in multilevel list for specified level.
	Len(level int) int
	// Size returns the total number of items in multilevel list for all levels
	Size() int
	// GetHighestLevel returns the highest level from the list
	GetHighestLevel() int
}

MultiLevelList holds all the lists with different Level, and a limit on total size of the list. If the limit is negative there is no size limit on the list. The Multi level list is implemented using a map[Level]List. Which holds list per Level. Push operation is O(1) Pop Operation is O(1) Remove Operation is O(m) where m is the list size of specified level RemoveItems Operation is O(m) where m is the list size of specified level

func NewMultiLevelList

func NewMultiLevelList(name string, maxListSize int64) MultiLevelList

NewMultiLevelList initializes the multi level list with a name and a max size, if the max size is negative, then the list will have no size bounds.

type PriorityQueue

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

PriorityQueue is FIFO queue which remove the highest priority task item entered first in the queue

func NewPriorityQueue

func NewPriorityQueue(limit int64) *PriorityQueue

NewPriorityQueue intializes the fifo queue and returns the pointer

func (*PriorityQueue) Dequeue

func (f *PriorityQueue) Dequeue() (*resmgrsvc.Gang, error)

Dequeue dequeues the gang (task list gang) based on the priority and order they came into the queue

func (*PriorityQueue) Enqueue

func (f *PriorityQueue) Enqueue(gang *resmgrsvc.Gang) error

Enqueue queues a gang (task list gang) based on its priority into FIFO queue

func (*PriorityQueue) Len

func (f *PriorityQueue) Len(priority int) int

Len returns the length of the queue for specified priority

func (*PriorityQueue) Peek

func (f *PriorityQueue) Peek(limit uint32) ([]*resmgrsvc.Gang, error)

Peek peeks the limit number of gangs based on the priority and order they came into the queue. It will return an `ErrorQueueEmpty` if there is no gangs in the queue

func (*PriorityQueue) Remove

func (f *PriorityQueue) Remove(gang *resmgrsvc.Gang) error

Remove removes the item from the queue

func (*PriorityQueue) Size

func (f *PriorityQueue) Size() int

Size returns the number of elements in the PriorityQueue

type Queue

type Queue interface {
	// Enqueue queues a gang (task list gang) based on its priority into FIFO queue
	Enqueue(gang *resmgrsvc.Gang) error
	// Dequeue dequeues the gang (task list gang) based on the priority and order
	// they came into the queue
	Dequeue() (*resmgrsvc.Gang, error)
	// Peek peeks the gang(list) based on the priority and order
	// they came into the queue.
	// limit is the number of gangs to peek.
	// It will return an error if there is no gang in the queue
	Peek(limit uint32) ([]*resmgrsvc.Gang, error)
	// Remove removes the item from the queue
	Remove(item *resmgrsvc.Gang) error
	// Size returns the total number of items in the queue
	Size() int
}

Queue is the interface implemented by all the the queues

func CreateQueue

func CreateQueue(policy respool.SchedulingPolicy, limit int64) (Queue, error)

CreateQueue is factory method to create the specified queue

Jump to

Keyboard shortcuts

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