Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
42389b70
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,发现更多精彩内容 >>
提交
42389b70
编写于
3月 06, 2014
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
collections: Correct with_capacity_and_hasher
The arguments were accidentally swapped in the wrong order. Closes #12743
上级
0e95b086
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
12 deletion
+13
-12
src/libcollections/hashmap.rs
src/libcollections/hashmap.rs
+11
-10
src/libserialize/collection_impls.rs
src/libserialize/collection_impls.rs
+2
-2
未找到文件。
src/libcollections/hashmap.rs
浏览文件 @
42389b70
...
...
@@ -358,13 +358,13 @@ pub fn new() -> HashMap<K, V, SipHasher> {
pub
fn
with_capacity
(
capacity
:
uint
)
->
HashMap
<
K
,
V
>
{
let
mut
r
=
rand
::
task_rng
();
let
hasher
=
SipHasher
::
new_with_keys
(
r
.gen
(),
r
.gen
());
HashMap
::
with_capacity_and_hasher
(
hasher
,
capacity
)
HashMap
::
with_capacity_and_hasher
(
capacity
,
hasher
)
}
}
impl
<
K
:
Hash
<
S
>
+
Eq
,
V
,
S
,
H
:
Hasher
<
S
>>
HashMap
<
K
,
V
,
H
>
{
pub
fn
with_hasher
(
hasher
:
H
)
->
HashMap
<
K
,
V
,
H
>
{
HashMap
::
with_capacity_and_hasher
(
hasher
,
INITIAL_CAPACITY
)
HashMap
::
with_capacity_and_hasher
(
INITIAL_CAPACITY
,
hasher
)
}
/// Create an empty HashMap with space for at least `capacity`
...
...
@@ -374,7 +374,7 @@ pub fn with_hasher(hasher: H) -> HashMap<K, V, H> {
/// is designed to allow HashMaps to be resistant to attacks that
/// cause many collisions and very poor performance. Setting it
/// manually using this function can expose a DoS attack vector.
pub
fn
with_capacity_and_hasher
(
hasher
:
H
,
capacity
:
uint
)
->
HashMap
<
K
,
V
,
H
>
{
pub
fn
with_capacity_and_hasher
(
capacity
:
uint
,
hasher
:
H
)
->
HashMap
<
K
,
V
,
H
>
{
let
cap
=
max
(
INITIAL_CAPACITY
,
capacity
);
HashMap
{
hasher
:
hasher
,
...
...
@@ -587,7 +587,8 @@ fn ne(&self, other: &HashMap<K, V, H>) -> bool { !self.eq(other) }
impl
<
K
:
Hash
<
S
>
+
Eq
+
Clone
,
V
:
Clone
,
S
,
H
:
Hasher
<
S
>
+
Clone
>
Clone
for
HashMap
<
K
,
V
,
H
>
{
fn
clone
(
&
self
)
->
HashMap
<
K
,
V
,
H
>
{
let
mut
new_map
=
HashMap
::
with_capacity_and_hasher
(
self
.hasher
.clone
(),
self
.len
());
let
mut
new_map
=
HashMap
::
with_capacity_and_hasher
(
self
.len
(),
self
.hasher
.clone
());
for
(
key
,
value
)
in
self
.iter
()
{
new_map
.insert
((
*
key
)
.clone
(),
(
*
value
)
.clone
());
}
...
...
@@ -714,7 +715,7 @@ fn next(&mut self) -> Option<K> {
impl
<
K
:
Hash
<
S
>
+
Eq
,
V
,
S
,
H
:
Hasher
<
S
>
+
Default
>
FromIterator
<
(
K
,
V
)
>
for
HashMap
<
K
,
V
,
H
>
{
fn
from_iterator
<
T
:
Iterator
<
(
K
,
V
)
>>
(
iter
:
&
mut
T
)
->
HashMap
<
K
,
V
,
H
>
{
let
(
lower
,
_
)
=
iter
.size_hint
();
let
mut
map
=
HashMap
::
with_capacity_and_hasher
(
Default
::
default
(),
lower
);
let
mut
map
=
HashMap
::
with_capacity_and_hasher
(
lower
,
Default
::
default
()
);
map
.extend
(
iter
);
map
}
...
...
@@ -730,7 +731,7 @@ fn extend<T: Iterator<(K, V)>>(&mut self, iter: &mut T) {
impl
<
K
:
Hash
<
S
>
+
Eq
,
V
,
S
,
H
:
Hasher
<
S
>
+
Default
>
Default
for
HashMap
<
K
,
V
,
H
>
{
fn
default
()
->
HashMap
<
K
,
V
,
H
>
{
HashMap
::
with_capacity_and_hasher
(
Default
::
default
(),
INITIAL_CAPACITY
)
HashMap
::
with_capacity_and_hasher
(
INITIAL_CAPACITY
,
Default
::
default
()
)
}
}
...
...
@@ -802,7 +803,7 @@ pub fn with_capacity(capacity: uint) -> HashSet<T, SipHasher> {
impl
<
T
:
Hash
<
S
>
+
Eq
,
S
,
H
:
Hasher
<
S
>>
HashSet
<
T
,
H
>
{
pub
fn
with_hasher
(
hasher
:
H
)
->
HashSet
<
T
,
H
>
{
HashSet
::
with_capacity_and_hasher
(
hasher
,
INITIAL_CAPACITY
)
HashSet
::
with_capacity_and_hasher
(
INITIAL_CAPACITY
,
hasher
)
}
/// Create an empty HashSet with space for at least `capacity`
...
...
@@ -812,9 +813,9 @@ pub fn with_hasher(hasher: H) -> HashSet<T, H> {
/// are designed to allow HashSets to be resistant to attacks that
/// cause many collisions and very poor performance. Setting them
/// manually using this function can expose a DoS attack vector.
pub
fn
with_capacity_and_hasher
(
hasher
:
H
,
capacity
:
uint
)
->
HashSet
<
T
,
H
>
{
pub
fn
with_capacity_and_hasher
(
capacity
:
uint
,
hasher
:
H
)
->
HashSet
<
T
,
H
>
{
HashSet
{
map
:
HashMap
::
with_capacity_and_hasher
(
hasher
,
capacity
)
map
:
HashMap
::
with_capacity_and_hasher
(
capacity
,
hasher
)
}
}
...
...
@@ -902,7 +903,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl
<
T
:
Hash
<
S
>
+
Eq
,
S
,
H
:
Hasher
<
S
>
+
Default
>
FromIterator
<
T
>
for
HashSet
<
T
,
H
>
{
fn
from_iterator
<
Iter
:
Iterator
<
T
>>
(
iter
:
&
mut
Iter
)
->
HashSet
<
T
,
H
>
{
let
(
lower
,
_
)
=
iter
.size_hint
();
let
mut
set
=
HashSet
::
with_capacity_and_hasher
(
Default
::
default
(),
lower
);
let
mut
set
=
HashSet
::
with_capacity_and_hasher
(
lower
,
Default
::
default
()
);
set
.extend
(
iter
);
set
}
...
...
src/libserialize/collection_impls.rs
浏览文件 @
42389b70
...
...
@@ -192,7 +192,7 @@ impl<
fn
decode
(
d
:
&
mut
D
)
->
HashMap
<
K
,
V
,
H
>
{
d
.read_map
(|
d
,
len
|
{
let
hasher
=
Default
::
default
();
let
mut
map
=
HashMap
::
with_capacity_and_hasher
(
hasher
,
len
);
let
mut
map
=
HashMap
::
with_capacity_and_hasher
(
len
,
hasher
);
for
i
in
range
(
0u
,
len
)
{
let
key
=
d
.read_map_elt_key
(
i
,
|
d
|
Decodable
::
decode
(
d
));
let
val
=
d
.read_map_elt_val
(
i
,
|
d
|
Decodable
::
decode
(
d
));
...
...
@@ -228,7 +228,7 @@ impl<
>
Decodable
<
D
>
for
HashSet
<
T
,
H
>
{
fn
decode
(
d
:
&
mut
D
)
->
HashSet
<
T
,
H
>
{
d
.read_seq
(|
d
,
len
|
{
let
mut
set
=
HashSet
::
with_capacity_and_hasher
(
Default
::
default
(),
len
);
let
mut
set
=
HashSet
::
with_capacity_and_hasher
(
len
,
Default
::
default
()
);
for
i
in
range
(
0u
,
len
)
{
set
.insert
(
d
.read_seq_elt
(
i
,
|
d
|
Decodable
::
decode
(
d
)));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录