graphix_io

Crates.iographix_io
lib.rsgraphix_io
version0.3.3
created_at2025-04-28 12:03:58.407756+00
updated_at2025-05-17 11:09:19.853736+00
descriptionA Rust library for reading and writing graphs from and to text files, based on the graphix crate.
homepagehttps://github.com/PlotoZypresse/graphix_io
repositoryhttps://github.com/PlotoZypresse/graphix_io
max_upload_size
id1652102
size7,018
Jan (PlotoZypresse)

documentation

README

graphix_io

Crates.io License: MIT

A minimal Rust I/O helper for loading and saving undirected graphs in plain-text edge-list format, built on top of graphix.


Features

  • Read

    • read<K>(path: &str) -> io::Result<GraphRep<K>>
    • Parses every valid line of u v w into Vec<(usize,usize,K)>, then calls GraphRep::from_list.
    • Trait bounds: K: FromStr + Copy
    • Skips blank or malformed lines silently.
  • Write

    • write<K>(graph: &GraphRep<K>, path: &str) -> io::Result<()>
    • Emits each original undirected edge exactly once by iterating graph.id.
    • Trait bounds: K: Display + Copy
  • Zero panics on empty files.

  • No hash tables or manual “seen” tracking—just buffered I/O and CSR’s id array.


Installation

[dependencies]
graphix_io = "0.3"
graphix    = "0.4"

Or via Cargo:

cargo add graphix_io@0.3 graphix@0.4

Usage

Input format

Plain-text file where each line is:

<u> <v> <w>
  • <u>, <v> are usize vertex IDs
  • <w> is your weight type K::from_str parses

Blank or malformed lines are skipped.

Example

use graphix::GraphRep;
use graphix_io::io::{read, write};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1) Read into CSR graph
    let graph: GraphRep<f64> = read("input.txt")?;
    println!("Loaded {} vertices, {} edges",
             graph.num_vertices(),
             graph.num_edges());

    // … run algorithms …

    // 2) Write back original edge list
    write(&graph, "output.txt")?;
    Ok(())
}

Run with:

cargo run

API

pub fn read<K>(file_path: &str) -> io::Result<GraphRep<K>>
where
    K: FromStr + Copy,
    K::Err: Debug;
pub fn write<K>(graph: &GraphRep<K>, file_path: &str) -> io::Result<()>
where
    K: Display + Copy;

License

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

Commit count: 18

cargo fmt