Files
nomad/lib/lang/stack.go
Seth Hoenig a4cc76bd3e numa: enable numa topology detection (#18146)
* 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
2023-08-10 17:05:30 -05:00

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
}