datastructure

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[ITEM any] struct {
	// contains filtered or unexported fields
}

func (*Queue[ITEM]) Dequeue

func (q *Queue[ITEM]) Dequeue() (ITEM, error)

Dequeue implements QueueInterface.

func (*Queue[ITEM]) Enqueue

func (q *Queue[ITEM]) Enqueue(item ITEM) error

Enqueue implements QueueInterface.

func (*Queue[ITEM]) Front

func (q *Queue[ITEM]) Front() (ITEM, error)

Front implements QueueInterface.

func (*Queue[ITEM]) IsEmpty

func (q *Queue[ITEM]) IsEmpty() bool

IsEmpty implements QueueInterface.

func (*Queue[ITEM]) IsFull

func (q *Queue[ITEM]) IsFull() bool

IsFull implements QueueInterface.

func (*Queue[ITEM]) Items

func (q *Queue[ITEM]) Items() []ITEM

Items implements QueueInterface.

func (*Queue[ITEM]) WithMax

func (q *Queue[ITEM]) WithMax(max int) QueueInterface[ITEM]

WithMax implements QueueInterface.

type QueueInterface

type QueueInterface[ITEM any] interface {
	WithMax(max int) QueueInterface[ITEM]
	Enqueue(item ITEM) error
	Dequeue() (ITEM, error)
	IsEmpty() bool
	IsFull() bool
	Front() (ITEM, error)
	Items() []ITEM
}

func NewQueue

func NewQueue[ITEM any]() QueueInterface[ITEM]

type Set

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

func (*Set[E]) Add

func (s *Set[E]) Add(values ...E)

func (*Set[E]) Clear

func (s *Set[E]) Clear()

func (*Set[E]) Del

func (s *Set[E]) Del(values ...E)

func (*Set[E]) DelIf

func (s *Set[E]) DelIf(condition func(value E) bool) SetInterface[E]

func (*Set[E]) Filter added in v0.0.18

func (s *Set[E]) Filter(condition func(value E) bool) SetInterface[E]

func (*Set[E]) Find added in v0.0.19

func (s *Set[E]) Find(condition func(value E) bool) (E, error)

func (*Set[E]) IsEmpty

func (s *Set[E]) IsEmpty() bool

func (*Set[E]) IsExists

func (s *Set[E]) IsExists(value E) bool

func (*Set[E]) Size

func (s *Set[E]) Size() int

func (*Set[E]) Slice

func (s *Set[E]) Slice() []E

type SetInterface

type SetInterface[E comparable] interface {
	// Added list element to set.
	Add(values ...E)

	// To check is element is exists on set.
	IsExists(value E) bool

	// Delete list element of set.
	Del(values ...E)

	// Convert set to slice. Maybe you need it for interation.
	Slice() []E

	// Clear list element from set.
	Clear()

	// Check is set is empty. Return true is empty and false is not empty.
	IsEmpty() bool

	// Get size of element on set.
	Size() int

	// Delete element from set if condition is matched.
	DelIf(condition func(value E) bool) SetInterface[E]

	// Filter elements of set. Will return new set with filtered elements.
	Filter(condition func(value E) bool) SetInterface[E]

	// Find first element in set that matches condition or return error with code `github.com/irdaislakhuafa/go-sdk/codes.CodeNotFound`.
	Find(condition func(value E) bool) (E, error)
}

func NewSet

func NewSet[E comparable](values ...E) SetInterface[E]

Set data type is like `slice` or `array` but without duplicate element and set element is unordered element

Jump to

Keyboard shortcuts

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