gg_collections

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List added in v0.2.111

type List[T any] struct {
	Data    []T  `json:"data"`     // list data
	MaxSize int  `json:"max_size"` // max size of the list
	FIFO    bool `json:"fifo"`     // first in - first out
	// contains filtered or unexported fields
}

List is a generic container that stores elements of any type T. It supports a maximum size and can operate as a FIFO r LIFO. Elements are stored in a slice, and access to the container is synchronized using a mutex to ensure thread safety. LIFO mode is default (Last In - First Out). Order of elements depends on "FIFO" or "LIFO" mode. If "LIFO", this object works as a normal array (stack) where items are appended at the end with Push() method. If "FIFO", this object works as a reversed array (queue) where items are inserted into first place with Push().

func NewList added in v0.2.111

func NewList[T any](maxSize int) (response *List[T])

func NewListFIFO added in v0.2.111

func NewListFIFO[T any](maxSize int) (response *List[T])

func NewListLIFO added in v0.2.111

func NewListLIFO[T any](maxSize int) (response *List[T])

func (*List[T]) Clear added in v0.3.6

func (instance *List[T]) Clear() *List[T]

func (*List[T]) Decode added in v0.2.111

func (instance *List[T]) Decode(byteData []byte) (err error)

func (*List[T]) Encode added in v0.2.111

func (instance *List[T]) Encode() (response []byte, err error)

func (*List[T]) First added in v0.2.111

func (instance *List[T]) First() (response T)

func (*List[T]) For added in v0.2.111

func (instance *List[T]) For(callback func(item T, index int, arr []T) error)

func (*List[T]) Get added in v0.2.111

func (instance *List[T]) Get(index int) (response T)

func (*List[T]) GetFIFO added in v0.2.111

func (instance *List[T]) GetFIFO() (response bool)

func (*List[T]) GetLIFO added in v0.2.111

func (instance *List[T]) GetLIFO() (response bool)

func (*List[T]) Insert added in v0.2.111

func (instance *List[T]) Insert(index int, items ...T)

func (*List[T]) Items added in v0.2.111

func (instance *List[T]) Items() (response []T)

func (*List[T]) Last added in v0.2.111

func (instance *List[T]) Last() (response T)

func (*List[T]) Len added in v0.2.111

func (instance *List[T]) Len() (response int)

func (*List[T]) LoadFromFile added in v0.2.111

func (instance *List[T]) LoadFromFile(filename string) (err error)

func (*List[T]) Map added in v0.2.111

func (instance *List[T]) Map(callback func(item T, index int, arr []T) (selected T, err error)) (response []T)

func (*List[T]) MapToFile added in v0.2.112

func (instance *List[T]) MapToFile(filename string, callback func(item T, index int, arr []T) (selected T, err error)) (err error)

func (*List[T]) Pop added in v0.2.111

func (instance *List[T]) Pop() (response T)

func (*List[T]) Push added in v0.2.111

func (instance *List[T]) Push(item T) *List[T]

func (*List[T]) Remove added in v0.2.111

func (instance *List[T]) Remove(index int)

func (*List[T]) Reverse added in v0.2.111

func (instance *List[T]) Reverse() *List[T]

func (*List[T]) SaveToFile added in v0.2.111

func (instance *List[T]) SaveToFile(filename string) (err error)

func (*List[T]) SetFIFO added in v0.2.111

func (instance *List[T]) SetFIFO(v bool) *List[T]

func (*List[T]) SetLIFO added in v0.2.111

func (instance *List[T]) SetLIFO(v bool) *List[T]

func (*List[T]) Shuffle added in v0.2.111

func (instance *List[T]) Shuffle() *List[T]

func (*List[T]) Sort added in v0.2.111

func (instance *List[T]) Sort(sortFunc func(a, b T) bool) *List[T]

func (*List[T]) String added in v0.2.111

func (instance *List[T]) String() string

type Queue

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

Queue is a basic FIFO queue based on a circular list that resizes as needed.

func NewQueue

func NewQueue(initialSize int) *Queue

NewQueue is deprecated Deprecated: use List in FIFO mode

func (*Queue) Count

func (instance *Queue) Count() int

func (*Queue) Pop

func (instance *Queue) Pop() interface{}

Pop removes and returns a node from the queue in first to last order.

func (*Queue) Push

func (instance *Queue) Push(value interface{})

Push adds a node to the queue.

type Stack

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

Stack is a basic LIFO stack that resizes as needed. Deprecated: use List in LIFO mode

func NewStack

func NewStack(initialSize int) *Stack

NewStack Deprecated: use List in LIFO mode

func (*Stack) Count

func (instance *Stack) Count() int

func (*Stack) Pop

func (instance *Stack) Pop() interface{}

Pop removes and returns an item from the stack in last to first order.

func (*Stack) Push

func (instance *Stack) Push(value interface{})

Push adds an item to the stack.

Jump to

Keyboard shortcuts

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