Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
440ba0c8
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,发现更多精彩内容 >>
提交
440ba0c8
编写于
2月 09, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成iterator
上级
e8ecf9df
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
87 addition
and
27 deletion
+87
-27
TinySTL/Detail/Graph.impl.h
TinySTL/Detail/Graph.impl.h
+43
-14
TinySTL/Graph.h
TinySTL/Graph.h
+44
-13
未找到文件。
TinySTL/Detail/Graph.impl.h
浏览文件 @
440ba0c8
...
...
@@ -21,6 +21,7 @@ namespace TinySTL{
if
(
equal_func
(
pair
.
first
.
first
,
index
))
return
pair
.
first
;
}
return
node
();
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
void
graph
<
Index
,
Value
,
EqualFunc
>::
cleanup
(){
...
...
@@ -48,23 +49,31 @@ namespace TinySTL{
return
nodes_
.
empty
();
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
bucket
_iterator
typename
graph
<
Index
,
Value
,
EqualFunc
>::
inner
_iterator
graph
<
Index
,
Value
,
EqualFunc
>::
begin
(
const
Index
&
index
){
for
(
auto
&
pair
:
nodes_
){
if
(
equal_func
(
pair
.
first
.
first
,
index
))
return
bucket
_iterator
(
this
,
(
pair
.
second
).
begin
());
return
inner
_iterator
(
this
,
(
pair
.
second
).
begin
());
}
return
end
(
index
);
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
bucket
_iterator
typename
graph
<
Index
,
Value
,
EqualFunc
>::
inner
_iterator
graph
<
Index
,
Value
,
EqualFunc
>::
end
(
const
Index
&
index
){
for
(
auto
&
pair
:
nodes_
){
if
(
equal_func
(
pair
.
first
.
first
,
index
))
return
bucket
_iterator
(
this
,
(
pair
.
second
).
end
());
return
inner
_iterator
(
this
,
(
pair
.
second
).
end
());
}
//throw std::exception("return end error");
return
bucket_iterator
();
return
inner_iterator
();
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
iterator
graph
<
Index
,
Value
,
EqualFunc
>::
begin
(){
return
iterator
(
this
,
nodes_
.
begin
());
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
iterator
graph
<
Index
,
Value
,
EqualFunc
>::
end
(){
return
iterator
(
this
,
nodes_
.
end
());
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
size_t
graph
<
Index
,
Value
,
EqualFunc
>::
size
()
const
{
...
...
@@ -99,26 +108,46 @@ namespace TinySTL{
}
//********************************************************************************
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
graph_iterator
<
Index
,
Value
,
EqualFunc
>&
graph
_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(){
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
inner
_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(){
++
inner_it_
;
return
*
this
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
const
graph_iterator
<
Index
,
Value
,
EqualFunc
>
graph_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(
int
){
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>
inner_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(
int
){
auto
temp
=
*
this
;
++*
this
;
return
temp
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
bool
operator
==
(
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
return
lhs
.
container_
==
rhs
.
container_
&&
lhs
.
inner_it_
==
rhs
.
inner_it_
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
bool
operator
!=
(
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
return
!
(
lhs
==
rhs
);
}
//*********************************************************************************
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
outter_iterator
<
Index
,
Value
,
EqualFunc
>&
outter_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(){
++
outter_it_
;
return
*
this
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
const
outter_iterator
<
Index
,
Value
,
EqualFunc
>
outter_iterator
<
Index
,
Value
,
EqualFunc
>::
operator
++
(
int
){
auto
temp
=
*
this
;
++*
this
;
return
temp
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
bool
operator
==
(
const
graph_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
graph_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
return
lhs
.
container_
==
rhs
.
container_
&&
//lhs.outter_it_ == rhs.outter_it_ &&
lhs
.
inner_it_
==
rhs
.
inner_it_
;
bool
operator
==
(
const
outter_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
outter_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
return
lhs
.
container_
==
rhs
.
container_
&&
lhs
.
outter_it_
==
rhs
.
outter_it_
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
bool
operator
!=
(
const
graph
_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
graph
_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
bool
operator
!=
(
const
outter
_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
outter
_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
){
return
!
(
lhs
==
rhs
);
}
}
//end of Detail
...
...
TinySTL/Graph.h
浏览文件 @
440ba0c8
...
...
@@ -12,19 +12,23 @@
namespace
TinySTL
{
namespace
Detail
{
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
class
graph_iterator
;
class
inner_iterator
;
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
class
outter_iterator
;
template
<
class
Index
,
class
Value
,
class
EqualFunc
=
equal_to
<
Index
>
>
class
graph
{
public:
friend
class
graph_iterator
<
Index
,
Value
,
EqualFunc
>
;
friend
class
inner_iterator
<
Index
,
Value
,
EqualFunc
>
;
friend
class
outter_iterator
<
Index
,
Value
,
EqualFunc
>
;
public:
typedef
Index
index_type
;
typedef
Value
value_type
;
typedef
EqualFunc
equal_func_type
;
typedef
pair
<
Index
,
Value
>
node
;
typedef
vector
<
node
>
node_sets
;
typedef
graph_iterator
<
Index
,
Value
,
EqualFunc
>
bucket_iterator
;
typedef
inner_iterator
<
Index
,
Value
,
EqualFunc
>
inner_iterator
;
typedef
outter_iterator
<
Index
,
Value
,
EqualFunc
>
iterator
;
typedef
allocator
<
node
>
nodeAllocator
;
typedef
std
::
function
<
void
(
node
&
)
>
visiter_func_type
;
public:
...
...
@@ -48,8 +52,10 @@ namespace TinySTL{
inline
bool
empty
()
const
;
inline
size_t
size
()
const
;
inline
bucket_iterator
begin
(
const
Index
&
index
);
inline
bucket_iterator
end
(
const
Index
&
index
);
inline
inner_iterator
begin
(
const
Index
&
index
);
inline
inner_iterator
end
(
const
Index
&
index
);
inline
iterator
begin
();
inline
iterator
end
();
protected:
list
<
pair
<
node
,
list
<
node
>>>
nodes_
;
equal_func_type
equal_func
;
...
...
@@ -59,17 +65,17 @@ namespace TinySTL{
};
template
<
class
Index
,
class
Value
,
class
EqualFunc
=
equal_to
<
Index
>
>
class
graph
_iterator
{
class
inner
_iterator
{
public:
friend
class
graph
<
Index
,
Value
,
EqualFunc
>
;
typedef
graph
<
Index
,
Value
,
EqualFunc
>*
cntrPtr
;
typedef
graph
<
Index
,
Value
,
EqualFunc
>
graph_type
;
typedef
typename
list
<
typename
graph_type
::
node
>::
iterator
inner_it_type
;
public:
explicit
graph
_iterator
(
cntrPtr
c
=
nullptr
,
inner_it_type
iit
=
inner_it_type
())
explicit
inner
_iterator
(
cntrPtr
c
=
nullptr
,
inner_it_type
iit
=
inner_it_type
())
:
container_
(
c
),
inner_it_
(
iit
){}
graph
_iterator
&
operator
++
();
const
graph
_iterator
operator
++
(
int
);
inner
_iterator
&
operator
++
();
const
inner
_iterator
operator
++
(
int
);
typename
graph_type
::
node
&
operator
*
(){
return
*
inner_it_
;
}
typename
graph_type
::
node
*
operator
->
(){
return
&
(
operator
*
());
}
private:
...
...
@@ -77,11 +83,36 @@ namespace TinySTL{
inner_it_type
inner_it_
;
public:
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
friend
bool
operator
==
(
const
graph_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
graph_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
friend
bool
operator
==
(
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
friend
bool
operator
!=
(
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
inner_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
};
template
<
class
Index
,
class
Value
,
class
EqualFunc
=
equal_to
<
Index
>
>
class
outter_iterator
{
public:
friend
class
graph
<
Index
,
Value
,
EqualFunc
>
;
typedef
graph
<
Index
,
Value
,
EqualFunc
>*
cntrPtr
;
typedef
graph
<
Index
,
Value
,
EqualFunc
>
graph_type
;
typedef
typename
list
<
pair
<
typename
graph_type
::
node
,
list
<
typename
graph_type
::
node
>>>::
iterator
outter_it_type
;
private:
cntrPtr
container_
;
outter_it_type
outter_it_
;
public:
explicit
outter_iterator
(
cntrPtr
c
=
nullptr
,
outter_it_type
oit
=
outter_it_type
())
:
container_
(
c
),
outter_it_
(
oit
){}
outter_iterator
&
operator
++
();
const
outter_iterator
operator
++
(
int
);
typename
graph_type
::
node
&
operator
*
(){
return
outter_it_
->
first
;
}
typename
graph_type
::
node
*
operator
->
(){
return
&
(
operator
*
());
}
public:
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
friend
bool
operator
==
(
const
outter_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
outter_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
friend
bool
operator
!=
(
const
graph
_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
graph
_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
friend
bool
operator
!=
(
const
outter
_iterator
<
Index
,
Value
,
EqualFunc
>&
lhs
,
const
outter
_iterator
<
Index
,
Value
,
EqualFunc
>&
rhs
);
};
}
//end of namespace Detail
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录