binary-search-tree-visualizer

Crates.iobinary-search-tree-visualizer
lib.rsbinary-search-tree-visualizer
version0.1.0
created_at2025-05-26 19:07:41.163432+00
updated_at2025-05-26 19:07:41.163432+00
descriptionA crate that provides visualization tools for binary search trees, including ASCII art and SVG generation. Great for educational purposes and debugging.
homepagehttps://github.com/nyakiomaina/binary-search-tree-visualizer
repositoryhttps://github.com/nyakiomaina/binary-search-tree-visualizer
max_upload_size
id1690147
size19,318
Nyakio Maina (nyakiomaina)

documentation

https://docs.rs/binary-search-tree-visualizer

README

Binary Search Tree Visualizer

Crates.io Docs.rs

A Rust crate that provides visualization tools for binary search trees, including both ASCII art and SVG generation. This crate is great for educational purposes and debugging binary search tree implementations.

Features

  • ASCII art visualization of binary search trees
  • SVG generation for high-quality tree visualization
  • Simple and intuitive API
  • Customizable visualization parameters
  • Support for any type that implements Ord and Display traits

Installation

Add this to your Cargo.toml:

[dependencies]
binary-search-tree-visualizer = "0.1.0"

Or use:

cargo add binary-search-tree-visualizer

Usage

Here's a simple example of how to use the crate:

use binary_search_tree_visualizer::{BinarySearchTree, AsciiVisualizer, SvgVisualizer};
use binary_search_tree_visualizer::visualizer::TreeVisualizer;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a binary search tree
    let mut tree = BinarySearchTree::new();

    // Insert some values
    tree.insert(5);
    tree.insert(3);
    tree.insert(7);
    tree.insert(1);
    tree.insert(9);

    // Generate ASCII visualization
    let ascii_viz = AsciiVisualizer;
    let ascii_output = ascii_viz.visualize(&tree)?;
    println!("{}", ascii_output);

    // Generate SVG visualization
    let svg_viz = SvgVisualizer::default();
    let svg_output = svg_viz.visualize(&tree)?;

    // Save SVG to file
    std::fs::write("tree.svg", svg_output)?;

    Ok(())
}

Visualization Examples

ASCII Art Output

└── 5
    ┌── 7
    │   ┌── 9
    └── 3
        └── 1

SVG Output

The SVG visualization will be saved to a file and can be viewed in any web browser or SVG-compatible viewer.

Customization

The SvgVisualizer can be customized with different parameters:

let svg_viz = SvgVisualizer {
    node_radius: 25.0,    // Size of node circles
    level_height: 80.0,   // Vertical spacing between levels
    horizontal_spacing: 50.0, // Horizontal spacing between nodes
};

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt