mirror of
https://github.com/MrAle98/sliver
synced 2026-06-08 11:54:46 +00:00
1c9d11f967
Bumps [github.com/jackc/pgx/v5](https://github.com/jackc/pgx) from 5.3.1 to 5.5.4. - [Changelog](https://github.com/jackc/pgx/blob/master/CHANGELOG.md) - [Commits](https://github.com/jackc/pgx/compare/v5.3.1...v5.5.4) --- updated-dependencies: - dependency-name: github.com/jackc/pgx/v5 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com>
40 lines
955 B
Go
40 lines
955 B
Go
package genstack
|
|
|
|
// stack is a wrapper around an array implementing a stack.
|
|
//
|
|
// We cannot use slice to represent the stack because append might change the
|
|
// pointer value of the slice. That would be an issue in GenStack
|
|
// implementation.
|
|
type stack[T any] struct {
|
|
arr []T
|
|
}
|
|
|
|
// push pushes a new element at the top of a stack.
|
|
func (s *stack[T]) push(vs ...T) { s.arr = append(s.arr, vs...) }
|
|
|
|
// pop pops the stack top-most element.
|
|
//
|
|
// If stack length is zero, this method panics.
|
|
func (s *stack[T]) pop() T {
|
|
idx := s.len() - 1
|
|
val := s.arr[idx]
|
|
|
|
// Avoid memory leak
|
|
var zero T
|
|
s.arr[idx] = zero
|
|
|
|
s.arr = s.arr[:idx]
|
|
return val
|
|
}
|
|
|
|
// takeAll returns all elements in the stack in order as they are stored - i.e.
|
|
// the top-most stack element is the last one.
|
|
func (s *stack[T]) takeAll() []T {
|
|
arr := s.arr
|
|
s.arr = nil
|
|
return arr
|
|
}
|
|
|
|
// len returns number of elements in the stack.
|
|
func (s *stack[T]) len() int { return len(s.arr) }
|