Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
c6250451
T
TinySTL
项目概览
OpenDocCN
/
TinySTL
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TinySTL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c6250451
编写于
1月 19, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成相关函数
上级
0873b826
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
2 deletion
+60
-2
TinySTL/Detail/Unordered_set.impl.h
TinySTL/Detail/Unordered_set.impl.h
+48
-2
TinySTL/Unordered_set.h
TinySTL/Unordered_set.h
+12
-0
未找到文件。
TinySTL/Detail/Unordered_set.impl.h
浏览文件 @
c6250451
#ifndef _UNORDERED_SET_IMPL_H_
#define _UNORDERED_SET_IMPL_H_
#include <functional>
namespace
TinySTL
{
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size_type
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size
()
const
{
return
size_
;
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
bool
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
empty
()
const
{
return
size
()
==
0
;
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size_type
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
bucket_count
()
const
{
return
buckets_
.
size
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size_type
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
bucket_size
(
size_type
i
)
const
{
return
buckets_
[
i
].
size
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size_type
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
bucket
(
const
key_type
&
key
)
const
{
return
bucket_index
(
key
);
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
float
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
load_factor
()
const
{
return
(
float
)
size
()
/
(
float
)
bucket_count
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
haser
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
hash_function
()
const
{
return
haser
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
key_equal
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
key_eq
()
const
{
return
key_equal
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
allocator_type
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
get_allocator
()
const
{
return
allocator_type
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
size_t
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
prime_list_
[
PRIME_LIST_SIZE
]
=
{
53
,
97
,
193
,
389
,
769
,
1543
,
3079
,
6151
,
12289
,
24593
,
49157
,
98317
,
196613
,
393241
,
...
...
@@ -11,7 +56,8 @@ namespace TinySTL{
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
bool
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
has_key
(
const
key_type
&
key
){
auto
&
list
=
buckets_
[
bucket_index
(
key
)];
return
TinySTL
::
find
(
list
.
begin
(),
list
.
end
(),
key
)
!=
list
.
end
();
auto
pred
=
std
::
bind
(
KeyEqual
(),
key
,
std
::
placeholders
::
_1
);
return
TinySTL
::
find_if
(
list
.
begin
(),
list
.
end
(),
pred
)
!=
list
.
end
();
}
template
<
class
Key
,
class
Hash
,
class
KeyEqual
,
class
Allocator
>
typename
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
size_type
...
...
@@ -42,7 +88,7 @@ namespace TinySTL{
Unordered_set
<
Key
,
Hash
,
KeyEqual
,
Allocator
>::
Unordered_set
(
InputIterator
first
,
InputIterator
last
){
size_
=
0
;
auto
len
=
last
-
first
;
buckets_
.
resize
(
len
);
buckets_
.
resize
(
next_prime
(
len
)
);
for
(;
first
!=
last
;
++
first
){
auto
index
=
bucket_index
(
*
first
);
if
(
!
has_key
(
*
first
)){
...
...
TinySTL/Unordered_set.h
浏览文件 @
c6250451
...
...
@@ -18,6 +18,7 @@ namespace TinySTL{
typedef
Key
value_type
;
typedef
size_t
size_type
;
typedef
Hash
haser
;
typedef
KeyEqual
key_equal
;
typedef
Allocator
allocator_type
;
typedef
value_type
&
reference
;
typedef
const
value_type
&
const_reference
;
...
...
@@ -32,6 +33,17 @@ namespace TinySTL{
Unordered_set
(
InputIterator
first
,
InputIterator
last
);
//Unordered_set(const Unordered_set& ust);
//Unordered_set& operator = (const Unordered_set& ust);
size_type
size
()
const
;
bool
empty
()
const
;
size_type
bucket_count
()
const
;
size_type
bucket_size
(
size_type
i
)
const
;
size_type
bucket
(
const
key_type
&
key
)
const
;
float
load_factor
()
const
;
haser
hash_function
()
const
;
key_equal
key_eq
()
const
;
allocator_type
get_allocator
()
const
;
private:
size_type
next_prime
(
size_type
n
)
const
;
size_type
bucket_index
(
const
key_type
&
key
)
const
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录