https://github.com/cattlecloud/stacks
stacks is a Go package with generics providing multiple Stack data structures optimized for various use cases
https://github.com/cattlecloud/stacks
generic go golang golang-library linked-list stacks
Last synced: about 1 month ago
JSON representation
stacks is a Go package with generics providing multiple Stack data structures optimized for various use cases
- Host: GitHub
- URL: https://github.com/cattlecloud/stacks
- Owner: cattlecloud
- License: bsd-3-clause
- Created: 2024-07-12T22:42:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-02T00:23:16.000Z (6 months ago)
- Last Synced: 2025-10-02T02:37:02.277Z (6 months ago)
- Topics: generic, go, golang, golang-library, linked-list, stacks
- Language: Go
- Homepage: https://cattlecloud.net/go/stacks
- Size: 30.3 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stacks
[](https://pkg.go.dev/cattlecloud.net/go/stacks)
[](https://github.com/cattlecloud/stacks/blob/main/LICENSE)
[](https://github.com/cattlecloud/stacks/actions/workflows/ci.yaml)
`stacks` is a Go library with generics implementing multiple Stack data structures
for optimizing by use-case.
```
stack (noun):
1. a LIFO data structure
```
### Getting Started
The `stacks` package can be added to a Go project with `go get`.
```shell
go get cattlecloud.net/go/stacks@latest
```
```go
import "cattlecloud.net/go/stacks"
```
### Examples
##### backed by slice
The `Simple` stack type is backed by a normal Go slice and is a good choice for
small numbers of elements or where the size of the stack will not increase or
decrease repeatedly - this is important so as to minmize re-copying the data as
the underlying slice is resized.
```go
s := stacks.Simple[string]()
s.Push("how")
s.Push("are")
s.Push("you")
fmt.Println(s.Pop()) // "you"
```
##### backed by linked list
The `Linked` stack type is backed by a linked-list and is a good choice for large
numbers of elements or where the size of the stack does increase or decrease
repeatedly. The nature of the linked list avoids the need to re-copy elements as
the size of the data structure changes over time.
```go
s := stacks.Linked[string]()
s.Push("foo")
s.Push("bar")
s.Push("baz")
fmt.Println(s.Pop()) // "baz"
```
##### methods
```go
s.Push[T](item T)
s.Pop() T
s.Peek() T
s.Empty() bool
s.Size() int
```
### License
The `cattlecloud.net/go/stacks` module is opensource under the [BSD-3-Clause](LICENSE) license.