Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
42cafcee
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,发现更多精彩内容 >>
提交
42cafcee
编写于
1月 29, 2013
作者:
D
Daniel Micay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add is_disjoint to the Set trait
上级
bfa9c9a0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
30 deletion
+61
-30
src/libcore/container.rs
src/libcore/container.rs
+4
-0
src/libcore/hashmap.rs
src/libcore/hashmap.rs
+30
-3
src/libstd/treemap.rs
src/libstd/treemap.rs
+27
-27
未找到文件。
src/libcore/container.rs
浏览文件 @
42cafcee
...
...
@@ -66,6 +66,10 @@ pub trait Set<T>: Mutable {
/// present in the set.
fn
remove
(
&
mut
self
,
value
:
&
T
)
->
bool
;
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure
fn
is_disjoint
(
&
self
,
other
:
&
self
)
->
bool
;
/// Return true if the set is a subset of another
pure
fn
is_subset
(
&
self
,
other
:
&
self
)
->
bool
;
...
...
src/libcore/hashmap.rs
浏览文件 @
42cafcee
...
...
@@ -14,16 +14,15 @@
#[forbid(deprecated_mode)]
;
#[forbid(deprecated_pattern)]
;
use
container
::{
Container
,
Mutable
,
Map
,
Set
};
use
cmp
::
Eq
;
use
hash
::
Hash
;
use
to_bytes
::
IterBytes
;
/// Open addressing with linear probing.
pub
mod
linear
{
use
super
::
*
;
use
iter
::
BaseIter
;
use
container
::{
Container
,
Mutable
,
Map
,
Set
};
use
cmp
::
Eq
;
use
cmp
;
use
hash
::
Hash
;
use
iter
;
use
kinds
::
Copy
;
...
...
@@ -455,6 +454,12 @@ fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) }
/// present in the set.
fn
remove
(
&
mut
self
,
value
:
&
T
)
->
bool
{
self
.map
.remove
(
value
)
}
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure
fn
is_disjoint
(
&
self
,
other
:
&
LinearSet
<
T
>
)
->
bool
{
iter
::
all
(
self
,
|
v
|
!
other
.contains
(
v
))
}
/// Return true if the set is a subset of another
pure
fn
is_subset
(
&
self
,
other
:
&
LinearSet
<
T
>
)
->
bool
{
iter
::
all
(
self
,
|
v
|
other
.contains
(
v
))
...
...
@@ -626,6 +631,28 @@ pub fn test_expand() {
mod
test_set
{
use
super
::
*
;
#[test]
fn
test_disjoint
()
{
let
mut
xs
=
linear
::
LinearSet
::
new
();
let
mut
ys
=
linear
::
LinearSet
::
new
();
assert
xs
.is_disjoint
(
&
ys
);
assert
ys
.is_disjoint
(
&
xs
);
assert
xs
.insert
(
5
);
assert
ys
.insert
(
11
);
assert
xs
.is_disjoint
(
&
ys
);
assert
ys
.is_disjoint
(
&
xs
);
assert
xs
.insert
(
7
);
assert
xs
.insert
(
19
);
assert
xs
.insert
(
4
);
assert
ys
.insert
(
2
);
assert
ys
.insert
(
-
11
);
assert
xs
.is_disjoint
(
&
ys
);
assert
ys
.is_disjoint
(
&
xs
);
assert
ys
.insert
(
7
);
assert
!
xs
.is_disjoint
(
&
ys
);
assert
!
ys
.is_disjoint
(
&
xs
);
}
#[test]
fn
test_subset_and_superset
()
{
let
mut
a
=
linear
::
LinearSet
::
new
();
...
...
src/libstd/treemap.rs
浏览文件 @
42cafcee
...
...
@@ -292,6 +292,33 @@ fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) }
/// present in the set.
fn
remove
(
&
mut
self
,
value
:
&
T
)
->
bool
{
self
.map
.remove
(
value
)
}
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure
fn
is_disjoint
(
&
self
,
other
:
&
TreeSet
<
T
>
)
->
bool
{
let
mut
x
=
self
.iter
();
let
mut
y
=
other
.iter
();
unsafe
{
// purity workaround
x
=
x
.next
();
y
=
y
.next
();
let
mut
a
=
x
.get
();
let
mut
b
=
y
.get
();
while
a
.is_some
()
&&
b
.is_some
()
{
let
a1
=
a
.unwrap
();
let
b1
=
b
.unwrap
();
if
a1
<
b1
{
x
=
x
.next
();
a
=
x
.get
();
}
else
if
b1
<
a1
{
y
=
y
.next
();
b
=
y
.get
();
}
else
{
return
false
;
}
}
}
true
}
/// Return true if the set is a subset of another
pure
fn
is_subset
(
&
self
,
other
:
&
TreeSet
<
T
>
)
->
bool
{
other
.is_superset
(
self
)
...
...
@@ -345,33 +372,6 @@ impl <T: Ord> TreeSet<T> {
TreeSetIterator
{
iter
:
self
.map
.iter
()}
}
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure
fn
is_disjoint
(
&
self
,
other
:
&
TreeSet
<
T
>
)
->
bool
{
let
mut
x
=
self
.iter
();
let
mut
y
=
other
.iter
();
unsafe
{
// purity workaround
x
=
x
.next
();
y
=
y
.next
();
let
mut
a
=
x
.get
();
let
mut
b
=
y
.get
();
while
a
.is_some
()
&&
b
.is_some
()
{
let
a1
=
a
.unwrap
();
let
b1
=
b
.unwrap
();
if
a1
<
b1
{
x
=
x
.next
();
a
=
x
.get
();
}
else
if
b1
<
a1
{
y
=
y
.next
();
b
=
y
.get
();
}
else
{
return
false
;
}
}
}
true
}
/// Visit the values (in-order) representing the difference
pure
fn
difference
(
&
self
,
other
:
&
TreeSet
<
T
>
,
f
:
fn
(
&
T
)
->
bool
)
{
let
mut
x
=
self
.iter
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录