Skip to content

Commit c89cbbf

Browse files
committed
Add AVLTree to docs
1 parent efd6bf8 commit c89cbbf

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This package implements a variety of data structures, including
3131
- SparseIntSet
3232
- DiBitVector (in which each element can store two bits)
3333
- Red Black Tree
34+
- AVL Tree
3435

3536
Resources
3637
---------

docs/make.jl

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

docs/src/avl_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+
# AVL Tree
6+
7+
The `AVLTree` type is an implementation of AVL Tree in Julia. It is a self-balancing binary search tree where balancing occurs based on the difference of height of the left subtree and the right subtree. Operations such as search, insert and delete can be done in `O(log n)` complexity, where `n` is the number of nodes in the `AVLTree`.
8+
9+
Examples:
10+
11+
```jldoctest
12+
julia> tree = AVLTree{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+
```

docs/src/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This package implements a variety of data structures, including
2323
- SparseIntSet
2424
- DiBitVector
2525
- Red Black Tree
26+
- AVL Tree
2627

2728
## Contents
2829

@@ -48,6 +49,7 @@ Pages = [
4849
"sorted_containers.md",
4950
"sparse_int_set.md",
5051
"dibit_vector.md",
51-
"red_black_tree.md"
52+
"red_black_tree.md",
53+
"avl_tree.md"
5254
]
5355
```

src/avl_tree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Returns true if `key` is present in the `tree`, else returns false.
111111
"""
112112
haskey(tree, key)
113113

114-
function haskey(tree::AVLTree{K}, d::K) where K
114+
function Base.haskey(tree::AVLTree{K}, d::K) where K
115115
(tree.root == nothing) && return false
116116
node = search_node(tree, d)
117117
return (node.data == d)

0 commit comments

Comments
 (0)