Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
smalltalk: [Pharo64-13, Pharo64-12, Pharo64-11, Pharo64-10]
runs-on: ${{ matrix.os }}
name: ${{ matrix.smalltalk }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup SmalltalkCI
uses: hpi-swa/setup-smalltalkCI@v1
with:
smalltalk-version: ${{ matrix.smalltalk }}
- name: Load and Test
run: smalltalkci -s ${{ matrix.smalltalk }}
shell: bash
timeout-minutes: 15
43 changes: 0 additions & 43 deletions .github/workflows/runTests.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .smalltalk.ston
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SmalltalkCISpec {
#loading : [
SCIMetacelloLoadSpec {
#baseline : 'ContainersAVLTree',
#directory : 'src',
#platforms : [ #pharo ]
}
],
#testing : {
#coverage : {
#packages : [ 'Containers-AVL-Tree' ]
}
}
}
90 changes: 78 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,93 @@
# AVL
# Containers-AVL-Tree

[![CI](https://github.com/pharo-containers/AVL/actions/workflows/runTests.yml/badge.svg)](https://github.com/pharo-containers/AVL/actions/workflows/runTests.yml)
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.

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

## How to install it
## What is an AVL Tree?

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):
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).

```st
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):

```smalltalk
Metacello new
baseline: 'ContainersAVLTree';
repository: 'github://pharo-containers/Container-AVL:main';
repository: 'github://pharo-containers/Container-AVL/src';
load
```

## How to depend on it

If you want to add a dependency on `linear-models` to your project, include the following lines into your baseline method:
```smalltalk
spec
baseline: 'ContainersAVLTree'
with: [ spec repository: 'github://pharo-containers/Container-AVL/src' ].
```

## Why use Containers-AVL-Tree?

AVL Trees maintain sorted data with guaranteed efficient operations, perfect for applications requiring consistent performance regardless of input order.

### Key Benefits
- **Guaranteed Performance**: O(log n) worst-case for all operations
- **Self-Balancing**: Automatic rebalancing through rotations
- **Ordered Iteration**: Automatic sorted traversal
- **Range Queries**: Efficient retrieval of value ranges

## Basic Usage

```st
spec
baseline: 'ContainersAVLTree'
with: [ spec repository: 'github://pharo-containers/Container-AVL' ].
```smalltalk
"Create and populate an AVL Tree"
tree := CTAVLTree new.
tree addAll: #(50 30 70 20 40 60 80).

"Search operations"
tree includes: 30. "=> true"
tree findMin. "=> 20"
tree findMax. "=> 80"

"Range queries"
tree elementsFrom: 35 to: 65. "=> #(40 50 60)"

"Tree automatically stays balanced"
tree validate. "=> true"
tree height. "=> 3 (logarithmic height)"
```

## Real-World Use Case

```smalltalk
"Order book for trading system - needs guaranteed fast operations"
orderBook := CTAVLTree new.
orderBook addAll: #(100.50 100.75 100.25 101.00 99.75).

"Fast operations regardless of market conditions"
bestPrice := orderBook findMax. "=> 101.00"
competitivePrices := orderBook elementsGreaterThan: 100.40.
"=> #(100.50 100.75 101.00)"

"Remove filled orders - tree rebalances automatically"
orderBook remove: 101.00.
orderBook validate. "=> still perfectly balanced"
```

## Performance Advantage

AVL Trees excel with sorted or nearly-sorted data where regular BSTs fail:

```smalltalk
"Worst case for regular BST: sorted input"
sortedData := 1 to: 10000.

avlTree := CTAVLTree new.
avlTree addAll: sortedData.
avlTree height. "=> ~14 (logarithmic)"

"Regular BST would have height 10000 (linear)!"
```

## Contributing

This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"
I am a baseline
I represent Baseline of AVL Tree
"
Class {
#name : 'BaselineOfContainersAVLTree',
Expand All @@ -10,9 +10,9 @@ Class {

{ #category : 'baselines' }
BaselineOfContainersAVLTree >> baseline: spec [

<baseline>
spec for: #common do: [ "Packages"
spec for: #common do: [
"Packages"
spec package: 'Containers-AVL-Tree'.
spec
package: 'Containers-AVL-Tree-Tests'
Expand All @@ -21,11 +21,11 @@ BaselineOfContainersAVLTree >> baseline: spec [
package: 'Containers-AVL-Tree-Inspector'
with: [ spec requires: #( 'Containers-AVL-Tree' ) ].

"Define groups"
"Groups"
spec
group: 'Core'
with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' );
group: 'Tests' with: #( 'Containers-AVL-Tree-Tests' ).

spec group: 'default' with: #( 'Core' 'Tests' ) ]
]
]
Loading
Loading