Skip to content

Commit 54ce2fd

Browse files
authored
Merge pull request #638 from eulerkochy/rb_tree
Red Black Tree
2 parents 2a8edba + 80b4b11 commit 54ce2fd

File tree

7 files changed

+595
-1
lines changed

7 files changed

+595
-1
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ makedocs(
2525
"intset.md",
2626
"sorted_containers.md",
2727
"dibit_vector.md",
28+
"red_black_tree.md",
2829
],
2930
modules = [DataStructures],
3031
format = Documenter.HTML()

docs/src/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This package implements a variety of data structures, including
2222
- DataStructures.IntSet
2323
- SparseIntSet
2424
- DiBitVector
25+
- Red Black Tree
2526

2627
## Contents
2728

@@ -46,6 +47,7 @@ Pages = [
4647
"intset.md",
4748
"sorted_containers.md",
4849
"sparse_int_set.md",
49-
"dibit_vector.md"
50+
"dibit_vector.md",
51+
"red_black_tree.md"
5052
]
5153
```

docs/src/red_black_tree.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```@meta
2+
DocTestSetup = :(using DataStructures)
3+
```
4+
5+
# Red Black Tree
6+
7+
The `RBTree` type is an implementation of Red Black Tree in Julia. It is a self-balancing binary search tree with an extra bit of information, the color, in each of its node. Operations such as search, insert and delete can be done in `O(log n)` complexity, where `n` is the number of nodes in the `RBTree`.
8+
9+
Examples:
10+
11+
```jldoctest
12+
julia> tree = RBTree{Int}();
13+
14+
julia> for k in 1:2:20
15+
push!(tree, k)
16+
end
17+
18+
julia> haskey(tree, 3)
19+
true
20+
21+
julia> tree[4]
22+
7
23+
24+
julia> for k in 1:2:10
25+
delete!(tree, k)
26+
end
27+
28+
julia> haskey(tree, 5)
29+
false
30+
```
31+
32+
```@meta
33+
DocTestSetup = nothing
34+
```

src/DataStructures.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ module DataStructures
5858

5959
export DiBitVector
6060

61+
export RBTree, search_node, minimum_node
62+
6163
export findkey
6264

6365
include("delegate.jl")
@@ -108,5 +110,7 @@ module DataStructures
108110
export SparseIntSet
109111

110112
include("dibit_vector.jl")
113+
include("red_black_tree.jl")
111114
include("deprecations.jl")
115+
112116
end

0 commit comments

Comments
 (0)