Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/novemberisms/stack

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/novemberisms/stack

  • v0.0.0-20190525054940-9e368989c1fc
  • Source
  • Go
  • Socket score

Version published
Created
Source

stack.go

This is my implementation of a LIFO stack in Go. Who hasn't made one of these?

Supports the following methods:

  • Push

    Pushes a value unto the stack

  • Pop

    Pops a value from the top of the stack

  • Peek

    Gets the top element of the stack without popping it

  • Bottom

    Gets the bottom element of the stack without popping it

  • Contains

    Tests whether a value is in the stack

  • Len

    Gets the number of items in the stack

  • Cap

    Gets the capacity of the underlying slice

  • PopFirst

    Pops the first value from the top of the stack that matches the given element

  • PopLast

    Pops the first value from the bottom of the stack that matches the given element

Design considerations

I've avoided doing the whole return nil, err thing for such a simple data structure. I've opted instead to just return nil on all illegal cases.

  • Returns nil when popping from an empty stack
  • Returns nil when peeking an empty stack
  • PopFirst and PopLast returns true or false depending on whether the item was in the stack. Since, you'd need a value that matches the item anyways to be able to search it. It makes no sense having them return the value you just searched for,

LICENSE

This is licensed under the MIT license

FAQs

Package last updated on 25 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc