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