filo

package module
v0.0.0-...-6e7a60a Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: ISC Imports: 1 Imported by: 0

README

FILO

  • A First In Last Out infinitly growable and concurrent Memory stack (channels alternative) for Golang.

Features

  • Concurrency-safe.
  • Infinite, no size limit of the data stored in the stack.
  • Can be used where FILO model is needed rather than FIFO (The default model found Channels).
  • Generic stack for complex types.
  • Special stack for string, float64 and int type.

Installation

  • Use the go get as go get github.com/coderme/filo
  • Or clone this repo into $GOPATH/github.com/coderme

Usage

  • Import the pkg import "github.com/coderme/filo"

License

  • See LICENSE.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Float64Stack

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

Float64Stack integer stack first in last out safe for concurrent usage

Example
stack := NewFloat64Stack()
data := []float64{
	1.3,
	2.3,
	3.3,
}

for _, d := range data {
	stack.Push(d)
}

for stack.Len() > 0 {
	fmt.Println(stack.Pop())
}
Output:

3.3
2.3
1.3

func NewFloat64Stack

func NewFloat64Stack() *Float64Stack

NewFloat64Stack creates new IntStack

func (*Float64Stack) Len

func (f *Float64Stack) Len() int

Len gets the number of items pushed into the stack

func (*Float64Stack) Pop

func (f *Float64Stack) Pop() float64

Pop pops the last string from the stack

func (*Float64Stack) Push

func (f *Float64Stack) Push(j float64)

Push pushes new item to the stack

type GenericStack

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

GenericStack stack first in last out safe for concurrent usage

Example
stack := NewGenericStack()
data := []interface{}{
	1,
	"a",
	true,
	nil,
	'b',
	[]string{
		"g",
		"o",
	},
	[]int{
		10,
		20,
		30,
	},
}

for _, d := range data {
	stack.Push(d)
}

for stack.Len() > 0 {
	fmt.Println(stack.Pop())
}
Output:

[10 20 30]
[g o]
98
<nil>
true
a
1

func NewGenericStack

func NewGenericStack() *GenericStack

NewGenericStack creates new GenericStack

func (*GenericStack) Len

func (g *GenericStack) Len() int

Len gets the number of items pushed into the stack

func (*GenericStack) Pop

func (g *GenericStack) Pop() interface{}

Pop pops the last interface{} from the stack

func (*GenericStack) Push

func (g *GenericStack) Push(j interface{})

Push pushes new interface{} to the stack

type IntStack

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

IntStack integer stack first in last out safe for concurrent usage

Example
stack := NewIntStack()
data := []int{
	1,
	2,
	3,
}

for _, d := range data {
	stack.Push(d)
}

for stack.Len() > 0 {
	fmt.Println(stack.Pop())
}
Output:

3
2
1

func NewIntStack

func NewIntStack() *IntStack

NewIntStack creates new IntStack

func (*IntStack) Len

func (i *IntStack) Len() int

Len gets the number of items pushed into the stack

func (*IntStack) Pop

func (i *IntStack) Pop() int

Pop pops the last string from the stack

func (*IntStack) Push

func (i *IntStack) Push(j int)

Push pushes new item to the stack

type StringStack

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

StringStack stack first in last out safe for concurrent usage

Example
stack := NewStringStack()
data := []string{
	"a",
	"b",
	"c",
}

for _, d := range data {
	stack.Push(d)
}

for stack.Len() > 0 {
	fmt.Println(stack.Pop())
}
Output:

c
b
a

func NewStringStack

func NewStringStack() *StringStack

NewStringStack creates new StringStack

func (*StringStack) Len

func (s *StringStack) Len() int

Len gets the number of items pushed into the stack

func (*StringStack) Pop

func (s *StringStack) Pop() string

Pop pops the last string from the stack

func (*StringStack) Push

func (s *StringStack) Push(j string)

Push pushes new item to the stack

Jump to

Keyboard shortcuts

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