stringmatch

package
v0.0.0-...-7a729f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AND = "AND" // 逻辑与操作符
	OR  = "OR"  // 逻辑或操作符
)

Variables

This section is empty.

Functions

func Calculate

func Calculate(str string, stackSize int, boolFunc func(string) bool) (r bool, b error)

Calculate 函数解析并计算给定的布尔表达式字符串。 参数:

str: 待计算的布尔表达式字符串,可以包含布尔值、逻辑操作符(AND、OR)、括号和标识符。
stackSize: 布尔值和操作符栈的最大大小。
boolFunc: 一个用于从标识符获取布尔值的回调函数。

返回值:

r: 计算结果的布尔值。
b: 如果在计算过程中出现错误,则为一个描述错误的字符串;如果没有错误,则为nil。

Types

type Stack

type Stack[T StackValue] struct {
	// contains filtered or unexported fields
}

栈 对象,用来存储数据或者比较结果

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

判断堆栈是否为空

func (*Stack[T]) IsFull

func (s *Stack[T]) IsFull() bool

判断堆栈是否满了

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

计算栈内还是多少个值

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

获得栈值,但是不出栈

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

取出栈值-后进先出

func (*Stack[T]) Push

func (s *Stack[T]) Push(d T)

压入栈值

type StackValue

type StackValue interface {
	~string | ~bool
}

定义堆栈的值范围,泛型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL