stack

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

stack package provides stack(FILO) feature apis. note not safety in concurrent operation.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

type Stack[E any] struct {
	// contains filtered or unexported fields
}

Stack struct

func NewStack

func NewStack[E any]() *Stack[E]
Example
// event bus send event as FILO mode
eventBus := stack.NewStack[*string]()
fmt.Println(eventBus.IsEmpty())

eventBus.Push(conv.ToPtr("Sig No 109"))
eventBus.Push(conv.ToPtr("Sig No 282"))

fmt.Println(eventBus.Size())
fmt.Println(*eventBus.Pop())
fmt.Println(*eventBus.Pop())
Output:

true
2
Sig No 282
Sig No 109

func NewStackSize

func NewStackSize[E any](initSize int) *Stack[E]
Example
// event bus send event as FILO mode
eventBus := stack.NewStackSize[*string](10)
fmt.Println(eventBus.IsEmpty())

eventBus.Push(conv.ToPtr("Sig No 109"))
eventBus.Push(conv.ToPtr("Sig No 282"))

fmt.Println(eventBus.Size())
fmt.Println(eventBus.Cap())
fmt.Println(*eventBus.Pop())
fmt.Println(*eventBus.Pop())
Output:

true
2
8
Sig No 282
Sig No 109

func (*Stack[E]) Cap

func (s *Stack[E]) Cap() int

Cap return capacity count

func (*Stack[E]) Copy

func (s *Stack[E]) Copy() *Stack[E]

Copy copy to a new stack

func (*Stack[E]) IsEmpty

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

IsEmpty to return if stack has elements

func (*Stack[E]) Pop

func (s *Stack[E]) Pop() (e E)

Pop pop the element from the stack

func (*Stack[E]) Push

func (s *Stack[E]) Push(e E)

Pop push the element into the stack

func (*Stack[E]) Size

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

Size to get stack elements size

Jump to

Keyboard shortcuts

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