cozad-union-find

A Rust implementation of the union-find disjoint set graph algorithm

MIT License Build Status Code Size Top Language

Quick Start

Using the named node interfaces

For relatively small networks you can simply interact with nodes by name.

``` rust use union_find::client as ufclient;

let mut client = ufclient::Client::new();

client.addnode("A"); client.addnode("B"); client.addnode("C"); client.addnode("D"); client.addnode("E"); client.addnode("F"); client.addnode("G"); client.addnode("H"); client.addnode("I"); client.addnode("J");

client.connectnodes("E", "D"); client.connectnodes("D", "I"); client.connectnodes("G", "F"); client.connectnodes("J", "E"); client.connectnodes("C", "B"); client.connectnodes("I", "J"); client.connectnodes("F", "A"); client.connectnodes("H", "B"); client.connectnodes("G", "B"); client.connectnodes("B", "A"); client.connect_nodes("G", "H");

println!("\nDisjoint sets found: {}", client.disjointsetcount()) ```

Output Disjoint sets found: 2

Using the bulk interfaces

When you have a large volume of connections to process you can skip the lookups that occur with named nodes and use the bulk interfaces. The process involves giving a vector of node names and then specifying connections between nodes by index.

``` rust use unionfind::client as ufclient; use unionfind::client::BulkConnection as ufconnection;

let mut client = ufclient::Client::new(); let nodes = vec![ String::from("A"), String::from("B"), String::from("C"), String::from("D"), String::from("E"), String::from("F"), String::from("G"), String::from("H"), String::from("I"), String::from("J") ]; client.addnodesbulk(nodes);

let connections = vec![ ufconnection { a: 4, b: 3 }, ufconnection { a: 3, b: 8 }, ufconnection { a: 6, b: 5 }, ufconnection { a: 9, b: 4 }, ufconnection { a: 2, b: 1 }, ufconnection { a: 8, b: 9 }, ufconnection { a: 5, b: 0 }, ufconnection { a: 7, b: 2 }, ufconnection { a: 6, b: 1 }, ufconnection { a: 1, b: 0 }, ufconnection{ a: 6, b: 7 } ]; client.connectnodesbulk(connections);

println!("\nDisjoint sets found: {}", client.disjointsetcount()) ```

Output Disjoint sets found: 2

Run as a CLI

``` cargo build cd target/debug ./cozad-union-find -n ../../data/nodessmall.txt -c ../../data/connectionssmall.txt

```

Example Output ``` Node File: ../../data/nodes_small.txt Processing nodes file... Nodes file processed Bulk adding nodes... Nodes bulk added

Connections File: ../../data/connections_small.txt Processing connections file... Connections file processed Bulk connecting nodes... Nodes bulk connected

Disjoint sets found: 2 ```

Run the tests

cargo test

Concepts

Support

License

Licensed under