Add rational load factor resizing policy
[libcds.git] / cds / container / bronson_avltree_map_rcu.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_BRONSON_AVLTREE_MAP_RCU_H
4 #define CDSLIB_CONTAINER_BRONSON_AVLTREE_MAP_RCU_H
5
6 #include <functional>
7 #include <cds/container/impl/bronson_avltree_map_rcu.h>
8
9 namespace cds { namespace container {
10
11     namespace bronson_avltree {
12         //@cond
13         namespace details {
14             template < class RCU, typename Key, typename T, typename Traits>
15             struct make_map
16             {
17                 typedef Key key_type;
18                 typedef T mapped_type;
19                 typedef Traits original_traits;
20
21                 typedef cds::details::Allocator< mapped_type, typename original_traits::allocator > cxx_allocator;
22
23                 struct traits : public original_traits
24                 {
25                     struct disposer {
26                         void operator()( mapped_type * p ) const
27                         {
28                             cxx_allocator().Delete( p );
29                         }
30                     };
31                 };
32
33                 // Metafunction result
34                 typedef BronsonAVLTreeMap< RCU, Key, mapped_type *, traits > type;
35             };
36         } // namespace details
37         //@endcond
38     } // namespace bronson_avltree
39
40     /// Bronson et al AVL-tree (RCU specialization)
41     /** @ingroup cds_nonintrusive_map
42         @ingroup cds_nonintrusive_tree
43         @anchor cds_container_BronsonAVLTreeMap_rcu
44
45         Source:
46             - [2010] N.Bronson, J.Casper, H.Chafi, K.Olukotun "A Practical Concurrent Binary Search Tree"
47             - <a href="http://github.com/nbronson/snaptree">Java implementation</a>
48
49         This is a concurrent AVL tree algorithm that uses hand-over-hand optimistic validation,
50         a concurrency control mechanism for searching and navigating a binary search tree.
51         This mechanism minimizes spurious retries when concurrent structural changes cannot
52         affect the correctness of the search or navigation result.
53         The algorithm is based on partially external trees, a simple scheme that simplifies deletions
54         by leaving a routing node in the tree when deleting a node that has two children,
55         then opportunistically unlinking routing nodes during rebalancing. As in external trees,
56         which store values only in leaf nodes, deletions can be performed locally while holding
57         a fixed number of locks. Partially external trees, however, require far fewer routing nodes
58         than an external tree for most sequences of insertions and deletions.
59         The algorithm uses optimistic concurrency control, but carefully manage the
60         tree in such a way that all atomic regions have fixed read and write sets
61         that are known ahead of time. This allows to reduce practical overheads by embedding
62         the concurrency control directly. To perform tree operations using only fixed sized
63         atomic regions the algo uses the following mechanisms: search operations overlap atomic blocks as
64         in the hand-over-hand locking technique; mutations perform rebalancing separately;
65         and deletions occasionally leave a routing node in the tree.
66
67         <b>Template arguments</b>:
68         - \p RCU - one of \ref cds_urcu_gc "RCU type"
69         - \p Key - key type
70         - \p T - value type to be stored in tree's nodes.
71         - \p Traits - tree traits, default is \p bronson_avltree::traits
72             It is possible to declare option-based tree with \p bronson_avltree::make_traits metafunction
73             instead of \p Traits template argument.
74
75         There is \ref cds_container_BronsonAVLTreeMap_rcu_ptr "a specialization" for "key -> value pointer" map.
76
77         @note Before including <tt><cds/container/bronson_avltree_map_rcu.h></tt> you should include appropriate RCU header file,
78         see \ref cds_urcu_gc "RCU type" for list of existing RCU class and corresponding header files.
79     */
80     template <
81         typename RCU,
82         typename Key,
83         typename T,
84 #   ifdef CDS_DOXYGEN_INVOKED
85         typename Traits = bronson_avltree::traits
86 #else
87         typename Traits
88 #endif
89     >
90     class BronsonAVLTreeMap< cds::urcu::gc<RCU>, Key, T, Traits >
91 #ifdef CDS_DOXYGEN_INVOKED
92         : private BronsonAVLTreeMap< cds::urcu::gc<RCU>, Key, T*, Traits >
93 #else
94         : private bronson_avltree::details::make_map< cds::urcu::gc<RCU>, Key, T, Traits >::type
95 #endif
96     {
97         //@cond
98         typedef bronson_avltree::details::make_map< cds::urcu::gc<RCU>, Key, T, Traits > maker;
99         typedef typename maker::type base_class;
100         //@endcond
101
102     public:
103         typedef cds::urcu::gc<RCU>  gc;   ///< RCU Garbage collector
104         typedef Key     key_type;    ///< type of a key stored in the map
105         typedef T       mapped_type; ///< type of value stored in the map
106         typedef Traits  traits;      ///< Traits template parameter
107
108         typedef typename base_class::key_comparator     key_comparator;     ///< key compare functor based on \p Traits::compare and \p Traits::less
109         typedef typename traits::item_counter           item_counter;       ///< Item counting policy
110         typedef typename traits::memory_model           memory_model;       ///< Memory ordering, see \p cds::opt::memory_model option
111         typedef typename traits::allocator              allocator_type;     ///< allocator for value
112         typedef typename traits::node_allocator         node_allocator_type;///< allocator for maintaining internal nodes
113         typedef typename traits::stat                   stat;               ///< internal statistics
114         typedef typename traits::rcu_check_deadlock     rcu_check_deadlock; ///< Deadlock checking policy
115         typedef typename traits::back_off               back_off;           ///< Back-off strategy
116         typedef typename traits::sync_monitor           sync_monitor;       ///< @ref cds_sync_monitor "Synchronization monitor" type for node-level locking
117
118         /// Enabled or disabled @ref bronson_avltree::relaxed_insert "relaxed insertion"
119         static bool const c_bRelaxedInsert = traits::relaxed_insert;
120
121         /// Group of \p extract_xxx functions does not require external locking
122         static CDS_CONSTEXPR const bool c_bExtractLockExternal = base_class::c_bExtractLockExternal;
123
124         typedef typename base_class::rcu_lock   rcu_lock;  ///< RCU scoped lock
125
126         /// Returned pointer to \p mapped_type of extracted node
127         typedef typename base_class::exempt_ptr exempt_ptr;
128
129     protected:
130         //@cond
131         typedef typename base_class::node_type        node_type;
132         typedef typename base_class::node_scoped_lock node_scoped_lock;
133         typedef typename maker::cxx_allocator         cxx_allocator;
134
135         typedef typename base_class::update_flags update_flags;
136         //@endcond
137
138     public:
139         /// Creates empty map
140         BronsonAVLTreeMap()
141         {}
142
143         /// Destroys the map
144         ~BronsonAVLTreeMap()
145         {}
146
147         /// Inserts new node with \p key and default value
148         /**
149             The function creates a node with \p key and default value, and then inserts the node created into the map.
150
151             Preconditions:
152             - The \p key_type should be constructible from a value of type \p K.
153             - The \p mapped_type should be default-constructible.
154
155             RCU \p synchronize() can be called. RCU should not be locked.
156
157             Returns \p true if inserting successful, \p false otherwise.
158         */
159         template <typename K>
160         bool insert( K const& key )
161         {
162             return base_class::do_update(key, key_comparator(),
163                 []( node_type * pNode ) -> mapped_type*
164                 {
165                     assert( pNode->m_pValue.load( memory_model::memory_order_relaxed ) == nullptr );
166                     CDS_UNUSED( pNode );
167                     return cxx_allocator().New();
168                 },
169                 update_flags::allow_insert
170             ) == update_flags::result_inserted;
171         }
172
173         /// Inserts new node
174         /**
175             The function creates a node with copy of \p val value
176             and then inserts the node created into the map.
177
178             Preconditions:
179             - The \p key_type should be constructible from \p key of type \p K.
180             - The \p mapped_type should be constructible from \p val of type \p V.
181
182             RCU \p synchronize() method can be called. RCU should not be locked.
183
184             Returns \p true if \p val is inserted into the map, \p false otherwise.
185         */
186         template <typename K, typename V>
187         bool insert( K const& key, V const& val )
188         {
189             return base_class::do_update( key, key_comparator(),
190                 [&val]( node_type * pNode ) -> mapped_type*
191                 {
192                     assert( pNode->m_pValue.load( memory_model::memory_order_relaxed ) == nullptr );
193                     CDS_UNUSED( pNode );
194                     return cxx_allocator().New( val );
195                 },
196                 update_flags::allow_insert
197             ) == update_flags::result_inserted;
198         }
199
200         /// Inserts new node and initialize it by a functor
201         /**
202             This function inserts new node with key \p key and if inserting is successful then it calls
203             \p func functor with signature
204             \code
205                 struct functor {
206                     void operator()( key_type const& key, mapped_type& item );
207                 };
208             \endcode
209
210             The key_type should be constructible from value of type \p K.
211
212             The function allows to split creating of new item into two part:
213             - create item from \p key;
214             - insert new item into the map;
215             - if inserting is successful, initialize the value of item by calling \p func functor
216
217             This can be useful if complete initialization of object of \p value_type is heavyweight and
218             it is preferable that the initialization should be completed only if inserting is successful.
219             The functor is called under the node lock.
220
221             RCU \p synchronize() method can be called. RCU should not be locked.
222         */
223         template <typename K, typename Func>
224         bool insert_with( K const& key, Func func )
225         {
226             return base_class::do_update( key, key_comparator(),
227                 [&func]( node_type * pNode ) -> mapped_type*
228                 {
229                     assert( pNode->m_pValue.load( memory_model::memory_order_relaxed ) == nullptr );
230                     mapped_type * pVal = cxx_allocator().New();
231                     func( pNode->m_key, *pVal );
232                     return pVal;
233                 },
234                 update_flags::allow_insert
235             ) == update_flags::result_inserted;
236         }
237
238         /// For key \p key inserts data of type \p mapped_type created in-place from \p args
239         /**
240             Returns \p true if inserting successful, \p false otherwise.
241
242             RCU \p synchronize() method can be called. RCU should not be locked.
243         */
244         template <typename K, typename... Args>
245         bool emplace( K&& key, Args&&... args )
246         {
247 #       if !( CDS_COMPILER == CDS_COMPILER_GCC && CDS_COMPILER_VERSION >= 40800 && CDS_COMPILER_VERSION < 40900 )
248             // Probably, the following code is not so efficient, since we pass lvalues instead rvalues to lambda
249             //TODO: study how to pass a parameter pack to a lambda efficiently using perfect forwarding
250             // see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#904 - this is what we need
251             return base_class::do_update( key, key_comparator(),
252                 [&args...]( node_type * pNode ) -> mapped_type *
253                 {
254                     assert( pNode->m_pValue.load( memory_model::memory_order_relaxed ) == nullptr );
255                     CDS_UNUSED( pNode );
256                     return cxx_allocator().New( std::forward<Args>(args)...);
257                 },
258                 update_flags::allow_insert
259             ) == update_flags::result_inserted;
260 #       else
261             // gcc 4.8 error: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226
262             // workaround (from http://stackoverflow.com/questions/14191989/how-do-i-use-variadic-perfect-forwarding-into-a-lambda)
263             auto f = std::bind<mapped_type *>(
264                         []( Args... args) -> mapped_type* { return cxx_allocator().New( std::move(args)...); },
265                         std::forward<Args>(args)...
266                         );
267             return base_class::do_update( key, key_comparator(),
268                 [&f]( node_type * pNode ) -> mapped_type *
269                 {
270                     assert( pNode->m_pValue.load( memory_model::memory_order_relaxed ) == nullptr );
271                     CDS_UNUSED( pNode );
272                     return f();
273                 },
274                 update_flags::allow_insert
275             ) == update_flags::result_inserted;
276 #       endif
277         }
278
279         /// Ensures that the \p key exists in the map
280         /**
281             The operation performs inserting or changing data with lock-free manner.
282
283             If the \p key not found in the map, then the new item created from \p key
284             will be inserted into the map (note that in this case the \ref key_type should be
285             constructible from type \p K).
286             Otherwise, the functor \p func is called with item found.
287             The functor \p Func may be a functor:
288             \code
289                 struct my_functor {
290                     void operator()( bool bNew, key_type const& key, mapped_type& item );
291                 };
292             \endcode
293
294             with arguments:
295             - \p bNew - \p true if the item has been inserted, \p false otherwise
296             - \p item - value
297
298             The functor may change any fields of the \p item. The functor is called under the node lock.
299
300             RCU \p synchronize() method can be called. RCU should not be locked.
301
302             Returns <tt> std::pair<bool, bool> </tt> where \p first is \p true if operation is successfull,
303             \p second is \p true if new item has been added or \p false if the item with \p key
304             already exists.
305         */
306         template <typename K, typename Func>
307         std::pair<bool, bool> update( K const& key, Func func )
308         {
309             int result = base_class::do_update( key, key_comparator(),
310                 [&func]( node_type * pNode ) -> mapped_type*
311                 {
312                     mapped_type * pVal = pNode->m_pValue.load( memory_model::memory_order_relaxed );
313                     if ( !pVal ) {
314                         pVal = cxx_allocator().New();
315                         func( true, pNode->m_key, *pVal );
316                     }
317                     else
318                         func( false, pNode->m_key, *pVal );
319                     return pVal;
320                 },
321                 update_flags::allow_insert | update_flags::allow_update
322             );
323             return std::make_pair( result != 0, (result & update_flags::result_inserted) != 0 );
324         }
325
326         //@cond
327         template <typename K, typename Func>
328         std::pair<bool, bool> ensure( K const& key, Func func )
329         {
330             return update( key, func );
331         }
332         //@endcond
333
334
335         /// Delete \p key from the map
336         /**
337             RCU \p synchronize() method can be called. RCU should not be locked.
338
339             Return \p true if \p key is found and deleted, \p false otherwise
340         */
341         template <typename K>
342         bool erase( K const& key )
343         {
344             return base_class::erase( key );
345         }
346
347         /// Deletes the item from the map using \p pred predicate for searching
348         /**
349             The function is an analog of \p erase(K const&)
350             but \p pred is used for key comparing.
351             \p Less functor has the interface like \p std::less.
352             \p Less must imply the same element order as the comparator used for building the map.
353         */
354         template <typename K, typename Less>
355         bool erase_with( K const& key, Less pred )
356         {
357             return base_class::erase_with( key, pred );
358         }
359
360         /// Delete \p key from the map
361         /** \anchor cds_nonintrusive_BronsonAVLTreeMap_rcu_erase_func
362
363             The function searches an item with key \p key, calls \p f functor
364             and deletes the item. If \p key is not found, the functor is not called.
365
366             The functor \p Func interface:
367             \code
368             struct extractor {
369                 void operator()(key_type const& key, mapped_type& item) { ... }
370             };
371             \endcode
372
373             RCU \p synchronize method can be called. RCU should not be locked.
374
375             Return \p true if key is found and deleted, \p false otherwise
376         */
377         template <typename K, typename Func>
378         bool erase( K const& key, Func f )
379         {
380             return base_class::erase( key, f );
381         }
382
383         /// Deletes the item from the map using \p pred predicate for searching
384         /**
385             The function is an analog of \ref cds_nonintrusive_BronsonAVLTreeMap_rcu_erase_func "erase(K const&, Func)"
386             but \p pred is used for key comparing.
387             \p Less functor has the interface like \p std::less.
388             \p Less must imply the same element order as the comparator used for building the map.
389         */
390         template <typename K, typename Less, typename Func>
391         bool erase_with( K const& key, Less pred, Func f )
392         {
393             return base_class::erase_with( key, pred, f );
394         }
395
396         /// Extracts a value with minimal key from the map
397         /**
398             Returns \p exempt_ptr pointer to the leftmost item.
399             If the set is empty, returns empty \p exempt_ptr.
400
401             Note that the function returns only the value for minimal key.
402             To retrieve its key use \p extract_min( Func ) member function.
403
404             @note Due the concurrent nature of the map, the function extracts <i>nearly</i> minimum key.
405             It means that the function gets leftmost leaf of the tree and tries to unlink it.
406             During unlinking, a concurrent thread may insert an item with key less than leftmost item's key.
407             So, the function returns the item with minimum key at the moment of tree traversing.
408
409             RCU \p synchronize method can be called. RCU should NOT be locked.
410             The function does not free the item.
411             The deallocator will be implicitly invoked when the returned object is destroyed or when
412             its \p release() member function is called.
413         */
414         exempt_ptr extract_min()
415         {
416             return base_class::extract_min();
417         }
418
419         /// Extracts minimal key key and corresponding value
420         /**
421             Returns \p exempt_ptr to the leftmost item.
422             If the tree is empty, returns empty \p exempt_ptr.
423
424             \p Func functor is used to store minimal key.
425             \p Func has the following signature:
426             \code
427                 struct functor {
428                     void operator()( key_type const& key );
429                 };
430             \endcode
431             If the tree is empty, \p f is not called.
432             Otherwise, is it called with minimal key, the pointer to corresponding value is returned
433             as \p exempt_ptr.
434
435             @note Due the concurrent nature of the map, the function extracts <i>nearly</i> minimum key.
436             It means that the function gets leftmost leaf of the tree and tries to unlink it.
437             During unlinking, a concurrent thread may insert an item with key less than leftmost item's key.
438             So, the function returns the item with minimum key at the moment of tree traversing.
439
440             RCU \p synchronize method can be called. RCU should NOT be locked.
441             The function does not free the item.
442             The deallocator will be implicitly invoked when the returned object is destroyed or when
443             its \p release() member function is called.
444         */
445         template <typename Func>
446         exempt_ptr extract_min( Func f )
447         {
448             return base_class::extract_min( f );
449         }
450
451         /// Extracts minimal key key and corresponding value
452         /**
453             This function is a shortcut for the following call:
454             \code
455                 key_type key;
456                 exempt_ptr xp = theTree.extract_min( [&key]( key_type const& k ) { key = k; } );
457             \endcode
458             \p key_type should be copy-assignable. The copy of minimal key
459             is returned in \p min_key argument.
460         */
461         typename std::enable_if< std::is_copy_assignable<key_type>::value, exempt_ptr >::type
462         extract_min_key( key_type& min_key )
463         {
464             return base_class::extract_min_key( min_key );
465         }
466
467         /// Extracts an item with maximal key from the map
468         /**
469             Returns \p exempt_ptr pointer to the rightmost item.
470             If the set is empty, returns empty \p exempt_ptr.
471
472             Note that the function returns only the value for maximal key.
473             To retrieve its key use \p extract_max( Func ) or \p extract_max_key(key_type&) member function.
474
475             @note Due the concurrent nature of the map, the function extracts <i>nearly</i> maximal key.
476             It means that the function gets rightmost leaf of the tree and tries to unlink it.
477             During unlinking, a concurrent thread may insert an item with key great than leftmost item's key.
478             So, the function returns the item with maximum key at the moment of tree traversing.
479
480             RCU \p synchronize method can be called. RCU should NOT be locked.
481             The function does not free the item.
482             The deallocator will be implicitly invoked when the returned object is destroyed or when
483             its \p release() is called.
484         */
485         exempt_ptr extract_max()
486         {
487             return base_class::extract_max();
488         }
489
490         /// Extracts the maximal key and corresponding value
491         /**
492             Returns \p exempt_ptr pointer to the rightmost item.
493             If the set is empty, returns empty \p exempt_ptr.
494
495             \p Func functor is used to store maximal key.
496             \p Func has the following signature:
497             \code
498                 struct functor {
499                     void operator()( key_type const& key );
500                 };
501             \endcode
502             If the tree is empty, \p f is not called.
503             Otherwise, is it called with maximal key, the pointer to corresponding value is returned
504             as \p exempt_ptr.
505
506             @note Due the concurrent nature of the map, the function extracts <i>nearly</i> maximal key.
507             It means that the function gets rightmost leaf of the tree and tries to unlink it.
508             During unlinking, a concurrent thread may insert an item with key great than leftmost item's key.
509             So, the function returns the item with maximum key at the moment of tree traversing.
510
511             RCU \p synchronize method can be called. RCU should NOT be locked.
512             The function does not free the item.
513             The deallocator will be implicitly invoked when the returned object is destroyed or when
514             its \p release() is called.
515         */
516         template <typename Func>
517         exempt_ptr extract_max( Func f )
518         {
519             return base_class::extract_max( f );
520         }
521
522         /// Extracts the maximal key and corresponding value
523         /**
524             This function is a shortcut for the following call:
525             \code
526                 key_type key;
527                 exempt_ptr xp = theTree.extract_max( [&key]( key_type const& k ) { key = k; } );
528             \endcode
529             \p key_type should be copy-assignable. The copy of maximal key
530             is returned in \p max_key argument.
531         */
532         typename std::enable_if< std::is_copy_assignable<key_type>::value, exempt_ptr >::type
533         extract_max_key( key_type& max_key )
534         {
535             return base_class::extract_max_key( max_key );
536         }
537
538         /// Extracts an item from the map
539         /**
540             The function searches an item with key equal to \p key in the tree,
541             unlinks it, and returns \p exempt_ptr pointer to a value found.
542             If \p key is not found the function returns an empty \p exempt_ptr.
543
544             RCU \p synchronize method can be called. RCU should NOT be locked.
545             The function does not destroy the value found.
546             The dealloctor will be implicitly invoked when the returned object is destroyed or when
547             its \p release() member function is called.
548         */
549         template <typename Q>
550         exempt_ptr extract( Q const& key )
551         {
552             return base_class::extract( key );
553         }
554
555         /// Extracts an item from the map using \p pred for searching
556         /**
557             The function is an analog of \p extract(Q const&)
558             but \p pred is used for key compare.
559             \p Less has the interface like \p std::less.
560             \p pred must imply the same element order as the comparator used for building the map.
561         */
562         template <typename Q, typename Less>
563         exempt_ptr extract_with( Q const& key, Less pred )
564         {
565             return base_class::extract_with( key, pred );
566         }
567
568         /// Find the key \p key
569         /**
570             The function searches the item with key equal to \p key and calls the functor \p f for item found.
571             The interface of \p Func functor is:
572             \code
573             struct functor {
574                 void operator()( key_type const& key, mapped_type& val );
575             };
576             \endcode
577             where \p val is the item found for \p key
578             The functor is called under node-level lock.
579
580             The function applies RCU lock internally.
581
582             The function returns \p true if \p key is found, \p false otherwise.
583         */
584         template <typename K, typename Func>
585         bool find( K const& key, Func f )
586         {
587             return base_class::find( key, f );
588         }
589
590         /// Finds the key \p val using \p pred predicate for searching
591         /**
592             The function is an analog of \p find(K const&, Func)
593             but \p pred is used for key comparing.
594             \p Less functor has the interface like \p std::less.
595             \p Less must imply the same element order as the comparator used for building the map.
596         */
597         template <typename K, typename Less, typename Func>
598         bool find_with( K const& key, Less pred, Func f )
599         {
600             return base_class::find_with( key, pred, f );
601         }
602
603         /// Find the key \p key
604         /**
605             The function searches the item with key equal to \p key
606             and returns \p true if it is found, and \p false otherwise.
607
608             The function applies RCU lock internally.
609         */
610         template <typename K>
611         bool find( K const& key )
612         {
613             return base_class::find( key );
614         }
615
616         /// Finds the key \p val using \p pred predicate for searching
617         /**
618             The function is an analog of \p find(K const&)
619             but \p pred is used for key comparing.
620             \p Less functor has the interface like \p std::less.
621             \p Less must imply the same element order as the comparator used for building the map.
622         */
623         template <typename K, typename Less>
624         bool find_with( K const& key, Less pred )
625         {
626             return base_class::find_with( key, pred );
627         }
628
629         /// Clears the map
630         void clear()
631         {
632             base_class::clear();
633         }
634
635         /// Checks if the map is empty
636         bool empty() const
637         {
638             return base_class::empty();
639         }
640
641         /// Returns item count in the map
642         /**
643             Only leaf nodes containing user data are counted.
644
645             The value returned depends on item counter type provided by \p Traits template parameter.
646             If it is \p atomicity::empty_item_counter this function always returns 0.
647
648             The function is not suitable for checking the tree emptiness, use \p empty()
649             member function for this purpose.
650         */
651         size_t size() const
652         {
653             return base_class::size();
654         }
655
656         /// Returns const reference to internal statistics
657         stat const& statistics() const
658         {
659             return base_class::statistics();
660         }
661
662         /// Returns reference to \p sync_monitor object
663         sync_monitor& monitor()
664         {
665             return base_class::monitor();
666         }
667         //@cond
668         sync_monitor const& monitor() const
669         {
670             return base_class::monitor();
671         }
672         //@endcond
673
674         /// Checks internal consistency (not atomic, not thread-safe)
675         /**
676             The debugging function to check internal consistency of the tree.
677         */
678         bool check_consistency() const
679         {
680             return base_class::check_consistency();
681         }
682
683         /// Checks internal consistency (not atomic, not thread-safe)
684         /**
685             The debugging function to check internal consistency of the tree.
686             The functor \p Func is called if a violation of internal tree structure
687             is found:
688             \code
689             struct functor {
690                 void operator()( size_t nLevel, size_t hLeft, size_t hRight );
691             };
692             \endcode
693             where
694             - \p nLevel - the level where the violation is found
695             - \p hLeft - the height of left subtree
696             - \p hRight - the height of right subtree
697
698             The functor is called for each violation found.
699         */
700         template <typename Func>
701         bool check_consistency( Func f ) const
702         {
703             return base_class::check_consistency( f );
704         }
705     };
706 }} // namespace cds::container
707
708 #endif // #ifndef CDSLIB_CONTAINER_IMPL_BRONSON_AVLTREE_MAP_RCU_H