Documentation ¶
Overview ¶
Package stack aims to provide a fast, simple, thread safe, and user friendly stack library. Stacks that are composed of primitive types (int, float64, string, bool) inherit from their parent GenericStacks, which can be of any data type. GenericStacks must be type asserted when retrieving their values, however, primitive Stacks include wrapping functions that will easily return the intended types for you. This way, completeness and user friendliness (through avoiding user-side type assertions when possible) is achieved.
Index ¶
- Constants
- func ToBool(memberReturned interface{}, err error) (bool, error)
- func ToFloat(memberReturned interface{}, err error) (float64, error)
- func ToInt(memberReturned interface{}, err error) (int, error)
- func ToString(memberReturned interface{}, err error) (string, error)
- type GenericStack
- type Stack
Constants ¶
const ( // Int : stack.Int const represents integer stacks Int = iota // Float : stack.Float const represents float stacks Float // String : stack.String const represents string stacks String // Bool : stack.Bool const represent boolean stacks Bool )
Variables ¶
This section is empty.
Functions ¶
func ToFloat ¶ added in v1.0.4
ToFloat behaves equivalently to ToInt, but operates with float64 types
Types ¶
type GenericStack ¶ added in v1.0.4
type GenericStack struct {
// contains filtered or unexported fields
}
GenericStack stores the lock and data members
func NewGenericStack ¶ added in v1.0.4
func NewGenericStack() *GenericStack
NewGenericStack is the constructor method that initializes a new, empty generic stack. Generic stacks can accept any data type, however, a type assertion will have to be included in a user-side program to retrieve values from the stack
func (*GenericStack) Drain ¶ added in v1.0.4
func (s *GenericStack) Drain()
Drain removes all elements that are currently in the stack.
func (*GenericStack) Peek ¶ added in v1.0.4
func (s *GenericStack) Peek() (interface{}, error)
Peek looks at, but does not remove, the top element of the stack. It returns an error if the stack is empty, or the value of the top element if it isn't.
func (*GenericStack) Pop ¶ added in v1.0.4
func (s *GenericStack) Pop() (interface{}, error)
Pop attempts to remove a value from the top of the stack. It will return an error if the stack is empty, or the value of the top element if it isn't.
func (*GenericStack) Push ¶ added in v1.0.4
func (s *GenericStack) Push(val interface{})
Push (GenericStack method) will add a new generic value to the top of the stack.
func (*GenericStack) Size ¶ added in v1.0.4
func (s *GenericStack) Size() int
Size returns the current size of the stack. If the stack is empty, it will simply return 0, not an error
type Stack ¶
type Stack struct { GenericStack // contains filtered or unexported fields }
Stack inherits GenericStack's previous fields, and adds a dataType field to store what primitive data type the stack should accept