iter-rationals

Crates.ioiter-rationals
lib.rsiter-rationals
version0.2.1
sourcesrc
created_at2022-08-30 04:59:05.552233
updated_at2023-03-08 23:52:41.751816
descriptionA fixed size, linear time, no-std iterator over the rational numbers.
homepage
repositoryhttps://github.com/nathanielknight/iter-rationals
max_upload_size
id654960
size24,276
Nathaniel Knight (nathanielknight)

documentation

README

iter-rationals

crate documentation main

This crate implements an iterator over the rational numbers which:

  • yields each number once-and-only-once,
  • requires only a fixed amount of memory, and
  • yields successive values with a fixed amount of arithmetic operations.

The algorithm is described in Functional Pearl: Enumerating the Rationals by Gibbons, Lester, and Bird; see the paper for an explanation of how it works.

Usage

use iter_rationals::Rationals;

fn main() {
    let rs = Rationals::<u32>::new();

    for r in rs.take(20) {
        println!("{r}");
    }
}

Installation

Add this dependency to your Cargo.toml:

iter-rationals = "0.1"

or on the command line:

cargo add iter-rationals

License

Commit count: 14

cargo fmt