9 releases
| 0.3.3 | May 17, 2025 |
|---|---|
| 0.3.2 | May 17, 2025 |
| 0.2.3 | Apr 28, 2025 |
| 0.1.0 | Apr 28, 2025 |
#969 in Data structures
496 downloads per month
6KB
graphix_io
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 wintoVec<(usize,usize,K)>, then callsGraphRep::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
idarray.
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>areusizevertex IDs<w>is your weight typeK::from_strparses
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.
Dependencies
~11KB