#![doc = include_str!("../README.md")]
#[derive(Clone, Copy)]
pub struct XorShift64(pub u64);
impl XorShift64 {
pub fn get(&mut self) -> u64 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 7;
self.0 ^= self.0 << 17;
self.0
}
}
impl Iterator for XorShift64 {
type Item = u64;
#[inline] fn next(&mut self) -> Option<Self::Item> {
Some(self.get())
}
#[inline] fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, None)
}
}
#[derive(Clone, Copy)]
pub struct XorShift32(pub u32);
impl XorShift32 {
pub fn get(&mut self) -> u32 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 17;
self.0 ^= self.0 << 5;
self.0
}
}
impl Iterator for XorShift32 {
type Item = u32;
#[inline] fn next(&mut self) -> Option<Self::Item> { Some(self.get()) }
#[inline] fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
}
pub trait UnitPrefix {
fn as_milis(self) -> Self;
fn as_micros(self) -> Self;
fn as_nanos(self) -> Self;
fn as_picos(self) -> Self;
}
impl UnitPrefix for f64 {
#[inline(always)] fn as_milis(self) -> f64 { self * 1_000.0 }
#[inline(always)] fn as_micros(self) -> f64 { self * 1_000_000.0 }
#[inline(always)] fn as_nanos(self) -> f64 { self * 1_000_000_000.0 }
#[inline(always)] fn as_picos(self) -> f64 { self * 1_000_000_000_000.0 }
}