binary-search-tree-visualizer 0.1.0

A crate that provides visualization tools for binary search trees, including ASCII art and SVG generation. Great for educational purposes and debugging.
Documentation
  • Coverage
  • 66.67%
    18 out of 27 items documented0 out of 11 items with examples
  • Size
  • Source code size: 18.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 22s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nyakiomaina

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.