Skip to content

Commit c5b7e12

Browse files
committed
Update README and baseline config file
1 parent 10093fb commit c5b7e12

File tree

2 files changed

+96
-18
lines changed

2 files changed

+96
-18
lines changed

README.md

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,93 @@
1-
# AVL
1+
# Containers-AVL-Tree
22

3-
[![CI](https://github.com/pharo-containers/AVL/actions/workflows/runTests.yml/badge.svg)](https://github.com/pharo-containers/AVL/actions/workflows/runTests.yml)
3+
A self-balancing AVL Tree implementation providing guaranteed O(log n) performance for all operations. Features automatic rebalancing, range queries, and full Collection protocol compliance.
44

5-
AVL Tree migration from Roassal 3. A work in progress since it should be packaged to follow project conventions.
5+
![Pharo Version](https://img.shields.io/badge/Pharo-10+-blue)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
67

7-
## How to install it
8+
## What is an AVL Tree?
89

9-
To install `AVL`, go to the Playground (Ctrl+OW) in your [Pharo](https://pharo.org/) image and execute the following Metacello script (select it and press Do-it button or Ctrl+D):
10+
An AVL Tree is a self-balancing binary search tree where the height difference between left and right subtrees of any node is at most 1. This guarantees O(log n) worst-case performance for all operations, unlike regular BSTs which can degrade to O(n).
1011

11-
```st
12+
To install `Container-AVL`, go to the Playground (Ctrl+OW) in your [Pharo](https://pharo.org/) image and execute the following Metacello script (select it and press Do-it button or Ctrl+D):
13+
14+
```smalltalk
1215
Metacello new
1316
baseline: 'ContainersAVLTree';
14-
repository: 'github://pharo-containers/Container-AVL:main';
17+
repository: 'github://pharo-containers/Container-AVL/src';
1518
load
1619
```
1720

1821
## How to depend on it
1922

20-
If you want to add a dependency on `linear-models` to your project, include the following lines into your baseline method:
23+
```smalltalk
24+
spec
25+
baseline: 'ContainersAVLTree'
26+
with: [ spec repository: 'github://pharo-containers/Container-AVL/src' ].
27+
```
28+
29+
## Why use Containers-AVL-Tree?
30+
31+
AVL Trees maintain sorted data with guaranteed efficient operations, perfect for applications requiring consistent performance regardless of input order.
32+
33+
### Key Benefits
34+
- **Guaranteed Performance**: O(log n) worst-case for all operations
35+
- **Self-Balancing**: Automatic rebalancing through rotations
36+
- **Ordered Iteration**: Automatic sorted traversal
37+
- **Range Queries**: Efficient retrieval of value ranges
38+
39+
## Basic Usage
2140

22-
```st
23-
spec
24-
baseline: 'ContainersAVLTree'
25-
with: [ spec repository: 'github://pharo-containers/Container-AVL' ].
41+
```smalltalk
42+
"Create and populate an AVL Tree"
43+
tree := CTAVLTree new.
44+
tree addAll: #(50 30 70 20 40 60 80).
45+
46+
"Search operations"
47+
tree includes: 30. "=> true"
48+
tree findMin. "=> 20"
49+
tree findMax. "=> 80"
50+
51+
"Range queries"
52+
tree elementsFrom: 35 to: 65. "=> #(40 50 60)"
53+
54+
"Tree automatically stays balanced"
55+
tree validate. "=> true"
56+
tree height. "=> 3 (logarithmic height)"
2657
```
2758

59+
## Real-World Use Case
60+
61+
```smalltalk
62+
"Order book for trading system - needs guaranteed fast operations"
63+
orderBook := CTAVLTree new.
64+
orderBook addAll: #(100.50 100.75 100.25 101.00 99.75).
65+
66+
"Fast operations regardless of market conditions"
67+
bestPrice := orderBook findMax. "=> 101.00"
68+
competitivePrices := orderBook elementsGreaterThan: 100.40.
69+
"=> #(100.50 100.75 101.00)"
70+
71+
"Remove filled orders - tree rebalances automatically"
72+
orderBook remove: 101.00.
73+
orderBook validate. "=> still perfectly balanced"
74+
```
75+
76+
## Performance Advantage
77+
78+
AVL Trees excel with sorted or nearly-sorted data where regular BSTs fail:
79+
80+
```smalltalk
81+
"Worst case for regular BST: sorted input"
82+
sortedData := 1 to: 10000.
83+
84+
avlTree := CTAVLTree new.
85+
avlTree addAll: sortedData.
86+
avlTree height. "=> ~14 (logarithmic)"
87+
88+
"Regular BST would have height 10000 (linear)!"
89+
```
90+
91+
## Contributing
92+
93+
This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.

src/BaselineOfContainersAVLTree/BaselineOfContainersAVLTree.class.st

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ Class {
1010

1111
{ #category : 'baselines' }
1212
BaselineOfContainersAVLTree >> baseline: spec [
13-
<baseline>
14-
spec for: #common do: [
15-
spec package: 'Containers-AVL-Tree'.
16-
spec
17-
package: 'Containers-AVL-Tree-Tests'
18-
with: [ spec requires: #( 'Containers-AVL-Tree' ) ] ]
13+
<baseline>
14+
spec for: #common do: [
15+
"Packages"
16+
spec package: 'Containers-AVL-Tree'.
17+
spec
18+
package: 'Containers-AVL-Tree-Tests'
19+
with: [ spec requires: #( 'Containers-AVL-Tree' ) ].
20+
spec
21+
package: 'Containers-AVL-Tree-Inspector'
22+
with: [ spec requires: #( 'Containers-AVL-Tree' ) ].
23+
24+
"Groups"
25+
spec
26+
group: 'Core'
27+
with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' );
28+
group: 'Tests' with: #( 'Containers-AVL-Tree-Tests' ).
29+
30+
spec group: 'default' with: #( 'Core' 'Tests' ) ]
1931
]

0 commit comments

Comments
 (0)