Skip to content

Commit

Permalink
convert BinaryTree to slightly more canonical Julia form
Browse files Browse the repository at this point in the history
With no node mutation, it is unclear why this is mutable (which costs
some extra loads), though the recursion forces this to the heap
regardless. But singleton struct Empty needs to be non-mutable now for
correctness
  • Loading branch information
vtjnash committed Apr 14, 2021
1 parent 406d5b1 commit dd25659
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/shootout/binary_trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#
# Ported from an OCaml version

abstract type BTree end

mutable struct Empty <: BTree
end
struct Empty end

mutable struct Node <: BTree
info
left::BTree
right::BTree
struct Node{T}
info::T
left::Union{Node{T}, Empty}
right::Union{Node{T}, Empty}
end

const BTree{T} = Union{Node{T}, Empty}

function make(val, d)
if d == 0
Node(val, Empty(), Empty())
Expand Down

0 comments on commit dd25659

Please sign in to comment.