SkillAgentSearch skills...

Stack

๐Ÿ“š A simple stack implementation in Go

Install / Use

/learn @atomicgo/Stack
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ IMPORTANT NOTE โ”‚ โ”‚ โ”‚ โ”‚ This file is automatically generated โ”‚ โ”‚ All manual modifications will be overwritten โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ --> <h1 align="center">AtomicGo | stack</h1> <p align="center"> <img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Fstack&style=flat-square" alt="Downloads"> <a href="https://github.com/atomicgo/stack/releases"> <img src="https://img.shields.io/github/v/release/atomicgo/stack?style=flat-square" alt="Latest Release"> </a> <a href="https://codecov.io/gh/atomicgo/stack" target="_blank"> <img src="https://img.shields.io/github/actions/workflow/status/atomicgo/stack/go.yml?style=flat-square" alt="Tests"> </a> <a href="https://codecov.io/gh/atomicgo/stack" target="_blank"> <img src="https://img.shields.io/codecov/c/gh/atomicgo/stack?color=magenta&logo=codecov&style=flat-square" alt="Coverage"> </a> <a href="https://codecov.io/gh/atomicgo/stack"> <!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-23-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end --> </a> <a href="https://opensource.org/licenses/MIT" target="_blank"> <img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="License: MIT"> </a> <a href="https://goreportcard.com/report/github.com/atomicgo/stack" target="_blank"> <img src="https://goreportcard.com/badge/github.com/atomicgo/stack?style=flat-square" alt="Go report"> </a> </p>
<p align="center"> <strong><a href="https://pkg.go.dev/atomicgo.dev/stack#section-documentation" target="_blank">Documentation</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></strong> | <strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md" target="_blank">Code of Conduct</a></strong> </p>
<p align="center"> <img src="https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png" alt="AtomicGo"> </p> <p align="center"> <table> <tbody> </tbody> </table> </p> <h3 align="center"><pre>go get atomicgo.dev/stack</pre></h3> <p align="center"> <table> <tbody> </tbody> </table> </p> <!-- gomarkdoc:embed:start --> <!-- Code generated by gomarkdoc. DO NOT EDIT -->

stack

import "atomicgo.dev/stack"

Package stack is a simple implemntation of a stack data structure. It uses generics to make it type safe.

Index

<a name="Stack"></a>

type Stack

Stack is a simple implementation of a stack data structure.

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

<a name="New"></a>

func New

func New[T any]() Stack[T]

New returns a new stack.

package main

import (
	"atomicgo.dev/stack"
)

func main() {
	stack.New[string]()
}

<a name="Stack[T].Clear"></a>

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

Clear removes all items from the stack.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	s.Clear()

	fmt.Println(s)

}

Output

[]

<a name="Stack[T].Contains"></a>

func (*Stack[T]) Contains

func (s *Stack[T]) Contains(item T) bool

Contains returns true if the stack contains the item.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.Contains("Hello"))
	fmt.Println(s.Contains("Foo"))

}

Output

true
false

<a name="Stack[T].IsEmpty"></a>

func (*Stack[T]) IsEmpty

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

IsEmpty returns true if the stack is empty.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.IsEmpty())

	s.Clear()

	fmt.Println(s.IsEmpty())

}

Output

false
true

<a name="Stack[T].Peek"></a>

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

Peek returns the top item of the stack without removing it.

<a name="Stack[T].Pop"></a>

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes an item from the stack and returns it. Panics if the stack is empty. Use PopSafe for safer access to the Stack.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.Pop())
	fmt.Println(s.Pop())

}

Output

World
Hello

<a name="Stack[T].PopSafe"></a>

func (*Stack[T]) PopSafe

func (s *Stack[T]) PopSafe() T

PopSafe removes an item from the stack and returns it. Returns the zero value of the type if the stack is empty. To make this function safe, it uses reflection and is therefore slower than Pop.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.PopSafe())
	fmt.Println(s.PopSafe())
	fmt.Println(s.PopSafe())

}

Output

World
Hello

<a name="Stack[T].Push"></a>

func (*Stack[T]) Push

func (s *Stack[T]) Push(item ...T)

Push adds items to a stack.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s)

}

Output

[Hello World]

<a name="Stack[T].Size"></a>

func (*Stack[T]) Size

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

Size returns the size of the stack.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.Size())

}

Output

2

<a name="Stack[T].String"></a>

func (Stack[T]) String

func (s Stack[T]) String() string
package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.String())

}

Output

[Hello World]

<a name="Stack[T].Values"></a>

func (*Stack[T]) Values

func (s *Stack[T]) Values() []T

Values returns the values of the stack as a slice.

package main

import (
	"fmt"

	"atomicgo.dev/stack"
)

func main() {
	s := stack.New[string]()
	s.Push("Hello")
	s.Push("World")

	fmt.Println(s.Values())

}

Output

[Hello World]

Generated by gomarkdoc

<!-- gomarkdoc:embed:end -->

AtomicGo.dev ย ยทย  with โค๏ธ by @MarvinJWendt | MarvinJWendt.com

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated1y ago
Forks0

Languages

Go

Security Score

75/100

Audited on Feb 14, 2025

No findings