3 // Copyright (C) 2005-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file tree_policy.hpp
38 * Contains tree-related policies.
41 #ifndef PB_DS_TREE_POLICY_HPP
42 #define PB_DS_TREE_POLICY_HPP
44 #include <bits/c++config.h>
46 #include <ext/pb_ds/detail/type_utils.hpp>
47 #include <ext/pb_ds/detail/branch_policy/branch_policy.hpp>
51 #define PB_DS_CLASS_T_DEC \
52 template<typename Node_CItr, typename Node_Itr, typename Cmp_Fn, \
55 #define PB_DS_CLASS_C_DEC \
56 tree_order_statistics_node_update<Node_CItr, Node_Itr, Cmp_Fn, _Alloc>
58 #define PB_DS_BRANCH_POLICY_BASE \
59 detail::branch_policy<Node_CItr, Node_Itr, _Alloc>
61 /// Functor updating ranks of entrees.
62 template<typename Node_CItr
, typename Node_Itr
,
63 typename Cmp_Fn
, typename _Alloc
>
64 class tree_order_statistics_node_update
: private PB_DS_BRANCH_POLICY_BASE
67 typedef PB_DS_BRANCH_POLICY_BASE base_type
;
70 typedef Cmp_Fn cmp_fn
;
71 typedef _Alloc allocator_type
;
72 typedef typename
allocator_type::size_type size_type
;
73 typedef typename
base_type::key_type key_type
;
74 typedef typename
base_type::key_const_reference key_const_reference
;
76 typedef size_type metadata_type
;
77 typedef Node_CItr node_const_iterator
;
78 typedef Node_Itr node_iterator
;
79 typedef typename
node_const_iterator::value_type const_iterator
;
80 typedef typename
node_iterator::value_type iterator
;
82 /// Finds an entry by __order. Returns a const_iterator to the
83 /// entry with the __order order, or a const_iterator to the
84 /// container object's end if order is at least the size of the
87 find_by_order(size_type
) const;
89 /// Finds an entry by __order. Returns an iterator to the entry
90 /// with the __order order, or an iterator to the container
91 /// object's end if order is at least the size of the container
94 find_by_order(size_type
);
96 /// Returns the order of a key within a sequence. For exapmle, if
97 /// r_key is the smallest key, this method will return 0; if r_key
98 /// is a key between the smallest and next key, this method will
99 /// return 1; if r_key is a key larger than the largest key, this
100 /// method will return the size of r_c.
102 order_of_key(key_const_reference
) const;
105 /// Const reference to the container's value-type.
106 typedef typename
base_type::const_reference const_reference
;
108 /// Const pointer to the container's value-type.
109 typedef typename
base_type::const_pointer const_pointer
;
111 /// Const metadata reference.
112 typedef typename
detail::rebind_traits
<_Alloc
, metadata_type
>::const_reference
113 metadata_const_reference
;
115 /// Metadata reference.
116 typedef typename
detail::rebind_traits
<_Alloc
, metadata_type
>::reference
119 /// Returns the node_const_iterator associated with the tree's root node.
120 virtual node_const_iterator
121 node_begin() const = 0;
123 /// Returns the node_iterator associated with the tree's root node.
124 virtual node_iterator
127 /// Returns the node_const_iterator associated with a just-after leaf node.
128 virtual node_const_iterator
129 node_end() const = 0;
131 /// Returns the node_iterator associated with a just-after leaf node.
132 virtual node_iterator
135 /// Access to the cmp_fn object.
140 /// Updates the rank of a node through a node_iterator node_it;
141 /// end_nd_it is the end node iterator.
143 operator()(node_iterator
, node_const_iterator
) const;
146 ~tree_order_statistics_node_update();
149 #include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp>
151 #undef PB_DS_CLASS_T_DEC
152 #undef PB_DS_CLASS_C_DEC
153 #undef PB_DS_BRANCH_POLICY_BASE
155 } // namespace __gnu_pbds