View on GitHub

ecgen-rs

๐Ÿ”ข Enumerative Combinatoric Generation Rust Code

Crates.io Docs.rs CI codecov

๐Ÿ”ข ecgen-rs

A high-performance Rust library for enumerative combinatoric generation. This library provides efficient algorithms for generating various combinatorial structures using lazy evaluation with generators.

โœจ Features

Combinatorial Structures

Key Characteristics

๐Ÿ› ๏ธ Installation

๐Ÿ“ฆ Cargo

Add this to your Cargo.toml:

[dependencies]
ecgen-rs = "0.1"

Or install the binary:

cargo install ecgen-rs

๐Ÿ“– Usage Examples

Generate Combinations

use ecgen_rs::combin::emk_comb_gen;

// Generate all 2-combinations from 5 elements
let mut gen = emk_comb_gen(5, 2);
while let Some(comb) = gen.next() {
    println!("{:?}", comb);
}
// Output: [0, 1], [1, 2], [0, 2], [2, 3], [1, 3], [3, 4], [2, 4], [1, 4]

Generate Permutations

use ecgen_rs::perm::sjt_gen;

// Generate all permutations of 3 elements
let mut gen = sjt_gen(3);
while let Some(perm) = gen.next() {
    println!("{:?}", perm);
}
// Output: [1, 2, 3], [1, 3, 2], [3, 1, 2], [2, 1, 3], [2, 3, 1], [3, 2, 1]

Generate Gray Codes

use ecgen_rs::gray_code::brgc_gen;

// Generate 3-bit Gray codes
let mut gen = brgc_gen(3);
while let Some(pos) = gen.next() {
    // Returns the bit position to flip
    println!("Flip bit at position: {}", pos);
}

Generate Set Partitions

use ecgen_rs::set_partition::set_partition_gen;

// Generate all partitions of 4 elements into 2 blocks
let mut gen = set_partition_gen(4, 2);
while let Some(part) = gen.next() {
    println!("{:?}", part);
}

Mathematical Functions

use ecgen_rs::{combin::comb, perm::factorial, set_partition::stirling2nd};

assert_eq!(factorial(5), 120);
assert_eq!(comb(10, 3), 120);
assert_eq!(stirling2nd(5, 3), 25);

๐Ÿ“š API Documentation

Full API documentation is available at docs.rs/ecgen-rs.

๐Ÿ—๏ธ Architecture

The library is organized into modules:

๐Ÿงช Testing

Run the test suite:

cargo test

Run with coverage:

cargo tarpaulin --out Html

๐Ÿ”ฌ Benchmarks

Run benchmarks:

cargo bench

๐Ÿค Contribution

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“œ License

Licensed under either of

at your option.

๐Ÿ™ Acknowledgments

This library implements classic algorithms from the literature:

๐Ÿ“ž Support

For issues, questions, or contributions, please visit the GitHub repository.