Skip to content

Commit

Permalink
Formatted iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf committed Aug 22, 2024
1 parent be3f504 commit 35638b1
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils/iterators/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
pub struct Bits {
num: i64,
}

impl Bits {
pub fn new(num: i64) -> Bits {
Bits { num }
}
}

impl Iterator for Bits {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/collatz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ pub struct Collatz {
num: i64,
done: bool,
}

impl Collatz {
pub fn new(num: i64) -> Collatz {
Collatz { num, done: false }
}
}

impl Iterator for Collatz {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/continued_fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct ContinuedFraction {
numerator_addend: i64,
denominator: i64,
}

impl ContinuedFraction {
pub fn new(num: i64) -> ContinuedFraction {
ContinuedFraction {
Expand All @@ -19,6 +20,7 @@ impl ContinuedFraction {
}
}
}

impl Iterator for ContinuedFraction {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/cubes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Cubes {
offset: i64,
num: i64,
}

impl Cubes {
pub fn new() -> Cubes {
Cubes {
Expand All @@ -16,6 +17,7 @@ impl Cubes {
}
}
}

impl Iterator for Cubes {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/digits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
pub struct Digits {
num: i64,
}

impl Digits {
pub fn new(num: i64) -> Digits {
Digits { num }
}
}

impl Iterator for Digits {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/divisors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Divisors {
current: i64,
other: i64,
}

impl Divisors {
pub fn new(dividend: i64) -> Divisors {
Divisors {
Expand All @@ -18,6 +19,7 @@ impl Divisors {
}
}
}

impl Iterator for Divisors {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ pub struct Fibonacci {
a: i64,
b: i64,
}

impl Fibonacci {
pub fn new(a: i64, b: i64) -> Fibonacci {
Fibonacci { a, b }
}
}

impl Iterator for Fibonacci {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/iterators/polygonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct Polygonal {
offset: i64,
num: i64,
}

impl Polygonal {
pub fn new(sides: i64) -> Polygonal {
Polygonal {
Expand All @@ -13,6 +14,7 @@ impl Polygonal {
num: 0,
}
}

/// Find the index at which the given number would appear in a sequence of
/// polygonal numbers.
///
Expand All @@ -39,6 +41,7 @@ impl Polygonal {
}
}
}

impl Iterator for Polygonal {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/potential_primes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct PotentialPrimes {
num: i64,
offset: std::iter::Cycle<std::array::IntoIter<i64, 8>>,
}

impl PotentialPrimes {
pub fn new(limit: i64) -> PotentialPrimes {
PotentialPrimes {
Expand All @@ -14,6 +15,7 @@ impl PotentialPrimes {
}
}
}

impl Iterator for PotentialPrimes {
type Item = i64;
fn next(&mut self) -> Option<i64> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/prime_divisors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct PrimeDivisors {
potential_primes: utils::PotentialPrimes,
num: i64,
}

impl PrimeDivisors {
pub fn new(num: i64) -> PrimeDivisors {
PrimeDivisors {
Expand All @@ -16,6 +17,7 @@ impl PrimeDivisors {
}
}
}

impl Iterator for PrimeDivisors {
type Item = (i64, u32);
fn next(&mut self) -> Option<(i64, u32)> {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/iterators/pythagorean_triplets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct PythagoreanTriplets {
m_ub: i64,
m: i64,
}

impl PythagoreanTriplets {
pub fn new(perimeter: i64) -> PythagoreanTriplets {
let semiperimeter = perimeter / 2;
Expand All @@ -20,6 +21,7 @@ impl PythagoreanTriplets {
}
}
}

impl Iterator for PythagoreanTriplets {
type Item = (i64, i64, i64);
fn next(&mut self) -> Option<(i64, i64, i64)> {
Expand Down

0 comments on commit 35638b1

Please sign in to comment.