croe

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBinaryOpNode

func GetBinaryOpNode() *math_node.BinaryOpNode

GetBinaryOpNode 获取二元运算符节点

func GetFunctionNode

func GetFunctionNode() *math_node.FunctionNode

GetFunctionNode 获取函数节点

func GetNumberNode

func GetNumberNode() *math_node.NumberNode

GetNumberNode 获取数字节点

func GetUnaryOpNode

func GetUnaryOpNode() *math_node.UnaryOpNode

GetUnaryOpNode 获取一元运算符节点

func GetVariableNode

func GetVariableNode() *math_node.VariableNode

GetVariableNode 获取变量节点

func PutBinaryOpNode

func PutBinaryOpNode(node *math_node.BinaryOpNode)

PutBinaryOpNode 归还二元运算符节点

func PutFunctionNode

func PutFunctionNode(node *math_node.FunctionNode)

PutFunctionNode 归还函数节点

func PutNumberNode

func PutNumberNode(node *math_node.NumberNode)

PutNumberNode 归还数字节点

func PutToken

func PutToken(token *Token)

PutToken 归还标记对象

func PutUnaryOpNode

func PutUnaryOpNode(node *math_node.UnaryOpNode)

PutUnaryOpNode 归还一元运算符节点

func PutVariableNode

func PutVariableNode(node *math_node.VariableNode)

PutVariableNode 归还变量节点

func ResetExprCache

func ResetExprCache()

ResetExprCache 重置表达式缓存

func ResetLexerCache

func ResetLexerCache()

ResetLexerCache 重置词法分析器缓存

func ResetShardedCache

func ResetShardedCache()

ResetShardedCache 重置分片缓存

func SetExprCacheCapacity

func SetExprCacheCapacity(capacity int)

SetExprCacheCapacity 设置表达式缓存容量

func SetLexerCacheCapacity

func SetLexerCacheCapacity(capacity int)

SetLexerCacheCapacity 设置词法分析器缓存容量

Types

type CompiledExpression

type CompiledExpression struct {
	// contains filtered or unexported fields
}

CompiledExpression 预编译表达式结构体

func Compile

func Compile(expression string, config *math_config.CalcConfig) (*CompiledExpression, error)

Compile 预编译表达式

func (*CompiledExpression) Evaluate

func (ce *CompiledExpression) Evaluate(vars map[string]decimal.Decimal) (decimal.Decimal, error)

Evaluate 使用预编译表达式计算结果

func (*CompiledExpression) GetLastError

func (ce *CompiledExpression) GetLastError() error

GetLastError 获取最后一次错误

func (*CompiledExpression) WithConfig

WithConfig 设置新的配置

func (*CompiledExpression) WithPrecision

func (ce *CompiledExpression) WithPrecision(precision int32) *CompiledExpression

WithPrecision 设置精度

func (*CompiledExpression) WithPrecisionEachStep

func (ce *CompiledExpression) WithPrecisionEachStep() *CompiledExpression

WithPrecisionEachStep 在每一步应用精度控制

func (*CompiledExpression) WithPrecisionFinalResult

func (ce *CompiledExpression) WithPrecisionFinalResult() *CompiledExpression

WithPrecisionFinalResult 只在最终结果应用精度控制

func (*CompiledExpression) WithPrecisionMode

func (ce *CompiledExpression) WithPrecisionMode(mode math_config.PrecisionMode) *CompiledExpression

WithPrecisionMode 设置精度模式

func (*CompiledExpression) WithTimeout

func (ce *CompiledExpression) WithTimeout(timeout time.Duration) *CompiledExpression

WithTimeout 设置超时时间

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache LRU缓存结构体,用于存储已解析的表达式

func NewLRUCache

func NewLRUCache(capacity int) *LRUCache

NewLRUCache 创建新的LRU缓存

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (math_node.Node, bool)

Get 从缓存中获取表达式节点

func (*LRUCache) Set

func (c *LRUCache) Set(key string, node math_node.Node)

Set 将表达式节点存入缓存

type LRUCacheItem

type LRUCacheItem struct {
	// contains filtered or unexported fields
}

LRUCacheItem LRU缓存项

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer 词法分析器结构体

func NewLexer

func NewLexer(config *math_config.CalcConfig) *Lexer

NewLexer 创建新的词法分析器

func (*Lexer) Lex

func (l *Lexer) Lex(input string) []Token

Lex 词法分析方法,将输入字符串分解为标记

type LexerCache

type LexerCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

词法分析缓存

func NewLexerCache

func NewLexerCache(capacity int) *LexerCache

创建新的词法分析器缓存

type NodePool

type NodePool struct {
	// contains filtered or unexported fields
}

NodePool 节点对象池

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser 解析器结构体

func NewParser

func NewParser(vars map[string]decimal.Decimal, config *math_config.CalcConfig) *Parser

NewParser 创建新的解析器

func (*Parser) Parse

func (p *Parser) Parse(expression string) (math_node.Node, error)

Parse 解析表达式

type ShardedLRUCache

type ShardedLRUCache struct {
	// contains filtered or unexported fields
}

ShardedLRUCache 分片LRU缓存

func NewShardedLRUCache

func NewShardedLRUCache(capacity int) *ShardedLRUCache

NewShardedLRUCache 创建新的分片LRU缓存

func (*ShardedLRUCache) Get

func (c *ShardedLRUCache) Get(key string) (math_node.Node, bool)

Get 获取缓存项

func (*ShardedLRUCache) Set

func (c *ShardedLRUCache) Set(key string, node math_node.Node)

Set 设置缓存项

type Token

type Token struct {
	Type  TokenType // 标记类型
	Value string    // 标记值
	Pos   int       // 标记在表达式中的位置
}

Token 标记结构体

func GetToken

func GetToken() *Token

GetToken 获取标记对象

type TokenPool

type TokenPool struct {
	// contains filtered or unexported fields
}

TokenPool 标记对象池

type TokenType

type TokenType int

TokenType 标记类型

const (
	TokenError TokenType = iota
	TokenNumber
	TokenVariable
	TokenFunc
	TokenPlus
	TokenMinus
	TokenAsterisk
	TokenSlash
	TokenLParen
	TokenRParen
	TokenCaret
	TokenComma
)

标记类型定义

Jump to

Keyboard shortcuts

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