mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-29 02:46:35 +08:00
feat: 支持关联多标签、计划任务立即执行、标签相关操作优化
This commit is contained in:
41
server/pkg/utils/collx/stack.go
Normal file
41
server/pkg/utils/collx/stack.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package collx
|
||||
|
||||
type Stack[T any] struct {
|
||||
items []T
|
||||
}
|
||||
|
||||
// 入栈
|
||||
func (s *Stack[T]) Push(item T) {
|
||||
s.items = append(s.items, item)
|
||||
}
|
||||
|
||||
// 出栈
|
||||
func (s *Stack[T]) Pop() T {
|
||||
var item T
|
||||
if len(s.items) == 0 {
|
||||
return item
|
||||
}
|
||||
lastIndex := len(s.items) - 1
|
||||
item = s.items[lastIndex]
|
||||
s.items = s.items[:lastIndex]
|
||||
return item
|
||||
}
|
||||
|
||||
// 获取栈顶元素
|
||||
func (s *Stack[T]) Top() T {
|
||||
var item T
|
||||
if len(s.items) == 0 {
|
||||
return item
|
||||
}
|
||||
return s.items[len(s.items)-1]
|
||||
}
|
||||
|
||||
// 检查栈是否为空
|
||||
func (s *Stack[T]) IsEmpty() bool {
|
||||
return len(s.items) == 0
|
||||
}
|
||||
|
||||
// 返回栈的大小
|
||||
func (s *Stack[T]) Size() int {
|
||||
return len(s.items)
|
||||
}
|
||||
Reference in New Issue
Block a user