From 7d7782f97f11405befd48b4dfd774bce221e03ec Mon Sep 17 00:00:00 2001 From: rubydragon Date: Wed, 8 May 2024 14:00:25 +0200 Subject: [PATCH] Add Workaround for Trie implementation for Julia version 1.10+ (#7) Co-authored-by: Anton Reinhard Reviewed-on: https://code.woubery.com/rubydragon/metagraphoptimization.jl/pulls/7 --- .gitea/workflows/julia-package-ci.yml | 8 +++---- src/trie.jl | 34 +++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/julia-package-ci.yml b/.gitea/workflows/julia-package-ci.yml index 0447d96..45ed06d 100644 --- a/.gitea/workflows/julia-package-ci.yml +++ b/.gitea/workflows/julia-package-ci.yml @@ -17,9 +17,9 @@ jobs: fetch-depth: 0 - name: Setup Julia environment - uses: https://github.com/julia-actions/setup-julia@v1.9.2 + uses: https://github.com/julia-actions/setup-julia@v2 with: - version: '1.9.2' + version: '1.10' - name: Instantiate run: | @@ -58,9 +58,9 @@ jobs: fetch-depth: 0 - name: Setup Julia environment - uses: https://github.com/julia-actions/setup-julia@v1.9.2 + uses: https://github.com/julia-actions/setup-julia@v2 with: - version: '1.9.2' + version: '1.10' - name: Build docs run: | diff --git a/src/trie.jl b/src/trie.jl index b3babca..441890a 100644 --- a/src/trie.jl +++ b/src/trie.jl @@ -48,7 +48,26 @@ function insert_helper!( trie::NodeIdTrie{NodeType}, node::NodeType, depth::Int, -) where {TaskType <: AbstractTask, NodeType <: Union{DataTaskNode{TaskType}, ComputeTaskNode{TaskType}}} +) where {TaskType <: AbstractDataTask, NodeType <: DataTaskNode{TaskType}} + if (length(children(node)) == depth) + push!(trie.value, node) + return nothing + end + + depth = depth + 1 + id = node.children[depth].id + + if (!haskey(trie.children, id)) + trie.children[id] = NodeIdTrie{NodeType}() + end + return insert_helper!(trie.children[id], node, depth) +end +# TODO: Remove this workaround once https://github.com/JuliaLang/julia/issues/54404 is fixed in julia 1.10+ +function insert_helper!( + trie::NodeIdTrie{NodeType}, + node::NodeType, + depth::Int, +) where {TaskType <: AbstractComputeTask, NodeType <: ComputeTaskNode{TaskType}} if (length(children(node)) == depth) push!(trie.value, node) return nothing @@ -63,6 +82,7 @@ function insert_helper!( return insert_helper!(trie.children[id], node, depth) end + """ insert!(trie::NodeTrie, node::Node) @@ -71,7 +91,17 @@ Insert the given node into the trie. It's sorted by its type in the first layer, function insert!( trie::NodeTrie, node::NodeType, -) where {TaskType <: AbstractTask, NodeType <: Union{DataTaskNode{TaskType}, ComputeTaskNode{TaskType}}} +) where {TaskType <: AbstractDataTask, NodeType <: DataTaskNode{TaskType}} + if (!haskey(trie.children, NodeType)) + trie.children[NodeType] = NodeIdTrie{NodeType}() + end + return insert_helper!(trie.children[NodeType], node, 0) +end +# TODO: Remove this workaround once https://github.com/JuliaLang/julia/issues/54404 is fixed in julia 1.10+ +function insert!( + trie::NodeTrie, + node::NodeType, +) where {TaskType <: AbstractComputeTask, NodeType <: ComputeTaskNode{TaskType}} if (!haskey(trie.children, NodeType)) trie.children[NodeType] = NodeIdTrie{NodeType}() end