This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// date: 2020-01-10 | |
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
// author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com | |
#![feature(generators)] | |
#![feature(generator_trait)] | |
use std::ops::{Generator, GeneratorState}; | |
use std::pin::Pin; | |
struct GeneratorIter<T: Generator + Unpin>(T); | |
impl<T: Generator + Unpin> Iterator for GeneratorIter<T> { | |
type Item = <T as Generator>::Yield; | |
fn next(&mut self) -> Option<Self::Item> { | |
match Pin::new(&mut self.0).resume(()) { | |
GeneratorState::Yielded(x) => Some(x), | |
_ => None | |
} | |
} | |
} | |
fn prime_generator() -> impl Generator<Yield=u16, Return=()> { | |
|| { | |
yield 2; | |
yield 3; | |
let mut l = vec![3]; | |
let mut n = 5u16; | |
loop { | |
for &i in &l { | |
let (q, r) = (n / i, n % i); | |
if i > q { | |
l.push(n); | |
yield n; | |
break; | |
} else if r == 0 { | |
break; | |
} | |
} | |
n = n.wrapping_add(2); | |
} | |
} | |
} | |
fn sha2_constant(root: f64) -> u32 { | |
(root.fract() * (1u64 << 32) as f64) as u32 | |
} | |
fn main() { | |
for v in GeneratorIter(prime_generator()).take(8) { | |
print!("{:#010x}, ", sha2_constant((v as f64).sqrt())); | |
} | |
println!("\n"); | |
for (i, v) in GeneratorIter(prime_generator()).take(64).enumerate() { | |
print!("{:#010x}, ", sha2_constant((v as f64).cbrt())); | |
if i % 8 == 7 { | |
println!(); | |
} | |
} | |
} |
Author
nanpuyue
commented
Jan 10, 2020
hey, is it possible to work with firefox's css thing to combine titlebar and menubar instead of hiding title bar all together?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment