libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2009 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 tree_policy.hpp 00038 * Contains tree-related policies. 00039 */ 00040 00041 #ifndef PB_DS_TREE_POLICY_HPP 00042 #define PB_DS_TREE_POLICY_HPP 00043 00044 #include <iterator> 00045 #include <ext/pb_ds/detail/type_utils.hpp> 00046 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp> 00047 00048 namespace __gnu_pbds 00049 { 00050 // A null node updator, indicating that no node updates are required. 00051 template<typename Const_Node_Iterator, 00052 typename Node_Iterator, 00053 typename Cmp_Fn, 00054 typename Allocator> 00055 struct null_tree_node_update 00056 { }; 00057 00058 #define PB_DS_CLASS_T_DEC \ 00059 template<typename Const_Node_Iterator, class Node_Iterator, class Cmp_Fn, class Allocator> 00060 00061 #define PB_DS_CLASS_C_DEC \ 00062 tree_order_statistics_node_update<Const_Node_Iterator, Node_Iterator, Cmp_Fn, Allocator> 00063 00064 #define PB_DS_BASE_C_DEC \ 00065 detail::basic_tree_policy_base<Const_Node_Iterator, Node_Iterator, Allocator> 00066 00067 // Functor updating ranks of entrees. 00068 template<typename Const_Node_Iterator, typename Node_Iterator, 00069 typename Cmp_Fn, typename Allocator> 00070 class tree_order_statistics_node_update : private PB_DS_BASE_C_DEC 00071 { 00072 private: 00073 typedef PB_DS_BASE_C_DEC base_type; 00074 00075 public: 00076 typedef Cmp_Fn cmp_fn; 00077 typedef Allocator allocator_type; 00078 typedef typename allocator_type::size_type size_type; 00079 typedef typename base_type::key_type key_type; 00080 typedef typename base_type::const_key_reference const_key_reference; 00081 00082 typedef size_type metadata_type; 00083 typedef Const_Node_Iterator const_node_iterator; 00084 typedef Node_Iterator node_iterator; 00085 typedef typename const_node_iterator::value_type const_iterator; 00086 typedef typename node_iterator::value_type iterator; 00087 00088 // Finds an entry by __order. Returns a const_iterator to the 00089 // entry with the __order order, or a const_iterator to the 00090 // container object's end if order is at least the size of the 00091 // container object. 00092 inline const_iterator 00093 find_by_order(size_type order) const; 00094 00095 // Finds an entry by __order. Returns an iterator to the entry 00096 // with the __order order, or an iterator to the container 00097 // object's end if order is at least the size of the container 00098 // object. 00099 inline iterator 00100 find_by_order(size_type order); 00101 00102 // Returns the order of a key within a sequence. For exapmle, if 00103 // r_key is the smallest key, this method will return 0; if r_key 00104 // is a key between the smallest and next key, this method will 00105 // return 1; if r_key is a key larger than the largest key, this 00106 // method will return the size of r_c. 00107 inline size_type 00108 order_of_key(const_key_reference r_key) const; 00109 00110 private: 00111 // Const reference to the container's value-type. 00112 typedef typename base_type::const_reference const_reference; 00113 00114 // Const pointer to the container's value-type. 00115 typedef typename base_type::const_pointer const_pointer; 00116 00117 typedef typename allocator_type::template rebind<metadata_type>::other metadata_rebind; 00118 // Const metadata reference. 00119 typedef typename metadata_rebind::const_reference const_metadata_reference; 00120 00121 // Metadata reference. 00122 typedef typename metadata_rebind::reference metadata_reference; 00123 00124 // Returns the const_node_iterator associated with the tree's root node. 00125 virtual const_node_iterator 00126 node_begin() const = 0; 00127 00128 // Returns the node_iterator associated with the tree's root node. 00129 virtual node_iterator 00130 node_begin() = 0; 00131 00132 // Returns the const_node_iterator associated with a just-after leaf node. 00133 virtual const_node_iterator 00134 node_end() const = 0; 00135 00136 // Returns the node_iterator associated with a just-after leaf node. 00137 virtual node_iterator 00138 node_end() = 0; 00139 00140 // Access to the cmp_fn object. 00141 virtual cmp_fn& 00142 get_cmp_fn() = 0; 00143 00144 protected: 00145 // Updates the rank of a node through a node_iterator node_it; 00146 // end_nd_it is the end node iterator. 00147 inline void 00148 operator()(node_iterator node_it, const_node_iterator end_nd_it) const; 00149 00150 virtual 00151 ~tree_order_statistics_node_update(); 00152 }; 00153 00154 #include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp> 00155 00156 #undef PB_DS_CLASS_T_DEC 00157 #undef PB_DS_CLASS_C_DEC 00158 #undef PB_DS_BASE_C_DEC 00159 00160 } // namespace __gnu_pbds 00161 00162 #endif