Skip to content

Commit

Permalink
Inline more random helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 24, 2018
1 parent e679836 commit 865398a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bigrand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub struct UniformBigUint {
impl UniformSampler for UniformBigUint {
type X = BigUint;

#[inline]
fn new(low: Self::X, high: Self::X) -> Self {
assert!(low < high);
UniformBigUint {
Expand All @@ -126,15 +127,18 @@ impl UniformSampler for UniformBigUint {
}
}

#[inline]
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
assert!(low <= high);
Self::new(low, high + 1u32)
}

#[inline]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
&self.base + rng.gen_biguint_below(&self.len)
}

#[inline]
fn sample_single<R: Rng + ?Sized>(low: Self::X, high: Self::X, rng: &mut R) -> Self::X {
rng.gen_biguint_range(&low, &high)
}
Expand All @@ -155,6 +159,7 @@ pub struct UniformBigInt {
impl UniformSampler for UniformBigInt {
type X = BigInt;

#[inline]
fn new(low: Self::X, high: Self::X) -> Self {
assert!(low < high);
UniformBigInt {
Expand All @@ -163,15 +168,18 @@ impl UniformSampler for UniformBigInt {
}
}

#[inline]
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
assert!(low <= high);
Self::new(low, high + 1u32)
}

#[inline]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
&self.base + BigInt::from(rng.gen_biguint_below(&self.len))
}

#[inline]
fn sample_single<R: Rng + ?Sized>(low: Self::X, high: Self::X, rng: &mut R) -> Self::X {
rng.gen_bigint_range(&low, &high)
}
Expand Down

0 comments on commit 865398a

Please sign in to comment.