Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
2af10635
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 搜索 >>
提交
2af10635
编写于
2月 10, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重构
上级
7072a460
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
34 deletion
+8
-34
TinySTL/Detail/Graph.impl.h
TinySTL/Detail/Graph.impl.h
+5
-27
TinySTL/Graph.h
TinySTL/Graph.h
+3
-7
未找到文件。
TinySTL/Detail/Graph.impl.h
浏览文件 @
2af10635
...
...
@@ -3,16 +3,9 @@
namespace
TinySTL
{
namespace
Detail
{
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
node_type
&
graph
<
Index
,
Value
,
EqualFunc
>::
new_node
(
const
Index
&
index
,
const
Value
&
val
){
auto
ptr
=
nodeAllocator
::
allocate
();
nodeAllocator
::
construct
(
ptr
,
node_type
(
index
,
val
));
return
*
ptr
;
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
void
graph
<
Index
,
Value
,
EqualFunc
>::
del_node
(
node_type
*
p
){
nodeAllocator
::
destroy
(
p
);
nodeAllocator
::
deallocate
(
p
);
typename
graph
<
Index
,
Value
,
EqualFunc
>::
node_type
graph
<
Index
,
Value
,
EqualFunc
>::
make_node
(
const
Index
&
index
,
const
Value
&
val
){
return
node_type
(
index
,
val
);
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
typename
graph
<
Index
,
Value
,
EqualFunc
>::
node_type
&
...
...
@@ -24,14 +17,6 @@ namespace TinySTL{
return
node_type
();
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
void
graph
<
Index
,
Value
,
EqualFunc
>::
cleanup
(){
for
(
auto
out
=
nodes_
.
begin
();
out
!=
nodes_
.
end
();
++
out
){
for
(
auto
in
=
(
out
->
second
).
begin
();
in
!=
(
out
->
second
).
end
();
++
in
){
del_node
(
&
(
*
in
));
}
}
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
bool
graph
<
Index
,
Value
,
EqualFunc
>::
is_contained
(
const
Index
&
index
){
for
(
auto
&
pair
:
nodes_
){
if
(
equal_func
(
pair
.
first
.
first
,
index
))
...
...
@@ -64,7 +49,6 @@ namespace TinySTL{
if
(
equal_func
(
pair
.
first
.
first
,
index
))
return
inner_iterator
(
this
,
(
pair
.
second
).
end
());
}
//throw std::exception("return end error");
return
inner_iterator
();
}
template
<
class
Index
,
class
Value
,
class
EqualFunc
>
...
...
@@ -231,19 +215,13 @@ namespace TinySTL{
for
(
auto
oit
=
nodes_
.
begin
();
oit
!=
nodes_
.
end
();){
auto
&
l
=
oit
->
second
;
if
(
equal_func
((
oit
->
first
).
first
,
index
)){
for
(
auto
iit
=
l
.
begin
();
iit
!=
l
.
end
();
++
iit
){
del_node
(
&
(
*
iit
));
}
del_node
(
&
(
oit
->
first
));
oit
=
nodes_
.
erase
(
oit
);
}
else
{
for
(
auto
iit
=
l
.
begin
();
iit
!=
l
.
end
();){
if
(
equal_func
(
iit
->
first
,
index
)){
del_node
(
&
(
*
iit
));
if
(
equal_func
(
iit
->
first
,
index
))
iit
=
l
.
erase
(
iit
);
}
else
{
else
++
iit
;
}
}
++
oit
;
}
...
...
TinySTL/Graph.h
浏览文件 @
2af10635
#ifndef _GRAPH_H_
#define _GRAPH_H_
#include "Allocator.h"
#include "Iterator.h"
#include "List.h"
#include "String.h"
...
...
@@ -31,13 +30,12 @@ namespace TinySTL{
typedef
EqualFunc
equal_func_type
;
typedef
pair
<
Index
,
Value
>
node_type
;
typedef
vector
<
node_type
>
nodes_set_type
;
typedef
allocator
<
node_type
>
nodeAllocator
;
typedef
std
::
function
<
void
(
node_type
&
)
>
visiter_func_type
;
typedef
outter_iterator
<
Index
,
Value
,
EqualFunc
>
iterator
;
typedef
inner_iterator
<
Index
,
Value
,
EqualFunc
>
inner_iterator
;
public:
graph
()
:
size_
(
0
){};
virtual
~
graph
(){
cleanup
();
};
virtual
~
graph
(){};
//node can be not in the graph
virtual
void
add_node
(
const
node_type
&
item
,
const
nodes_set_type
&
nodes
)
=
0
;
...
...
@@ -50,8 +48,8 @@ namespace TinySTL{
void
DFS
(
const
Index
&
index
,
visiter_func_type
func
);
void
BFS
(
const
Index
&
index
,
visiter_func_type
func
);
node_type
&
new_node
(
const
Index
&
index
,
const
Value
&
val
);
void
del_node
(
node_type
*
p
);
//
node_type& new_node(const Index& index, const Value& val);
node_type
make_node
(
const
Index
&
index
,
const
Value
&
val
);
node_type
&
get_node
(
const
Index
&
index
);
bool
is_contained
(
const
Index
&
index
);
...
...
@@ -72,8 +70,6 @@ namespace TinySTL{
list
<
pair
<
node_type
,
list
<
node_type
>>>
nodes_
;
equal_func_type
equal_func
;
size_t
size_
;
protected:
void
cleanup
();
};
template
<
class
Index
,
class
Value
,
class
EqualFunc
=
equal_to
<
Index
>
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录