diff --git a/TinySTL/Detail/Graph.impl.h b/TinySTL/Detail/Graph.impl.h index db65679..5b674cb 100644 --- a/TinySTL/Detail/Graph.impl.h +++ b/TinySTL/Detail/Graph.impl.h @@ -3,16 +3,9 @@ namespace TinySTL{ namespace Detail{ template - typename graph::node_type& - graph::new_node(const Index& index, const Value& val){ - auto ptr = nodeAllocator::allocate(); - nodeAllocator::construct(ptr, node_type(index, val)); - return *ptr; - } - template - void graph::del_node(node_type *p){ - nodeAllocator::destroy(p); - nodeAllocator::deallocate(p); + typename graph::node_type + graph::make_node(const Index& index, const Value& val){ + return node_type(index, val); } template typename graph::node_type& @@ -24,14 +17,6 @@ namespace TinySTL{ return node_type(); } template - void graph::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 bool graph::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 @@ -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; } diff --git a/TinySTL/Graph.h b/TinySTL/Graph.h index 76cb798..fafdadb 100644 --- a/TinySTL/Graph.h +++ b/TinySTL/Graph.h @@ -1,7 +1,6 @@ #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 node_type; typedef vector nodes_set_type; - typedef allocator nodeAllocator; typedef std::function visiter_func_type; typedef outter_iterator iterator; typedef inner_iterator 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>> nodes_; equal_func_type equal_func; size_t size_; - protected: - void cleanup(); }; template>