ds

package
v0.0.0-...-5ed4748 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 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 CircularQueue

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

CircularQueue implements bounded-size int64 queue. This implementation is NOT goroutine-safe

func NewCircularQueue

func NewCircularQueue(n int) *CircularQueue

NewCircularQueue creates a CircularQueue with size n

func (*CircularQueue) IsEmpty

func (c *CircularQueue) IsEmpty() bool

IsEmpty checks whether circularQueue has remaining slots

func (*CircularQueue) IsFull

func (c *CircularQueue) IsFull() bool

IsFull checks whether circularQueue has no remaining slots

func (*CircularQueue) Pop

func (c *CircularQueue) Pop() (int64, bool)

Pop one item from circularQueue. Also returns whether it returns a dummy or not

func (*CircularQueue) Push

func (c *CircularQueue) Push(n int64) bool

Push n into circularQueue. Returns whether the push success or not (because of full)

type OrderedMap

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

OrderedMap is a map with a slice combined into a single api used as a priority queue with fast lookup API

we can use slice/array internally because the expected inflight retrived task should be small and the task tracker size is relatively small using an array would reduce unnecessary cache miss from a skiplist/b-tree

this implementation is NOT goroutine-safe

func NewOrderedMap

func NewOrderedMap(secondsToExpire int64) *OrderedMap

NewOrderedMap returns a default orderedMap API

func (*OrderedMap) Delete

func (op *OrderedMap) Delete(key string)

Delete the key from the orderedmap also remove it from array by scanning it

func (*OrderedMap) Get

func (op *OrderedMap) Get(key string) (*PqItem, bool)

Get the item from the orderedmap

func (*OrderedMap) Insert

func (op *OrderedMap) Insert(key string, item *PqItem)

Insert the item into the orderedmap also tracks with its expire time each item will be expired `secondsToExpire` from insertion time

func (*OrderedMap) Length

func (op *OrderedMap) Length() int

Length / number of items in the orderedmap

func (*OrderedMap) PeekExpire

func (op *OrderedMap) PeekExpire() int64

PeekExpire an item from the frontmost in arr without removing it (if any)

func (*OrderedMap) Pop

func (op *OrderedMap) Pop() (*PqItem, bool)

Pop an item from the frontmost in arr also remove it from the kv (if any)

type PqItem

type PqItem struct {
	ScheduledAt int64
	Key         string
	Value       []byte
	Retries     int16
}

PqItem is our task object

This implementation is NOT thread-safe

type PriorityQueue

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

PriorityQueue is our main priority queue implementation the sort order is determined by ScheduledAt with smaller value returned earlier

This implementation is NOT thread-safe

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

NewPriorityQueue setups our priorityqueue with the config

func (*PriorityQueue) HeapSize

func (m *PriorityQueue) HeapSize() int

HeapSize returns our priorityqueue size

func (*PriorityQueue) Insert

func (m *PriorityQueue) Insert(item *PqItem) error

Insert an item into the priorityqueue and reorder its internal

in theory, if the later work always scheduled earlier this gonna be bit slower, cause lots of swapping (log2(m.HeapSize()))

func (*PriorityQueue) Peek

func (m *PriorityQueue) Peek() *PqItem

Peek returns one item from the priorityqueue but not removing it

func (*PriorityQueue) Pop

func (m *PriorityQueue) Pop() *PqItem

Pop returns one item from the priorityqueue and removing it

type SkipList

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

SkipList is our skiplist implementation This API does not implement batch retrieval rather, more like skiplist-based priority queue

This implementation is NOT thread-safe

func (*SkipList) Delete

func (sl *SkipList) Delete(key string)

Delete our SlItem to the skiplist at the same time, also manage all the pointer

func (*SkipList) Insert

func (sl *SkipList) Insert(key string)

Insert our SlItem to the skiplist at the same time, also manage all the pointer

func (*SkipList) Pop

func (sl *SkipList) Pop() (string, bool)

Pop the earliest item in the skiplist, in our case, the most front

type SlItem

type SlItem struct {
	Key string
	// contains filtered or unexported fields
}

SlItem represents our skiplist node

This implementation is NOT thread-safe

Jump to

Keyboard shortcuts

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