]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
99dee823 | 3 | // Copyright (C) 2005-2021 Free Software Foundation, Inc. |
4569a895 AT |
4 | // |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
9 | // version. |
10 | ||
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. | |
15 | ||
748086b7 JJ |
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. | |
19 | ||
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/>. | |
4569a895 AT |
24 | |
25 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
26 | ||
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 | |
34 | // warranty. | |
35 | ||
36 | /** | |
37 | * @file tree_policy.hpp | |
38 | * Contains tree-related policies. | |
39 | */ | |
40 | ||
41 | #ifndef PB_DS_TREE_POLICY_HPP | |
42 | #define PB_DS_TREE_POLICY_HPP | |
43 | ||
8fc81078 | 44 | #include <bits/c++config.h> |
4569a895 AT |
45 | #include <iterator> |
46 | #include <ext/pb_ds/detail/type_utils.hpp> | |
a345e45d | 47 | #include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> |
4569a895 | 48 | |
5e11f978 | 49 | namespace __gnu_pbds |
4569a895 | 50 | { |
4569a895 | 51 | #define PB_DS_CLASS_T_DEC \ |
a345e45d BK |
52 | template<typename Node_CItr, typename Node_Itr, typename Cmp_Fn, \ |
53 | typename _Alloc> | |
4569a895 AT |
54 | |
55 | #define PB_DS_CLASS_C_DEC \ | |
a345e45d | 56 | tree_order_statistics_node_update<Node_CItr, Node_Itr, Cmp_Fn, _Alloc> |
4569a895 | 57 | |
a345e45d BK |
58 | #define PB_DS_BRANCH_POLICY_BASE \ |
59 | detail::branch_policy<Node_CItr, Node_Itr, _Alloc> | |
4569a895 | 60 | |
a345e45d BK |
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 | |
4569a895 AT |
65 | { |
66 | private: | |
a345e45d | 67 | typedef PB_DS_BRANCH_POLICY_BASE base_type; |
4569a895 AT |
68 | |
69 | public: | |
a345e45d BK |
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; | |
75 | ||
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; | |
4569a895 | 81 | |
30a96b3b BK |
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 | |
85 | /// container object. | |
4569a895 | 86 | inline const_iterator |
a345e45d | 87 | find_by_order(size_type) const; |
4569a895 | 88 | |
30a96b3b BK |
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 | |
92 | /// object. | |
4569a895 | 93 | inline iterator |
a345e45d | 94 | find_by_order(size_type); |
4569a895 | 95 | |
30a96b3b BK |
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. | |
4569a895 | 101 | inline size_type |
a345e45d | 102 | order_of_key(key_const_reference) const; |
4569a895 AT |
103 | |
104 | private: | |
30a96b3b | 105 | /// Const reference to the container's value-type. |
a345e45d | 106 | typedef typename base_type::const_reference const_reference; |
4569a895 | 107 | |
30a96b3b | 108 | /// Const pointer to the container's value-type. |
a345e45d BK |
109 | typedef typename base_type::const_pointer const_pointer; |
110 | ||
30a96b3b | 111 | /// Const metadata reference. |
ec541f1b JW |
112 | typedef typename detail::rebind_traits<_Alloc, metadata_type>::const_reference |
113 | metadata_const_reference; | |
4569a895 | 114 | |
30a96b3b | 115 | /// Metadata reference. |
ec541f1b JW |
116 | typedef typename detail::rebind_traits<_Alloc, metadata_type>::reference |
117 | metadata_reference; | |
4569a895 | 118 | |
30a96b3b | 119 | /// Returns the node_const_iterator associated with the tree's root node. |
a345e45d | 120 | virtual node_const_iterator |
4569a895 AT |
121 | node_begin() const = 0; |
122 | ||
30a96b3b | 123 | /// Returns the node_iterator associated with the tree's root node. |
4569a895 AT |
124 | virtual node_iterator |
125 | node_begin() = 0; | |
126 | ||
30a96b3b | 127 | /// Returns the node_const_iterator associated with a just-after leaf node. |
a345e45d | 128 | virtual node_const_iterator |
4569a895 AT |
129 | node_end() const = 0; |
130 | ||
30a96b3b | 131 | /// Returns the node_iterator associated with a just-after leaf node. |
4569a895 AT |
132 | virtual node_iterator |
133 | node_end() = 0; | |
134 | ||
30a96b3b | 135 | /// Access to the cmp_fn object. |
4569a895 AT |
136 | virtual cmp_fn& |
137 | get_cmp_fn() = 0; | |
138 | ||
139 | protected: | |
30a96b3b BK |
140 | /// Updates the rank of a node through a node_iterator node_it; |
141 | /// end_nd_it is the end node iterator. | |
4569a895 | 142 | inline void |
a345e45d | 143 | operator()(node_iterator, node_const_iterator) const; |
4569a895 AT |
144 | |
145 | virtual | |
146 | ~tree_order_statistics_node_update(); | |
147 | }; | |
148 | ||
149 | #include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp> | |
150 | ||
151 | #undef PB_DS_CLASS_T_DEC | |
152 | #undef PB_DS_CLASS_C_DEC | |
a345e45d | 153 | #undef PB_DS_BRANCH_POLICY_BASE |
4569a895 | 154 | |
5e11f978 | 155 | } // namespace __gnu_pbds |
4569a895 AT |
156 | |
157 | #endif |