Skip to content

Commit

Permalink
Merge pull request #26 from azizkayumov/develop
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
azizkayumov authored Oct 12, 2023
2 parents 91b5a24 + 9a43da5 commit 72fb1bf
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
name = "lctree"
version = "0.1.0"
edition = "2021"
rust-version = "1.66"
readme = "README.md"
license = "Apache-2.0"
keywords = ["tree", "dynamic-connectivity"]
categories = ["algorithms", "data-structures"]
authors = ["Kayumov A.I. <[email protected]>"]
exclude = ["./github"]
description = "Rust implementation of Link-Cut-Tree: self-balancing data structure to maintain a forest of rooted trees."
repository = "https://github.com/azizkayumov/lctree"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,86 @@
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/azizkayumov/lctree/ci.yml?style=plastic)](#)
[![crates.io](https://img.shields.io/crates/v/lctree)](https://crates.io/crates/lctree)

# lctree
Rust implementation of [Link-Cut-Tree](https://dl.acm.org/doi/10.1145/253262.253347](https://dl.acm.org/doi/pdf/10.1145/800076.802464)): self-balancing data structure to maintain a forest of rooted trees.

## Example
This example shows how to link and cut edges:
```rust
use srtree::SRTree;

fn main() {
// We form a link-cut tree from a rooted tree with the following structure:
// 0
// / \
// 1 4
// / \ \
// 2 3 5
// /
// 6
let mut lctree = super::LinkCutTree::new(7);
lctree.link(1, 0);
lctree.link(2, 1);
lctree.link(3, 1);
lctree.link(4, 0);
lctree.link(5, 4);
lctree.link(6, 5);

// Checking connectivity:
for i in 0..7 {
for j in 0..7 {
assert!(lctree.connected(i, j));
}
}

// We cut node 4 from its parent 0:
lctree.cut(4, 0);

// The forest should now look like this:
// 0
// /
// 1 4
// / \ \
// 2 3 5
// /
// 6

// We check connectivity again for the two trees:
for i in 0..4 {
for j in 0..4 {
assert!(lctree.connected(i, j));
}
}
for i in 4..7 {
for j in 4..7 {
assert!(lctree.connected(i, j));
}
}
for i in 0..4 {
for j in 4..7 {
assert!(!lctree.connected(i, j));
}
}
}
```

## License

Copyright 2019-2024 Kayumov Abduaziz.

Licensed under [Apache License, Version 2.0][apache-license] (the "License");
you may not use this crate except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See [LICENSE](LICENSE) for
the specific language governing permissions and limitations under the License.

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the [Apache-2.0
license][apache-license], shall be licensed as above, without any additional
terms or conditions.

[apache-license]: http://www.apache.org/licenses/LICENSE-2.0

0 comments on commit 72fb1bf

Please sign in to comment.