tree_policy.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License
00017 // along with this library; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00019 // MA 02111-1307, USA.
00020 
00021 // As a special exception, you may use this file as part of a free
00022 // software library without restriction.  Specifically, if other files
00023 // instantiate templates or use macros or inline functions from this
00024 // file, or you compile this file and link it with other files to
00025 // produce an executable, this file does not by itself cause the
00026 // resulting executable to be covered by the GNU General Public
00027 // License.  This exception does not however invalidate any other
00028 // reasons why the executable file might be covered by the GNU General
00029 // Public License.
00030 
00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00032 
00033 // Permission to use, copy, modify, sell, and distribute this software
00034 // is hereby granted without fee, provided that the above copyright
00035 // notice appears in all copies, and that both that copyright notice
00036 // and this permission notice appear in supporting documentation. None
00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
00038 // representation about the suitability of this software for any
00039 // purpose. It is provided "as is" without express or implied
00040 // warranty.
00041 
00042 /**
00043  * @file tree_policy.hpp
00044  * Contains tree-related policies.
00045  */
00046 
00047 #ifndef PB_DS_TREE_POLICY_HPP
00048 #define PB_DS_TREE_POLICY_HPP
00049 
00050 #include <iterator>
00051 #include <ext/pb_ds/detail/type_utils.hpp>
00052 #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
00053 
00054 namespace pb_ds
00055 {
00056   // A null node updator, indicating that no node updates are required.
00057   template<typename Const_Node_Iterator,
00058        typename Node_Iterator,
00059        typename Cmp_Fn,
00060        typename Allocator>
00061   struct null_tree_node_update
00062   { };
00063 
00064 #define PB_DS_CLASS_T_DEC \
00065   template<typename Const_Node_Iterator, class Node_Iterator, class Cmp_Fn, class Allocator>
00066 
00067 #define PB_DS_CLASS_C_DEC \
00068   tree_order_statistics_node_update<Const_Node_Iterator, Node_Iterator, Cmp_Fn, Allocator>
00069 
00070 #define PB_DS_BASE_C_DEC                        \
00071   detail::basic_tree_policy_base<Const_Node_Iterator, Node_Iterator, Allocator>
00072 
00073   // Functor updating ranks of entrees.
00074   template<typename Const_Node_Iterator, typename Node_Iterator, 
00075        typename Cmp_Fn, typename Allocator>
00076   class tree_order_statistics_node_update : private PB_DS_BASE_C_DEC
00077   {
00078   private:
00079     typedef PB_DS_BASE_C_DEC base_type;
00080 
00081   public:
00082     typedef Cmp_Fn cmp_fn;
00083     typedef Allocator allocator;
00084     typedef typename allocator::size_type size_type;
00085     typedef typename base_type::key_type key_type;
00086     typedef typename base_type::const_key_reference const_key_reference;
00087 
00088     typedef size_type metadata_type;
00089     typedef Const_Node_Iterator const_node_iterator;
00090     typedef Node_Iterator node_iterator;
00091     typedef typename const_node_iterator::value_type const_iterator;
00092     typedef typename node_iterator::value_type iterator;
00093 
00094     // Finds an entry by __order. Returns a const_iterator to the
00095     // entry with the __order order, or a const_iterator to the
00096     // container object's end if order is at least the size of the
00097     // container object.
00098     inline const_iterator
00099     find_by_order(size_type order) const;
00100 
00101     // Finds an entry by __order. Returns an iterator to the entry
00102     // with the __order order, or an iterator to the container
00103     // object's end if order is at least the size of the container
00104     // object.
00105     inline iterator
00106     find_by_order(size_type order);
00107 
00108     // Returns the order of a key within a sequence. For exapmle, if
00109     // r_key is the smallest key, this method will return 0; if r_key
00110     // is a key between the smallest and next key, this method will
00111     // return 1; if r_key is a key larger than the largest key, this
00112     // method will return the size of r_c.
00113     inline size_type
00114     order_of_key(const_key_reference r_key) const;
00115 
00116   private:
00117     // Const reference to the container's value-type.
00118     typedef typename base_type::const_reference const_reference;
00119 
00120     // Const pointer to the container's value-type.
00121     typedef typename base_type::const_pointer const_pointer;
00122 
00123     typedef typename allocator::template rebind<metadata_type>::other metadata_rebind;
00124     // Const metadata reference.
00125     typedef typename metadata_rebind::const_reference const_metadata_reference;
00126 
00127     // Metadata reference.
00128     typedef typename metadata_rebind::reference metadata_reference;
00129 
00130     // Returns the const_node_iterator associated with the tree's root node.
00131     virtual const_node_iterator
00132     node_begin() const = 0;
00133 
00134     // Returns the node_iterator associated with the tree's root node.
00135     virtual node_iterator
00136     node_begin() = 0;
00137 
00138     // Returns the const_node_iterator associated with a just-after leaf node.
00139     virtual const_node_iterator
00140     node_end() const = 0;
00141 
00142     // Returns the node_iterator associated with a just-after leaf node.
00143     virtual node_iterator
00144     node_end() = 0;
00145 
00146     // Access to the cmp_fn object.
00147     virtual cmp_fn& 
00148     get_cmp_fn() = 0;
00149 
00150   protected:
00151     // Updates the rank of a node through a node_iterator node_it;
00152     // end_nd_it is the end node iterator.
00153     inline void
00154     operator()(node_iterator node_it, const_node_iterator end_nd_it) const;
00155 
00156     virtual
00157     ~tree_order_statistics_node_update();
00158   };
00159 
00160 #include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp>
00161 
00162 #undef PB_DS_CLASS_T_DEC
00163 #undef PB_DS_CLASS_C_DEC
00164 #undef PB_DS_BASE_C_DEC
00165 
00166 } // namespace pb_ds
00167 
00168 #endif 

Generated on Thu Nov 1 13:12:46 2007 for libstdc++ by  doxygen 1.5.1