1
0
mirror of https://github.com/divan/expvarmon.git synced 2025-04-27 13:48:55 +08:00
expvarmon/stack.go

24 lines
449 B
Go
Raw Normal View History

2015-04-21 16:33:04 +03:00
package main
2015-04-25 09:06:45 +03:00
// Stack is a limited FIFO for holding sparkline values.
2015-04-21 16:33:04 +03:00
type Stack struct {
Values []int
Len int
}
2015-04-25 09:06:45 +03:00
// NewStack inits new Stack with size limit.
2015-04-21 16:33:04 +03:00
func NewStack(size int) *Stack {
return &Stack{
Values: make([]int, size),
Len: size,
}
}
2015-04-25 09:06:45 +03:00
// Push inserts data to stack, preserving constant length.
2015-04-21 16:33:04 +03:00
func (s *Stack) Push(val int) {
s.Values = append(s.Values, val)
if len(s.Values) > s.Len {
s.Values = s.Values[1:]
}
}