implementation: continued pre-processing section; added cache to ExpressionProcessing.jl to improve performance
Some checks are pending
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Waiting to run

This commit is contained in:
2025-04-25 16:22:57 +02:00
parent b40a06af3f
commit ad2eab2e0a
9 changed files with 143 additions and 55 deletions

View File

@ -17,12 +17,16 @@ struct ExpressionElement
end
const PostfixType = Vector{ExpressionElement}
const cache = Dict{Expr, PostfixType}()
"
Converts a julia expression to its postfix notation.
NOTE: All 64-Bit values will be converted to 32-Bit. Be aware of the lost precision
"
function expr_to_postfix(expr::Expr)::PostfixType
if haskey(cache, expr)
return cache[expr]
end
postfix = PostfixType()
@inbounds operator = get_operator(expr.args[1])
@ -40,7 +44,8 @@ function expr_to_postfix(expr::Expr)::PostfixType
push!(postfix, exprElement)
end
# only add operator if at least 2 values are added. For the case where another expression is added first, we check if we are at the first iteration or not ( j != 2)
# only add operator if at least 2 values are added. Needed because e.g. multiple consecutive additions are one subtree with one operator, but multiple operators need to be added to the postfix notation.
# For the case where another expression has already been added, we check if we are at the first iteration or not ( j != 2)
if length(postfix) >= 2 && j != 2
exprElement = convert_to_ExpressionElement(operator)
push!(postfix, exprElement)