Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

stack

GoDoc Go Report Card Go Coverage

Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

Purpose

Provide a fast, thread safe, and generic Golang Stack API with minimal external linkage and maximum performance and usability.

Installation

go get -d -v github.com/lossdev/stack

Example

package main

import (
    "github.com/lossdev/stack"
    "log"
    "fmt"
)

type foo struct {
    bar string
    baz bool
}

func main() {
    // declare a new Stack 's' with int type (stack.Int)
    s := stack.NewStack(stack.Int)
    if err := s.Push(1); err != nil {
        log.Println(err)
    }
    if recv, err := stack.ToInt(s.Peek()); err != nil {
        log.Println(err)
    } else {
        fmt.Println(recv)
    }
    // Adding a member of a different type than what s is declared as will error
    if err := s.Push("Hello, World!"); err != nil {
        log.Println(err)
    }
    gs := stack.NewGenericStack()
    f := foo{"Hello, World!", true}
    gs.Push(f)
    if recv, err := gs.Peek(); err != nil {
        log.Println(err)
    } else {
        // type assertion needed
        frecv := recv.(foo)
        fmt.Printf("GenericStack: {%s, %t}\n", frecv.bar, frecv.baz)
    }
}
$ go run example.go
1
2021/04/07 13:31:52 Push(): expected: [int]; received: [string]
GenericStack: {Hello, World!, true}
Owner
Brendan Wilson
Golang | Full Stack | Kubernetes | DevOps | Cybersecurity | Open to trade Arch Linux and macOS ricing tips for chicken nuggets
Brendan Wilson
Similar Resources

Sliding window counters Redis rate limiting implementation for Golang

Sliding window counters Redis rate limiting implementation for Golang (Based on the Figma API rate limit algorithm)

Dec 21, 2022

A pure Golang implementation of Rockchip rknand vendor storage interface.

go-rkvendorstorage A pure Golang implementation of Rockchip rknand vendor storage interface. Usage package main import ( "fmt" "github.com/jamesits

Nov 8, 2022

Golang 1.18+ Generics implementation of Set methods

Golang Generics: Set A golang 1.18+ implementation of Set using Go generics Installation $ go get -u github.com/chrispappas/golang-generics-set Quick

Oct 26, 2022

go implementation of timsort

timsort timsort is a Go implementation of Tim Peters's mergesort sorting algorithm. For many input types it is 2-3 times faster than Go's built-in sor

Nov 7, 2022

Implementation of do255e and do255s in Go

Go Implementation of do255e and do255s This is a plain Go implementation of do255e and do255s. It is considered secure; all relevant functions should

Aug 15, 2022

Go implementation of the Heaven's Gate technique

Go implementation of the Heaven's Gate technique

gopherheaven is a Go implementation of the classic Heaven's Gate technique originally published by roy g biv on VX Heaven in 2009. gopherheaven can be used as an evasion technique to directly call 64-bit code from a 32-bit process.

Dec 20, 2022

An idiomatic Go implementation of Leaky bucket.

lbucket lbucket is an idiomatic Go leaky bucket implementation. The library make use of plain old Go stdlib; in other words, there are no third-party

Apr 17, 2022

A faster RWLock primitive in Go, 2-3 times faster than RWMutex. A Go implementation of concurrency control algorithm in paper Left-Right - A Concurrency Control Technique with Wait-Free Population Oblivious Reads

Go Left Right Concurrency A Go implementation of the left-right concurrency control algorithm in paper Left-Right - A Concurrency Control Technique w

Jan 6, 2023

Go implementation of the geodesic routines from GeographicLib

Go implementation of the geodesic routines from GeographicLib

geodesic This package is a Go implementation of the geodesic routines from GeographicLib. Features Pure Go implementation Distance calculations with n

Dec 23, 2022
Comments
  • naming?

    naming?

    go get -d -v github.com/lossdev/stack go: github.com/lossdev/stack upgrade => v1.0.2 go get: github.com/lossdev/[email protected]: parsing go.mod: module declares its path as: github.com/bmw417/stack but was required as: github.com/lossdev/stack

Related tags
a thread-safe concurrent map for go

concurrent map As explained here and here, the map type in Go doesn't support concurrent reads and writes. concurrent-map provides a high-performance

Jan 8, 2023
A thread-safe concurrent map for go

concurrent map Original repo didn't support go mod and no any tags,so I forkd this repo add go mod support and patch a tag on this repo. No any code c

Dec 7, 2021
A simple API for computing diffs of your documents over the time built on a scalable technology stack.

Diffme API WIP - this is an API to compute diffs between documents. It serves as a way to easily create audit logs for documents in your system, think

Sep 8, 2021
safe and easy casting from one type to another in Go

cast Easy and safe casting from one type to another in Go Don’t Panic! ... Cast What is Cast? Cast is a library to convert between different go types

Jan 1, 2023
A lightweight casting package for Go projects

Cast GoLobby Cast is a lightweight casting package for Go projects. Documentation Required Go Versions It requires Go v1.11 or newer versions. Install

Dec 21, 2022
[Go] Lightweight eventbus with async compatibility for Go

[Go] Lightweight eventbus with async compatibility for Go

Jan 3, 2023
Fast, lightweight and NOT reliable tool for downloading tons of images.

image-download-tool Fast, lightweight and NOT reliable tool for downloading tons of images. How to use Run .exe with --help flag Create json file with

May 12, 2022
🎓 A lightweight, rich and beautiful Go wrapper for JSPaste.

GOPaste GOPaste is a lightweight, rich and beautiful wrapper for JSPaste. JSPaste allows you to upload, get and delete texts rapidly. It's also the li

Nov 15, 2021
Go-generics-simple-doubly-linked-list - A simple doubly linked list implemented using generics (Golang)

Welcome to Go-Generics-Simple-Doubly-Linked-List! Hi, This repository contains a

Jun 30, 2022
Optimal implementation of ordered maps for Golang - ie maps that remember the order in which keys were inserted.

Goland Ordered Maps Same as regular maps, but also remembers the order in which keys were inserted, akin to Python's collections.OrderedDicts. It offe

Jan 3, 2023