Skip to content

Commit bdc2213

Browse files
committed
Fix parametric initialisation of RBTree
1 parent a0af2ef commit bdc2213

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/red_black_tree.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# color is true if it's a Red Node, else it's false
55
mutable struct RBTreeNode{K}
66
color::Bool
7-
data::K
7+
data::Union{K, Nothing}
88
leftChild::Union{Nothing, RBTreeNode{K}}
99
rightChild::Union{Nothing, RBTreeNode{K}}
1010
parent::Union{Nothing, RBTreeNode{K}}
@@ -183,7 +183,7 @@ function Base.insert!(tree::RBTree{K}, d::K) where K
183183
search_key(tree, d) && return tree
184184
# search_key(tree, d) && return tree
185185
# insert, if not present in the tree
186-
node = RBTreeNode(d)
186+
node = RBTreeNode{K}(d)
187187
node.leftChild = node.rightChild = tree.Nil
188188

189189
insert_node!(tree, node)

test/test_red_black_tree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include("../src/red_black_tree.jl")
22
@testset "RBTree" begin
3-
t = RBTree()
3+
t = RBTree{Int}()
44
for i = 1:10000
55
insert!(t, i)
66
end

0 commit comments

Comments
 (0)