Algorithms-and-Data-Structures/Rust-Dense-Graph/ReadMe.md

67 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2024-05-04 16:13:07 +01:00
# Graph Implementation with Adjacency Matrix
This project provides a Rust implementation of a graph data structure using an adjacency matrix. The implementation allows you to create, modify, and query properties of a graph, such as adding nodes and edges, removing nodes and edges, and retrieving information about the graph's structure.
## Features
- Node Operations: Add nodes to the graph, remove nodes from the graph, and check if the graph is empty.
- Edge Operations: Add edges between nodes, remove edges between nodes, and retrieve the weight of edges.
- Graph Properties: Retrieve the number of nodes and edges in the graph.
- Clear Graph: Remove all nodes and edges from the graph.
## Usage
To use this graph implementation in your Rust project, follow these steps:
Add the following dependency to your Cargo.toml file:
```toml
[dependencies]
graph-adjacency-matrix = "0.1.0"
```
### Import the Graph struct into your Rust code
```rust
use graph_adjacency_matrix::Graph;
```
### Create a new graph
```rust
let mut graph = Graph::new();
```
Perform operations such as adding nodes, adding edges, removing nodes, removing edges, and querying graph properties using the methods provided by the Graph struct.
```rust
// Add nodes
graph.add_node("A");
graph.add_node("B");
// Add edges
graph.add_edge("A", "B", 5);
// Query edge weight
let weight = graph.get_edge_weight("A", "B").unwrap();
// Remove nodes and edges
graph.remove_node("A");
graph.remove_edge("A", "B");
// Check graph properties
let node_count = graph.node_count();
let edge_count = graph.edge_count();
let is_empty = graph.is_empty();
// Clear the graph
graph.clear();
```
## Contributing
Contributions to this project are welcome! If you find any issues or have suggestions for improvements, please open an issue or a pull request on the GitHub repository.
## License
This project is licensed under the MIT License. See the LICENSE file for details.