Documentation ¶
Overview ¶
stack implements a stack with "last in, first out" functionality. it also provides a ring memory type which overrides itself after n write ops.
Index ¶
- type Rings
- type Stack
- func (s *Stack) Add(n interface{})
- func (s *Stack) Get() interface{}
- func (s *Stack) IsEmpty() bool
- func (s *Stack) Len() int
- func (s *Stack) Pop() interface{}
- func (s *Stack) Push(n interface{})
- func (s *Stack) ToFifo() *Stack
- func (s *Stack) ToLifo() *Stack
- func (s *Stack) Unset()
- func (s *Stack) Val() []interface{}
- type Stype
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rings ¶
type Rings struct {
// contains filtered or unexported fields
}
struct Rings contains nodes as slice of strings, count for the current ring position, xcount for the total amount of added entries and size for the maximum size of the "Ring".
Example ¶
package main import ( "fmt" "simonwaldherr.de/go/golibs/stack" ) func main() { ring := stack.Ring() ring.Init(4) for i := 0; i < 16; i++ { ring.Push(fmt.Sprintf("%v", i)) } vals := ring.Get(2) for _, v := range vals { fmt.Println(v) } }
Output: 12 13 14
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
struct Stack contains nodes as slice of interfaces and a counter for the current position.
Example ¶
package main import ( "fmt" "simonwaldherr.de/go/golibs/as" "simonwaldherr.de/go/golibs/stack" ) func main() { array := stack.Lifo() array.Push("1") array.Push(float64(13.37)) array.Push(false) array.Push("Lorem Ipsum Dolor sit Amet") for array.Len() > 0 { fmt.Println(as.String(array.Pop())) } }
Output: Lorem Ipsum Dolor sit Amet false 13.37 1
Click to show internal directories.
Click to hide internal directories.