xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/ext/pb_ds/tree_policy.hpp (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the terms
7*404b540aSrobert // of the GNU General Public License as published by the Free Software
8*404b540aSrobert // Foundation; either version 2, or (at your option) any later
9*404b540aSrobert // version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful, but
12*404b540aSrobert // WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*404b540aSrobert // General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License
17*404b540aSrobert // along with this library; see the file COPYING.  If not, write to
18*404b540aSrobert // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19*404b540aSrobert // MA 02111-1307, USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free
22*404b540aSrobert // software library without restriction.  Specifically, if other files
23*404b540aSrobert // instantiate templates or use macros or inline functions from this
24*404b540aSrobert // file, or you compile this file and link it with other files to
25*404b540aSrobert // produce an executable, this file does not by itself cause the
26*404b540aSrobert // resulting executable to be covered by the GNU General Public
27*404b540aSrobert // License.  This exception does not however invalidate any other
28*404b540aSrobert // reasons why the executable file might be covered by the GNU General
29*404b540aSrobert // Public License.
30*404b540aSrobert 
31*404b540aSrobert // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32*404b540aSrobert 
33*404b540aSrobert // Permission to use, copy, modify, sell, and distribute this software
34*404b540aSrobert // is hereby granted without fee, provided that the above copyright
35*404b540aSrobert // notice appears in all copies, and that both that copyright notice
36*404b540aSrobert // and this permission notice appear in supporting documentation. None
37*404b540aSrobert // of the above authors, nor IBM Haifa Research Laboratories, make any
38*404b540aSrobert // representation about the suitability of this software for any
39*404b540aSrobert // purpose. It is provided "as is" without express or implied
40*404b540aSrobert // warranty.
41*404b540aSrobert 
42*404b540aSrobert /**
43*404b540aSrobert  * @file tree_policy.hpp
44*404b540aSrobert  * Contains tree-related policies.
45*404b540aSrobert  */
46*404b540aSrobert 
47*404b540aSrobert #ifndef PB_DS_TREE_POLICY_HPP
48*404b540aSrobert #define PB_DS_TREE_POLICY_HPP
49*404b540aSrobert 
50*404b540aSrobert #include <iterator>
51*404b540aSrobert #include <ext/pb_ds/detail/type_utils.hpp>
52*404b540aSrobert #include <ext/pb_ds/detail/basic_tree_policy/basic_tree_policy_base.hpp>
53*404b540aSrobert 
54*404b540aSrobert namespace pb_ds
55*404b540aSrobert {
56*404b540aSrobert   // A null node updator, indicating that no node updates are required.
57*404b540aSrobert   template<typename Const_Node_Iterator,
58*404b540aSrobert 	   typename Node_Iterator,
59*404b540aSrobert 	   typename Cmp_Fn,
60*404b540aSrobert 	   typename Allocator>
61*404b540aSrobert   struct null_tree_node_update
62*404b540aSrobert   { };
63*404b540aSrobert 
64*404b540aSrobert #define PB_DS_CLASS_T_DEC \
65*404b540aSrobert   template<typename Const_Node_Iterator, class Node_Iterator, class Cmp_Fn, class Allocator>
66*404b540aSrobert 
67*404b540aSrobert #define PB_DS_CLASS_C_DEC \
68*404b540aSrobert   tree_order_statistics_node_update<Const_Node_Iterator, Node_Iterator, Cmp_Fn, Allocator>
69*404b540aSrobert 
70*404b540aSrobert #define PB_DS_BASE_C_DEC						\
71*404b540aSrobert   detail::basic_tree_policy_base<Const_Node_Iterator, Node_Iterator, Allocator>
72*404b540aSrobert 
73*404b540aSrobert   // Functor updating ranks of entrees.
74*404b540aSrobert   template<typename Const_Node_Iterator, typename Node_Iterator,
75*404b540aSrobert 	   typename Cmp_Fn, typename Allocator>
76*404b540aSrobert   class tree_order_statistics_node_update : private PB_DS_BASE_C_DEC
77*404b540aSrobert   {
78*404b540aSrobert   private:
79*404b540aSrobert     typedef PB_DS_BASE_C_DEC base_type;
80*404b540aSrobert 
81*404b540aSrobert   public:
82*404b540aSrobert     typedef Cmp_Fn cmp_fn;
83*404b540aSrobert     typedef Allocator allocator;
84*404b540aSrobert     typedef typename allocator::size_type size_type;
85*404b540aSrobert     typedef typename base_type::key_type key_type;
86*404b540aSrobert     typedef typename base_type::const_key_reference const_key_reference;
87*404b540aSrobert 
88*404b540aSrobert     typedef size_type metadata_type;
89*404b540aSrobert     typedef Const_Node_Iterator const_node_iterator;
90*404b540aSrobert     typedef Node_Iterator node_iterator;
91*404b540aSrobert     typedef typename const_node_iterator::value_type const_iterator;
92*404b540aSrobert     typedef typename node_iterator::value_type iterator;
93*404b540aSrobert 
94*404b540aSrobert     // Finds an entry by __order. Returns a const_iterator to the
95*404b540aSrobert     // entry with the __order order, or a const_iterator to the
96*404b540aSrobert     // container object's end if order is at least the size of the
97*404b540aSrobert     // container object.
98*404b540aSrobert     inline const_iterator
99*404b540aSrobert     find_by_order(size_type order) const;
100*404b540aSrobert 
101*404b540aSrobert     // Finds an entry by __order. Returns an iterator to the entry
102*404b540aSrobert     // with the __order order, or an iterator to the container
103*404b540aSrobert     // object's end if order is at least the size of the container
104*404b540aSrobert     // object.
105*404b540aSrobert     inline iterator
106*404b540aSrobert     find_by_order(size_type order);
107*404b540aSrobert 
108*404b540aSrobert     // Returns the order of a key within a sequence. For exapmle, if
109*404b540aSrobert     // r_key is the smallest key, this method will return 0; if r_key
110*404b540aSrobert     // is a key between the smallest and next key, this method will
111*404b540aSrobert     // return 1; if r_key is a key larger than the largest key, this
112*404b540aSrobert     // method will return the size of r_c.
113*404b540aSrobert     inline size_type
114*404b540aSrobert     order_of_key(const_key_reference r_key) const;
115*404b540aSrobert 
116*404b540aSrobert   private:
117*404b540aSrobert     // Const reference to the container's value-type.
118*404b540aSrobert     typedef typename base_type::const_reference const_reference;
119*404b540aSrobert 
120*404b540aSrobert     // Const pointer to the container's value-type.
121*404b540aSrobert     typedef typename base_type::const_pointer const_pointer;
122*404b540aSrobert 
123*404b540aSrobert     typedef typename allocator::template rebind<metadata_type>::other metadata_rebind;
124*404b540aSrobert     // Const metadata reference.
125*404b540aSrobert     typedef typename metadata_rebind::const_reference const_metadata_reference;
126*404b540aSrobert 
127*404b540aSrobert     // Metadata reference.
128*404b540aSrobert     typedef typename metadata_rebind::reference metadata_reference;
129*404b540aSrobert 
130*404b540aSrobert     // Returns the const_node_iterator associated with the tree's root node.
131*404b540aSrobert     virtual const_node_iterator
132*404b540aSrobert     node_begin() const = 0;
133*404b540aSrobert 
134*404b540aSrobert     // Returns the node_iterator associated with the tree's root node.
135*404b540aSrobert     virtual node_iterator
136*404b540aSrobert     node_begin() = 0;
137*404b540aSrobert 
138*404b540aSrobert     // Returns the const_node_iterator associated with a just-after leaf node.
139*404b540aSrobert     virtual const_node_iterator
140*404b540aSrobert     node_end() const = 0;
141*404b540aSrobert 
142*404b540aSrobert     // Returns the node_iterator associated with a just-after leaf node.
143*404b540aSrobert     virtual node_iterator
144*404b540aSrobert     node_end() = 0;
145*404b540aSrobert 
146*404b540aSrobert     // Access to the cmp_fn object.
147*404b540aSrobert     virtual cmp_fn&
148*404b540aSrobert     get_cmp_fn() = 0;
149*404b540aSrobert 
150*404b540aSrobert   protected:
151*404b540aSrobert     // Updates the rank of a node through a node_iterator node_it;
152*404b540aSrobert     // end_nd_it is the end node iterator.
153*404b540aSrobert     inline void
154*404b540aSrobert     operator()(node_iterator node_it, const_node_iterator end_nd_it) const;
155*404b540aSrobert 
156*404b540aSrobert     virtual
157*404b540aSrobert     ~tree_order_statistics_node_update();
158*404b540aSrobert   };
159*404b540aSrobert 
160*404b540aSrobert #include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp>
161*404b540aSrobert 
162*404b540aSrobert #undef PB_DS_CLASS_T_DEC
163*404b540aSrobert #undef PB_DS_CLASS_C_DEC
164*404b540aSrobert #undef PB_DS_BASE_C_DEC
165*404b540aSrobert 
166*404b540aSrobert } // namespace pb_ds
167*404b540aSrobert 
168*404b540aSrobert #endif
169