3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file splay_tree_.hpp
42 * Contains an implementation class for splay_tree_.
45 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
46 #ifndef BIN_SEARCH_TREE_HPP__DATA_TRUE_INDICATOR
47 #define BIN_SEARCH_TREE_HPP__DATA_TRUE_INDICATOR
48 #include <ext/pb_assoc/detail/bin_search_tree_/bin_search_tree_.hpp>
49 #endif // #ifndef BIN_SEARCH_TREE_HPP__DATA_TRUE_INDICATOR
50 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
52 #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
53 #ifndef BIN_SEARCH_TREE_HPP__DATA_FALSE_INDICATOR
54 #define BIN_SEARCH_TREE_HPP__DATA_FALSE_INDICATOR
55 #include <ext/pb_assoc/detail/bin_search_tree_/bin_search_tree_.hpp>
56 #endif // #ifndef BIN_SEARCH_TREE_HPP__DATA_FALSE_INDICATOR
57 #endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
59 #include <ext/pb_assoc/detail/splay_tree_/node.hpp>
70 #ifdef PB_ASSOC_SPLAY_TREE_DEBUG_
71 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
72 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
73 #define PB_ASSOC_DBG_ONLY(X) X
74 #else // #ifdef PB_ASSOC_SPLAY_TREE_DEBUG_
75 #define PB_ASSOC_DBG_ASSERT(X)
76 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
77 #define PB_ASSOC_DBG_ONLY(X) ;
78 #endif // #ifdef PB_ASSOC_SPLAY_TREE_DEBUG_
80 #define PB_ASSOC_CLASS_T_DEC \
88 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
89 #define PB_ASSOC_CLASS_NAME \
91 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
93 #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
94 #define PB_ASSOC_CLASS_NAME \
96 #endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
98 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
99 #define PB_ASSOC_BASE_CLASS_NAME \
100 bin_search_tree_data_
101 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
103 #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
104 #define PB_ASSOC_BASE_CLASS_NAME \
105 bin_search_tree_no_data_
106 #endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
108 #define PB_ASSOC_CLASS_C_DEC \
109 PB_ASSOC_CLASS_NAME< \
116 #define PB_ASSOC_TYPES_TRAITS_C_DEC \
122 #define PB_ASSOC_NODE_C_DEC \
124 typename PB_ASSOC_TYPES_TRAITS_C_DEC::value_type, \
127 #define PB_ASSOC_BASE_C_DEC \
128 PB_ASSOC_BASE_CLASS_NAME< \
131 PB_ASSOC_NODE_C_DEC, \
136 template<typename Key,
141 struct PB_ASSOC_CLASS_NAME : public PB_ASSOC_BASE_C_DEC
146 typedef typename Allocator::size_type size_type;
149 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_key_reference
152 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_type data_type;
155 typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_reference
159 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_data_reference
160 const_data_reference;
162 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::value_type value_type;
164 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::pointer pointer;
167 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_pointer
170 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::reference reference;
173 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_reference
176 typedef typename PB_ASSOC_BASE_C_DEC::node_pointer node_pointer;
178 typedef typename PB_ASSOC_BASE_C_DEC::find_iterator find_iterator;
181 typename PB_ASSOC_BASE_C_DEC::const_iterator
184 typedef typename PB_ASSOC_BASE_C_DEC::iterator iterator;
186 typedef typename PB_ASSOC_BASE_C_DEC::const_iterator const_iterator;
189 typename PB_ASSOC_BASE_C_DEC::reverse_iterator
193 typename PB_ASSOC_BASE_C_DEC::const_reverse_iterator
194 const_reverse_iterator;
198 PB_ASSOC_CLASS_NAME();
200 PB_ASSOC_CLASS_NAME(const Cmp_Fn& r_cmp_fn);
202 PB_ASSOC_CLASS_NAME(const Cmp_Fn& r_cmp_fn, const Node_Updator& r_node_updator);
204 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other);
207 swap(PB_ASSOC_CLASS_C_DEC& r_other);
211 copy_from_range(It first_it, It last_it);
216 inline std::pair<find_iterator, bool>
217 insert(const_reference r_value);
219 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
220 inline data_reference
221 subscript_imp(const_key_reference r_key);
222 #endif // #ifdef PB_ASSOC_DATA_TRUE
225 lower_bound(const_key_reference r_key);
227 inline const_find_iterator
228 lower_bound(const_key_reference r_key) const;
231 upper_bound(const_key_reference r_key);
233 inline const_find_iterator
234 upper_bound(const_key_reference r_key) const;
237 find(const_key_reference r_key);
239 inline const_find_iterator
240 find(const_key_reference r_key) const;
243 erase(const_key_reference r_key);
245 inline const_iterator
246 erase(const_iterator it);
248 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
251 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
253 inline const_reverse_iterator
254 erase(const_reverse_iterator it);
256 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
257 inline reverse_iterator
258 erase(reverse_iterator it);
259 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
266 leftmost(node_pointer p_nd);
269 join(PB_ASSOC_CLASS_C_DEC& r_other);
272 split(const_key_reference r_key, PB_ASSOC_CLASS_C_DEC& r_other);
274 #ifdef PB_ASSOC_SPLAY_TREE_DEBUG_
277 assert_valid() const;
280 assert_special_imp(const node_pointer p_nd) const;
282 #endif // #ifdef PB_ASSOC_SPLAY_TREE_DEBUG_
287 splay(node_pointer p_nd);
290 splay_zig_zag_left(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
293 splay_zig_zag_right(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
296 splay_zig_zig_left(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
299 splay_zig_zig_right(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
302 splay_zz_start(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
305 splay_zz_end(node_pointer p_nd, node_pointer p_parent, node_pointer p_grandparent);
308 erase_node(node_pointer p_nd);
312 #include <ext/pb_assoc/detail/splay_tree_/constructors_destructor_fn_imps.hpp>
313 #include <ext/pb_assoc/detail/splay_tree_/info_fn_imps.hpp>
314 #include <ext/pb_assoc/detail/splay_tree_/insert_fn_imps.hpp>
315 #include <ext/pb_assoc/detail/splay_tree_/splay_fn_imps.hpp>
316 #include <ext/pb_assoc/detail/splay_tree_/erase_fn_imps.hpp>
317 #include <ext/pb_assoc/detail/splay_tree_/find_fn_imps.hpp>
318 #include <ext/pb_assoc/detail/splay_tree_/debug_fn_imps.hpp>
319 #include <ext/pb_assoc/detail/splay_tree_/split_join_fn_imps.hpp>
321 #undef PB_ASSOC_CLASS_T_DEC
323 #undef PB_ASSOC_CLASS_C_DEC
325 #undef PB_ASSOC_CLASS_NAME
327 #undef PB_ASSOC_TYPES_TRAITS_C_DEC
329 #undef PB_ASSOC_BASE_CLASS_NAME
331 #undef PB_ASSOC_NODE_C_DEC
333 #undef PB_ASSOC_BASE_C_DEC
335 #undef PB_ASSOC_DBG_ASSERT
336 #undef PB_ASSOC_DBG_VERIFY
337 #undef PB_ASSOC_DBG_ONLY
339 } // namespace detail
341 } // namespace pb_assoc