libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file rb_tree_map_/node.hpp 00038 * Contains an implementation for rb_tree_. 00039 */ 00040 00041 #ifndef PB_DS_RB_TREE_NODE_HPP 00042 #define PB_DS_RB_TREE_NODE_HPP 00043 00044 #include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> 00045 00046 namespace __gnu_pbds 00047 { 00048 namespace detail 00049 { 00050 /// Node for Red-Black trees. 00051 template<typename Value_Type, class Metadata, typename _Alloc> 00052 struct rb_tree_node_ 00053 { 00054 public: 00055 typedef Value_Type value_type; 00056 typedef Metadata metadata_type; 00057 00058 typedef 00059 typename _Alloc::template rebind< 00060 rb_tree_node_< 00061 Value_Type, 00062 Metadata, 00063 _Alloc> >::other::pointer 00064 node_pointer; 00065 00066 typedef 00067 typename _Alloc::template rebind< 00068 metadata_type>::other::reference 00069 metadata_reference; 00070 00071 typedef 00072 typename _Alloc::template rebind< 00073 metadata_type>::other::const_reference 00074 metadata_const_reference; 00075 00076 bool 00077 special() const 00078 { return m_red; } 00079 00080 metadata_const_reference 00081 get_metadata() const 00082 { return m_metadata; } 00083 00084 metadata_reference 00085 get_metadata() 00086 { return m_metadata; } 00087 00088 #ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ 00089 void 00090 trace() const 00091 { 00092 std::cout << PB_DS_V2F(m_value) <<(m_red? " <r> " : " <b> ") 00093 << "(" << m_metadata << ")"; 00094 } 00095 #endif 00096 00097 node_pointer m_p_left; 00098 node_pointer m_p_right; 00099 node_pointer m_p_parent; 00100 value_type m_value; 00101 bool m_red; 00102 metadata_type m_metadata; 00103 }; 00104 00105 template<typename Value_Type, typename _Alloc> 00106 struct rb_tree_node_<Value_Type, null_type, _Alloc> 00107 { 00108 public: 00109 typedef Value_Type value_type; 00110 typedef null_type metadata_type; 00111 00112 typedef 00113 typename _Alloc::template rebind< 00114 rb_tree_node_< 00115 Value_Type, 00116 null_type, 00117 _Alloc> >::other::pointer 00118 node_pointer; 00119 00120 bool 00121 special() const 00122 { return m_red; } 00123 00124 #ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ 00125 void 00126 trace() const 00127 { std::cout << PB_DS_V2F(m_value) <<(m_red? " <r> " : " <b> "); } 00128 #endif 00129 00130 node_pointer m_p_left; 00131 node_pointer m_p_right; 00132 node_pointer m_p_parent; 00133 value_type m_value; 00134 bool m_red; 00135 }; 00136 } // namespace detail 00137 } // namespace __gnu_pbds 00138 00139 #endif