Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a18d090c
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a18d090c
编写于
12月 14, 2014
作者:
J
Jorge Aparicio
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
librand: use `#[deriving(Copy)]`
上级
e0a88a78
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
10 addition
and
20 deletion
+10
-20
src/librand/chacha.rs
src/librand/chacha.rs
+1
-2
src/librand/distributions/exponential.rs
src/librand/distributions/exponential.rs
+2
-5
src/librand/distributions/normal.rs
src/librand/distributions/normal.rs
+3
-7
src/librand/isaac.rs
src/librand/isaac.rs
+2
-4
src/librand/lib.rs
src/librand/lib.rs
+1
-0
src/librand/reseeding.rs
src/librand/reseeding.rs
+1
-2
未找到文件。
src/librand/chacha.rs
浏览文件 @
a18d090c
...
...
@@ -29,14 +29,13 @@
/// [1]: D. J. Bernstein, [*ChaCha, a variant of
/// Salsa20*](http://cr.yp.to/chacha.html)
#[deriving(Copy)]
pub
struct
ChaChaRng
{
buffer
:
[
u32
,
..
STATE_WORDS
],
// Internal buffer of output
state
:
[
u32
,
..
STATE_WORDS
],
// Initial state
index
:
uint
,
// Index into state
}
impl
Copy
for
ChaChaRng
{}
static
EMPTY
:
ChaChaRng
=
ChaChaRng
{
buffer
:
[
0
,
..
STATE_WORDS
],
state
:
[
0
,
..
STATE_WORDS
],
...
...
src/librand/distributions/exponential.rs
浏览文件 @
a18d090c
...
...
@@ -10,7 +10,6 @@
//! The exponential distribution.
use
core
::
kinds
::
Copy
;
use
core
::
num
::
Float
;
use
{
Rng
,
Rand
};
...
...
@@ -30,10 +29,9 @@
/// Generate Normal Random
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
/// College, Oxford
#[deriving(Copy)]
pub
struct
Exp1
(
pub
f64
);
impl
Copy
for
Exp1
{}
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
impl
Rand
for
Exp1
{
#[inline]
...
...
@@ -69,13 +67,12 @@ fn zero_case<R:Rng>(rng: &mut R, _u: f64) -> f64 {
/// let v = exp.ind_sample(&mut rand::task_rng());
/// println!("{} is from a Exp(2) distribution", v);
/// ```
#[deriving(Copy)]
pub
struct
Exp
{
/// `lambda` stored as `1/lambda`, since this is what we scale by.
lambda_inverse
:
f64
}
impl
Copy
for
Exp
{}
impl
Exp
{
/// Construct a new `Exp` with the given shape parameter
/// `lambda`. Panics if `lambda <= 0`.
...
...
src/librand/distributions/normal.rs
浏览文件 @
a18d090c
...
...
@@ -10,7 +10,6 @@
//! The normal and derived distributions.
use
core
::
kinds
::
Copy
;
use
core
::
num
::
Float
;
use
{
Rng
,
Rand
,
Open01
};
...
...
@@ -29,10 +28,9 @@
/// Generate Normal Random
/// Samples*](http://www.doornik.com/research/ziggurat.pdf). Nuffield
/// College, Oxford
#[deriving(Copy)]
pub
struct
StandardNormal
(
pub
f64
);
impl
Copy
for
StandardNormal
{}
impl
Rand
for
StandardNormal
{
fn
rand
<
R
:
Rng
>
(
rng
:
&
mut
R
)
->
StandardNormal
{
#[inline]
...
...
@@ -86,13 +84,12 @@ fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
/// let v = normal.ind_sample(&mut rand::task_rng());
/// println!("{} is from a N(2, 9) distribution", v)
/// ```
#[deriving(Copy)]
pub
struct
Normal
{
mean
:
f64
,
std_dev
:
f64
,
}
impl
Copy
for
Normal
{}
impl
Normal
{
/// Construct a new `Normal` distribution with the given mean and
/// standard deviation.
...
...
@@ -135,12 +132,11 @@ fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
/// let v = log_normal.ind_sample(&mut rand::task_rng());
/// println!("{} is from an ln N(2, 9) distribution", v)
/// ```
#[deriving(Copy)]
pub
struct
LogNormal
{
norm
:
Normal
}
impl
Copy
for
LogNormal
{}
impl
LogNormal
{
/// Construct a new `LogNormal` distribution with the given mean
/// and standard deviation.
...
...
src/librand/isaac.rs
浏览文件 @
a18d090c
...
...
@@ -29,6 +29,7 @@
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
#[deriving(Copy)]
pub
struct
IsaacRng
{
cnt
:
u32
,
rsl
:
[
u32
,
..
RAND_SIZE_UINT
],
...
...
@@ -38,8 +39,6 @@ pub struct IsaacRng {
c
:
u32
}
impl
Copy
for
IsaacRng
{}
static
EMPTY
:
IsaacRng
=
IsaacRng
{
cnt
:
0
,
rsl
:
[
0
,
..
RAND_SIZE_UINT
],
...
...
@@ -265,6 +264,7 @@ fn rand<R: Rng>(other: &mut R) -> IsaacRng {
///
/// [1]: Bob Jenkins, [*ISAAC: A fast cryptographic random number
/// generator*](http://www.burtleburtle.net/bob/rand/isaacafa.html)
#[deriving(Copy)]
pub
struct
Isaac64Rng
{
cnt
:
uint
,
rsl
:
[
u64
,
..
RAND_SIZE_64
],
...
...
@@ -274,8 +274,6 @@ pub struct Isaac64Rng {
c
:
u64
,
}
impl
Copy
for
Isaac64Rng
{}
static
EMPTY_64
:
Isaac64Rng
=
Isaac64Rng
{
cnt
:
0
,
rsl
:
[
0
,
..
RAND_SIZE_64
],
...
...
src/librand/lib.rs
浏览文件 @
a18d090c
...
...
@@ -501,6 +501,7 @@ fn rand<R: Rng>(rng: &mut R) -> XorShiftRng {
#[cfg(not(test))]
mod
std
{
pub
use
core
::{
option
,
fmt
};
// panic!()
pub
use
core
::
kinds
;
}
#[cfg(test)]
...
...
src/librand/reseeding.rs
浏览文件 @
a18d090c
...
...
@@ -133,10 +133,9 @@ pub trait Reseeder<R> {
/// Reseed an RNG using a `Default` instance. This reseeds by
/// replacing the RNG with the result of a `Default::default` call.
#[deriving(Copy)]
pub
struct
ReseedWithDefault
;
impl
Copy
for
ReseedWithDefault
{}
impl
<
R
:
Rng
+
Default
>
Reseeder
<
R
>
for
ReseedWithDefault
{
fn
reseed
(
&
mut
self
,
rng
:
&
mut
R
)
{
*
rng
=
Default
::
default
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录