ds

package module
v0.0.0-...-d2aafa2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 8 Imported by: 5

README

ds

Common data structures for golang

References

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBClosed    = errors.New("queue: database is closed")
	ErrEmpty       = errors.New("queue: queue is empty")
	ErrOutOfBounds = errors.New("queue: ID is outside range of queue")
)

Functions

This section is empty.

Types

type CompareFunc

type CompareFunc func(interface{}, interface{}) int

type Item

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

func (*Item) ToObject

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

func (*Item) ToString

func (i *Item) ToString() string

type Queue

type Queue struct {
	sync.RWMutex
	DataDir string
	// contains filtered or unexported fields
}

Standard FIFO (fist in, first out) queue

func OpenQueue

func OpenQueue(dataDir string) (*Queue, error)

func (*Queue) Close

func (q *Queue) Close() error

func (*Queue) Dequeue

func (q *Queue) Dequeue() (*Item, error)

func (*Queue) Drop

func (q *Queue) Drop() error

func (*Queue) Enqueue

func (q *Queue) Enqueue(value []byte) (*Item, error)

func (*Queue) EnqueueObject

func (q *Queue) EnqueueObject(value interface{}) (*Item, error)

func (*Queue) EnqueueString

func (q *Queue) EnqueueString(value string) (*Item, error)

func (*Queue) Length

func (q *Queue) Length() uint64

func (*Queue) Peek

func (q *Queue) Peek() (*Item, error)

type SortedList

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

func NewSortedList

func NewSortedList(compare CompareFunc) *SortedList

func (*SortedList) Back

func (l *SortedList) Back() *list.Element

func (*SortedList) Clear

func (l *SortedList) Clear()

func (*SortedList) Front

func (l *SortedList) Front() *list.Element

func (*SortedList) Insert

func (l *SortedList) Insert(item interface{})

Only Search from front to end, optimized for from end to front

func (*SortedList) Len

func (l *SortedList) Len() int64

func (*SortedList) Remove

func (l *SortedList) Remove(e *list.Element) interface{}

type Stack

type Stack struct {
	sync.RWMutex
	DataDir string
	// contains filtered or unexported fields
}

Stack is a standard LIFO (last in, first out) stack.

func OpenStack

func OpenStack(dataDir string) (*Stack, error)

OpenStack opens a stack if one exists at the given directory. If one does not already exist, a new stack is created.

func (*Stack) Close

func (s *Stack) Close() error

Close closes the LevelDB database of the stack.

func (*Stack) Drop

func (s *Stack) Drop() error

Drop closes and deletes the LevelDB database of the stack.

func (*Stack) Length

func (s *Stack) Length() uint64

Length returns the total number of items in the stack.

func (*Stack) Peek

func (s *Stack) Peek() (*Item, error)

Peek returns the next item in the stack without removing it.

func (*Stack) PeekByID

func (s *Stack) PeekByID(id uint64) (*Item, error)

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

func (*Stack) PeekByOffset

func (s *Stack) PeekByOffset(offset uint64) (*Item, error)

PeekByOffset returns the item located at the given offset, starting from the head of the stack, without removing it.

func (*Stack) Pop

func (s *Stack) Pop() (*Item, error)

Pop removes the next item in the stack and returns it.

func (*Stack) Push

func (s *Stack) Push(value []byte) (*Item, error)

Push adds an item to the stack.

func (*Stack) PushObject

func (s *Stack) PushObject(value interface{}) (*Item, error)

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

func (*Stack) PushString

func (s *Stack) PushString(value string) (*Item, error)

PushString is a helper function for Push that accepts a value as a string rather than a byte slice.

func (*Stack) Update

func (s *Stack) Update(id uint64, newValue []byte) (*Item, error)

Update updates an item in the stack without changing its position.

func (*Stack) UpdateObject

func (s *Stack) UpdateObject(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.

func (*Stack) UpdateString

func (s *Stack) UpdateString(id uint64, newValue string) (*Item, error)

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

Jump to

Keyboard shortcuts

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