mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
* client: refactor cgroups management in client * client: fingerprint numa topology * client: plumb numa and cgroups changes to drivers * client: cleanup task resource accounting * client: numa client and config plumbing * lib: add a stack implementation * tools: remove ec2info tool * plugins: fixup testing for cgroups / numa changes * build: update makefile and package tests and cl
44 lines
793 B
Go
44 lines
793 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package lang
|
|
|
|
// A Stack is a simple LIFO datastructure.
|
|
type Stack[T any] struct {
|
|
top *object[T]
|
|
}
|
|
|
|
type object[T any] struct {
|
|
item T
|
|
next *object[T]
|
|
}
|
|
|
|
// NewStack creates a Stack with no elements.
|
|
func NewStack[T any]() *Stack[T] {
|
|
return new(Stack[T])
|
|
}
|
|
|
|
// Push pushes item onto the stack.
|
|
func (s *Stack[T]) Push(item T) {
|
|
obj := &object[T]{
|
|
item: item,
|
|
next: s.top,
|
|
}
|
|
s.top = obj
|
|
}
|
|
|
|
// Pop pops the most recently pushed item from the Stack.
|
|
//
|
|
// It is a logic bug to Pop an Empty stack.
|
|
func (s *Stack[T]) Pop() T {
|
|
obj := s.top
|
|
s.top = obj.next
|
|
obj.next = nil
|
|
return obj.item
|
|
}
|
|
|
|
// Empty returns true if there are no elements on the Stack.
|
|
func (s *Stack[T]) Empty() bool {
|
|
return s.top == nil
|
|
}
|