Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b69fb753
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
b69fb753
编写于
3月 08, 2013
作者:
D
Daniel Micay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement BaseIter for dlist (removing iter-trait)
Closes #2827
上级
eaed16ce
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
151 deletion
+43
-151
src/libcore/core.rc
src/libcore/core.rc
+0
-2
src/libcore/dlist.rs
src/libcore/dlist.rs
+43
-1
src/libcore/iter-trait.rs
src/libcore/iter-trait.rs
+0
-89
src/libcore/iter-trait/dlist.rs
src/libcore/iter-trait/dlist.rs
+0
-59
未找到文件。
src/libcore/core.rc
浏览文件 @
b69fb753
...
...
@@ -142,8 +142,6 @@ pub mod option;
pub mod result;
pub mod either;
pub mod dlist;
#[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"]
pub mod dlist_iter;
pub mod hashmap;
pub mod cell;
pub mod trie;
...
...
src/libcore/dlist.rs
浏览文件 @
b69fb753
...
...
@@ -18,6 +18,8 @@
*/
use
iter
;
use
iter
::
BaseIter
;
use
kinds
::
Copy
;
use
managed
;
use
option
::{
None
,
Option
,
Some
};
...
...
@@ -489,7 +491,7 @@ fn pop_tail(@mut self) -> Option<T> {
let
mut
v
=
vec
::
with_capacity
(
self
.size
);
unsafe
{
// Take this out of the unchecked when iter's functions are pure
for
self
.eachi
|
index
,
data
|
{
for
iter
::
eachi
(
&
self
)
|
index
,
data
|
{
v
[
index
]
=
*
data
;
}
}
...
...
@@ -497,6 +499,46 @@ fn pop_tail(@mut self) -> Option<T> {
}
}
impl
<
T
>
BaseIter
<
T
>
for
@
mut
DList
<
T
>
{
/**
* Iterates through the current contents.
*
* Attempts to access this dlist during iteration are allowed (to
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pure
fn
each
(
&
self
,
f
:
fn
(
v
:
&
T
)
->
bool
)
{
let
mut
link
=
self
.peek_n
();
while
option
::
is_some
(
&
link
)
{
let
nobe
=
option
::
get
(
link
);
fail_unless!
(
nobe
.linked
);
{
let
frozen_nobe
=
&*
nobe
;
if
!
f
(
&
frozen_nobe
.data
)
{
break
;
}
}
// Check (weakly) that the user didn't do a remove.
if
self
.size
==
0
{
fail
!
(
~
"The dlist became empty during iteration??"
)
}
if
!
nobe
.linked
||
(
!
((
nobe
.prev
.is_some
()
||
managed
::
mut_ptr_eq
(
self
.hd
.expect
(
~
"headless dlist?"
),
nobe
))
&&
(
nobe
.next
.is_some
()
||
managed
::
mut_ptr_eq
(
self
.tl
.expect
(
~
"tailless dlist?"
),
nobe
))))
{
fail
!
(
~
"Removing a dlist node during iteration is forbidden!"
)
}
link
=
nobe
.next_link
();
}
}
#[inline(always)]
pure
fn
size_hint
(
&
self
)
->
Option
<
uint
>
{
Some
(
self
.len
())
}
}
#[cfg(test)]
mod
tests
{
use
dlist
::{
DList
,
concat
,
from_vec
,
new_dlist_node
};
...
...
src/libcore/iter-trait.rs
已删除
100644 → 0
浏览文件 @
eaed16ce
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This makes use of a clever hack that brson came up with to
// workaround our lack of traits and lack of macros. See core.{rc,rs} for
// how this file is used.
use
cmp
::{
Eq
,
Ord
};
use
iter
::
BaseIter
;
use
iter
;
use
kinds
::
Copy
;
use
option
::
Option
;
use
self
::
inst
::{
IMPL_T
,
EACH
,
SIZE_HINT
};
impl
<
A
>
iter
::
BaseIter
<
A
>
for
IMPL_T
<
A
>
{
#[inline(always)]
pure
fn
each
(
&
self
,
blk
:
fn
(
v
:
&
A
)
->
bool
)
{
EACH
(
self
,
blk
)
}
#[inline(always)]
pure
fn
size_hint
(
&
self
)
->
Option
<
uint
>
{
SIZE_HINT
(
self
)
}
}
impl
<
A
>
iter
::
ExtendedIter
<
A
>
for
IMPL_T
<
A
>
{
#[inline(always)]
pure
fn
eachi
(
&
self
,
blk
:
fn
(
uint
,
v
:
&
A
)
->
bool
)
{
iter
::
eachi
(
self
,
blk
)
}
#[inline(always)]
pure
fn
all
(
&
self
,
blk
:
fn
(
&
A
)
->
bool
)
->
bool
{
iter
::
all
(
self
,
blk
)
}
#[inline(always)]
pure
fn
any
(
&
self
,
blk
:
fn
(
&
A
)
->
bool
)
->
bool
{
iter
::
any
(
self
,
blk
)
}
#[inline(always)]
pure
fn
foldl
<
B
>
(
&
self
,
b0
:
B
,
blk
:
fn
(
&
B
,
&
A
)
->
B
)
->
B
{
iter
::
foldl
(
self
,
b0
,
blk
)
}
#[inline(always)]
pure
fn
position
(
&
self
,
f
:
fn
(
&
A
)
->
bool
)
->
Option
<
uint
>
{
iter
::
position
(
self
,
f
)
}
#[inline(always)]
pure
fn
map_to_vec
<
B
>
(
&
self
,
op
:
fn
(
&
A
)
->
B
)
->
~
[
B
]
{
iter
::
map_to_vec
(
self
,
op
)
}
#[inline(always)]
pure
fn
flat_map_to_vec
<
B
,
IB
:
BaseIter
<
B
>>
(
&
self
,
op
:
fn
(
&
A
)
->
IB
)
->
~
[
B
]
{
iter
::
flat_map_to_vec
(
self
,
op
)
}
}
impl
<
A
:
Eq
>
iter
::
EqIter
<
A
>
for
IMPL_T
<
A
>
{
#[inline(always)]
pure
fn
contains
(
&
self
,
x
:
&
A
)
->
bool
{
iter
::
contains
(
self
,
x
)
}
#[inline(always)]
pure
fn
count
(
&
self
,
x
:
&
A
)
->
uint
{
iter
::
count
(
self
,
x
)
}
}
impl
<
A
:
Copy
>
iter
::
CopyableIter
<
A
>
for
IMPL_T
<
A
>
{
#[inline(always)]
pure
fn
filter_to_vec
(
&
self
,
pred
:
fn
(
&
A
)
->
bool
)
->
~
[
A
]
{
iter
::
filter_to_vec
(
self
,
pred
)
}
#[inline(always)]
pure
fn
to_vec
(
&
self
)
->
~
[
A
]
{
iter
::
to_vec
(
self
)
}
#[inline(always)]
pure
fn
find
(
&
self
,
f
:
fn
(
&
A
)
->
bool
)
->
Option
<
A
>
{
iter
::
find
(
self
,
f
)
}
}
impl
<
A
:
Copy
+
Ord
>
iter
::
CopyableOrderedIter
<
A
>
for
IMPL_T
<
A
>
{
#[inline(always)]
pure
fn
min
(
&
self
)
->
A
{
iter
::
min
(
self
)
}
#[inline(always)]
pure
fn
max
(
&
self
)
->
A
{
iter
::
max
(
self
)
}
}
src/libcore/iter-trait/dlist.rs
已删除
100644 → 0
浏览文件 @
eaed16ce
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
mod
inst
{
use
dlist
::
DList
;
use
managed
;
use
option
::{
Option
,
Some
};
use
option
;
#[allow(non_camel_case_types)]
pub
type
IMPL_T
<
A
>
=
@
mut
DList
<
A
>
;
/**
* Iterates through the current contents.
*
* Attempts to access this dlist during iteration are allowed (to
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pub
pure
fn
EACH
<
A
>
(
self
:
&
IMPL_T
<
A
>
,
f
:
fn
(
v
:
&
A
)
->
bool
)
{
let
mut
link
=
self
.peek_n
();
while
option
::
is_some
(
&
link
)
{
let
nobe
=
option
::
get
(
link
);
fail_unless!
(
nobe
.linked
);
{
let
frozen_nobe
=
&*
nobe
;
if
!
f
(
&
frozen_nobe
.data
)
{
break
;
}
}
// Check (weakly) that the user didn't do a remove.
if
self
.size
==
0
{
fail
!
(
~
"The dlist became empty during iteration??"
)
}
if
!
nobe
.linked
||
(
!
((
nobe
.prev
.is_some
()
||
managed
::
mut_ptr_eq
(
self
.hd
.expect
(
~
"headless dlist?"
),
nobe
))
&&
(
nobe
.next
.is_some
()
||
managed
::
mut_ptr_eq
(
self
.tl
.expect
(
~
"tailless dlist?"
),
nobe
))))
{
fail
!
(
~
"Removing a dlist node during iteration is forbidden!"
)
}
link
=
nobe
.next_link
();
}
}
#[inline(always)]
pub
pure
fn
SIZE_HINT
<
A
>
(
self
:
&
IMPL_T
<
A
>
)
->
Option
<
uint
>
{
Some
(
self
.len
())
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录