Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bf038b9b
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,发现更多精彩内容 >>
提交
bf038b9b
编写于
1月 06, 2012
作者:
J
Jesse Ruderman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get these files compiling again
上级
373dbe77
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
26 addition
and
24 deletion
+26
-24
src/fuzzer/ast_match.rs
src/fuzzer/ast_match.rs
+8
-6
src/fuzzer/cycles.rs
src/fuzzer/cycles.rs
+5
-5
src/fuzzer/ivec_fuzz.rs
src/fuzzer/ivec_fuzz.rs
+8
-8
src/fuzzer/rand_util.rs
src/fuzzer/rand_util.rs
+5
-5
未找到文件。
src/fuzzer/ast_match.rs
浏览文件 @
bf038b9b
use
std
;
import
vec
;
fn
vec_equal
<
T
>
(
v
:
[
T
],
u
:
[
T
],
element_equality_test
:
fn
(
T
,
T
)
->
bool
)
->
fn
vec_equal
<
T
>
(
v
:
[
T
],
u
:
[
T
],
element_equality_test
:
fn
@
(
&&
T
,
&&
T
)
->
bool
)
->
bool
{
let
Lv
=
vec
::
len
(
v
);
if
Lv
!=
vec
::
len
(
u
)
{
ret
false
;
}
...
...
@@ -13,15 +13,17 @@ fn vec_equal<T>(v: [T], u: [T], element_equality_test: fn(T, T) -> bool) ->
ret
true
;
}
fn
builtin_equal
<
T
>
(
a
:
T
,
b
:
T
)
->
bool
{
ret
a
==
b
;
}
pure
fn
builtin_equal
<
T
>
(
&&
a
:
T
,
&&
b
:
T
)
->
bool
{
ret
a
==
b
;
}
pure
fn
builtin_equal_int
(
&&
a
:
int
,
&&
b
:
int
)
->
bool
{
ret
a
==
b
;
}
fn
main
()
{
assert
(
builtin_equal
(
5
,
5
));
assert
(
!
builtin_equal
(
5
,
4
));
assert
(
!
vec_equal
([
5
,
5
],
[
5
],
builtin_equal
));
assert
(
!
vec_equal
([
5
,
5
],
[
5
,
4
],
builtin_equal
));
assert
(
!
vec_equal
([
5
,
5
],
[
4
,
5
],
builtin_equal
));
assert
(
vec_equal
([
5
,
5
],
[
5
,
5
],
builtin_equal
));
assert
(
!
vec_equal
([
5
,
5
],
[
5
],
bind
builtin_equal
(
_
,
_
)));
assert
(
!
vec_equal
([
5
,
5
],
[
5
],
builtin_equal_int
));
assert
(
!
vec_equal
([
5
,
5
],
[
5
,
4
],
builtin_equal_int
));
assert
(
!
vec_equal
([
5
,
5
],
[
4
,
5
],
builtin_equal_int
));
assert
(
vec_equal
([
5
,
5
],
[
5
,
5
],
builtin_equal_int
));
#
error
(
"Pass"
);
}
src/fuzzer/cycles.rs
浏览文件 @
bf038b9b
...
...
@@ -7,7 +7,7 @@
fn
under
(
r
:
rand
::
rng
,
n
:
uint
)
->
uint
{
assert
n
!=
0u
;
r
.next
()
as
uint
%
n
}
// random choice from a vec
fn
choice
<
T
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
T
{
assert
vec
::
len
(
v
)
!=
0u
;
v
[
under
(
r
,
vec
::
len
(
v
))]
}
fn
choice
<
T
:
copy
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
T
{
assert
vec
::
len
(
v
)
!=
0u
;
v
[
under
(
r
,
vec
::
len
(
v
))]
}
// 1 in n chance of being true
fn
unlikely
(
r
:
rand
::
rng
,
n
:
uint
)
->
bool
{
under
(
r
,
n
)
==
0u
}
...
...
@@ -20,7 +20,7 @@ fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u }
type
pointy
=
{
mutable
x
:
maybe_pointy
,
mutable
y
:
maybe_pointy
,
mutable
z
:
fn
()
->
()
mutable
z
:
fn
@
()
->
()
};
fn
allunder
(
n
:
uint
,
it
:
block
(
uint
))
{
...
...
@@ -36,8 +36,8 @@ fn test_cycles(r : rand::rng)
const
max
:
uint
=
10u
;
let
v
:
[
mutable
@
pointy
]
=
[
mutable
];
allunder
(
max
)
{|
i
|
v
+=
[
mutable
@
{
mutable
x
:
no_pointy
,
mutable
y
:
no_pointy
,
mutable
z
:
nop
}];
allunder
(
max
)
{|
_
i
|
v
+=
[
mutable
@
{
mutable
x
:
no_pointy
,
mutable
y
:
no_pointy
,
mutable
z
:
bind
nop
()
}];
}
allunder
(
max
)
{|
i
|
...
...
@@ -48,7 +48,7 @@ fn test_cycles(r : rand::rng)
// Drop refs one at a time
allunder
(
max
)
{|
i
|
v
[
i
]
=
@
{
mutable
x
:
no_pointy
,
mutable
y
:
no_pointy
,
mutable
z
:
nop
};
v
[
i
]
=
@
{
mutable
x
:
no_pointy
,
mutable
y
:
no_pointy
,
mutable
z
:
bind
nop
()
};
}
}
...
...
src/fuzzer/ivec_fuzz.rs
浏览文件 @
bf038b9b
...
...
@@ -22,22 +22,22 @@
import
vec
::
len
;
import
int
;
fn
vec_omit
<
T
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
fn
vec_omit
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
+
slice
(
v
,
i
+
1u
,
len
(
v
))
}
fn
vec_dup
<
T
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
fn
vec_dup
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
+
[
v
[
i
]]
+
slice
(
v
,
i
,
len
(
v
))
}
fn
vec_swadj
<
T
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
fn
vec_swadj
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
+
[
v
[
i
+
1u
],
v
[
i
]]
+
slice
(
v
,
i
+
2u
,
len
(
v
))
}
fn
vec_prefix
<
T
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
}
fn
vec_suffix
<
T
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
i
,
len
(
v
))
}
fn
vec_prefix
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
}
fn
vec_suffix
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
)
->
[
T
]
{
slice
(
v
,
i
,
len
(
v
))
}
fn
vec_poke
<
T
>
(
v
:
[
T
],
i
:
uint
,
x
:
T
)
->
[
T
]
{
fn
vec_poke
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
,
x
:
T
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
+
[
x
]
+
slice
(
v
,
i
+
1u
,
len
(
v
))
}
fn
vec_insert
<
T
>
(
v
:
[
T
],
i
:
uint
,
x
:
T
)
->
[
T
]
{
fn
vec_insert
<
T
:
copy
>
(
v
:
[
T
],
i
:
uint
,
x
:
T
)
->
[
T
]
{
slice
(
v
,
0u
,
i
)
+
[
x
]
+
slice
(
v
,
i
,
len
(
v
))
}
...
...
@@ -48,7 +48,7 @@ fn ix(skip_low: uint, skip_high: uint, length: uint, it: block(uint)) {
}
// Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs).
fn
vec_edits
<
T
>
(
v
:
[
T
],
xs
:
[
T
])
->
[[
T
]]
{
fn
vec_edits
<
T
:
copy
>
(
v
:
[
T
],
xs
:
[
T
])
->
[[
T
]]
{
let
edits
:
[[
T
]]
=
[];
let
Lv
:
uint
=
len
(
v
);
...
...
src/fuzzer/rand_util.rs
浏览文件 @
bf038b9b
...
...
@@ -6,7 +6,7 @@
fn
under
(
r
:
rand
::
rng
,
n
:
uint
)
->
uint
{
assert
n
!=
0u
;
r
.next
()
as
uint
%
n
}
// random choice from a vec
fn
choice
<
T
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
T
{
assert
vec
::
len
(
v
)
!=
0u
;
v
[
under
(
r
,
vec
::
len
(
v
))]
}
fn
choice
<
T
:
copy
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
T
{
assert
vec
::
len
(
v
)
!=
0u
;
v
[
under
(
r
,
vec
::
len
(
v
))]
}
// 1 in n chance of being true
fn
unlikely
(
r
:
rand
::
rng
,
n
:
uint
)
->
bool
{
under
(
r
,
n
)
==
0u
}
...
...
@@ -22,7 +22,7 @@ fn shuffle<T>(r : rand::rng, &v : [mutable T]) {
}
// create a shuffled copy of a vec
fn
shuffled
<
T
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
[
T
]
{
fn
shuffled
<
T
:
copy
>
(
r
:
rand
::
rng
,
v
:
[
T
])
->
[
T
]
{
let
w
=
vec
::
to_mut
(
v
);
shuffle
(
r
,
w
);
vec
::
from_mut
(
w
)
// Shouldn't this happen automatically?
...
...
@@ -35,7 +35,7 @@ fn shuffled<T>(r : rand::rng, v : [T]) -> [T] {
// * weighted_choice is O(number of choices) time
// * weighted_vec is O(total weight) space
type
weighted
<
T
>
=
{
weight
:
uint
,
item
:
T
};
fn
weighted_choice
<
T
>
(
r
:
rand
::
rng
,
v
:
[
weighted
<
T
>
])
->
T
{
fn
weighted_choice
<
T
:
copy
>
(
r
:
rand
::
rng
,
v
:
[
weighted
<
T
>
])
->
T
{
assert
vec
::
len
(
v
)
!=
0u
;
let
total
=
0u
;
for
{
weight
:
weight
,
item
:
_
}
in
v
{
...
...
@@ -53,7 +53,7 @@ fn weighted_choice<T>(r : rand::rng, v : [weighted<T>]) -> T {
std
::
util
::
unreachable
();
}
fn
weighted_vec
<
T
>
(
v
:
[
weighted
<
T
>
])
->
[
T
]
{
fn
weighted_vec
<
T
:
copy
>
(
v
:
[
weighted
<
T
>
])
->
[
T
]
{
let
r
=
[];
for
{
weight
:
weight
,
item
:
item
}
in
v
{
let
i
=
0u
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录