| Crates.io | graphix_io |
| lib.rs | graphix_io |
| version | 0.3.3 |
| created_at | 2025-04-28 12:03:58.407756+00 |
| updated_at | 2025-05-17 11:09:19.853736+00 |
| description | A Rust library for reading and writing graphs from and to text files, based on the graphix crate. |
| homepage | https://github.com/PlotoZypresse/graphix_io |
| repository | https://github.com/PlotoZypresse/graphix_io |
| max_upload_size | |
| id | 1652102 |
| size | 7,018 |
A minimal Rust I/O helper for loading and saving undirected graphs in plain-text edge-list format, built on top of graphix.
Read
read<K>(path: &str) -> io::Result<GraphRep<K>>u v w into Vec<(usize,usize,K)>, then calls GraphRep::from_list.K: FromStr + CopyWrite
write<K>(graph: &GraphRep<K>, path: &str) -> io::Result<()>graph.id.K: Display + CopyZero panics on empty files.
No hash tables or manual “seen” tracking—just buffered I/O and CSR’s id array.
[dependencies]
graphix_io = "0.3"
graphix = "0.4"
Or via Cargo:
cargo add graphix_io@0.3 graphix@0.4
Plain-text file where each line is:
<u> <v> <w>
<u>, <v> are usize vertex IDs<w> is your weight type K::from_str parsesBlank or malformed lines are skipped.
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
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;
This project is licensed under the MIT License. See the LICENSE file for details.