3 #ifndef __CDSUNIT_STD_ELLEN_BINTREE_PQUEUE_H
4 #define __CDSUNIT_STD_ELLEN_BINTREE_PQUEUE_H
6 #include <cds/container/ellen_bintree_set_hp.h>
7 #include <cds/container/ellen_bintree_set_dhp.h>
8 #include <cds/urcu/general_instant.h>
9 #include <cds/urcu/general_buffered.h>
10 #include <cds/urcu/general_threaded.h>
11 #include <cds/urcu/signal_buffered.h>
12 #include <cds/urcu/signal_threaded.h>
13 #include <cds/container/ellen_bintree_set_rcu.h>
17 template <typename GC>
18 struct EllenBinTreePQueue_pop_max
20 template <typename T, typename Tree>
21 bool operator()( T& dest, Tree& container ) const
23 typename Tree::guarded_ptr gp;
24 bool bRet = container.extract_max( gp );
31 template <typename RCU>
32 struct EllenBinTreePQueue_pop_max< cds::urcu::gc<RCU> >
34 template <typename T, typename Tree>
35 bool operator()( T& dest, Tree& container ) const
37 typename Tree::exempt_ptr ep;
38 bool bRet = container.extract_max( ep );
45 template <typename GC>
46 struct EllenBinTreePQueue_pop_min
48 template <typename T, typename Tree>
49 bool operator()( T& dest, Tree& container ) const
51 typename Tree::guarded_ptr gp;
52 bool bRet = container.extract_min( gp );
59 template <typename RCU>
60 struct EllenBinTreePQueue_pop_min< cds::urcu::gc<RCU> >
62 template <typename T, typename Tree>
63 bool operator()( T& dest, Tree& container ) const
65 typename Tree::exempt_ptr ep;
66 bool bRet = container.extract_min( ep );
73 template <typename GC, typename Key, typename T, typename Traits, bool Max=true>
74 class EllenBinTreePQueue: protected cds::container::EllenBinTreeSet< GC, Key, T, Traits >
76 typedef cds::container::EllenBinTreeSet< GC, Key, T, Traits > base_class;
78 template <typename GC2> friend struct EllenBinTreePQueue_pop_max;
79 template <typename GC2> friend struct EllenBinTreePQueue_pop_min;
82 bool push( value_type const& val )
84 return base_class::insert( val );
87 bool pop( value_type& dest )
89 return Max ? EllenBinTreePQueue_pop_max< typename base_class::gc >()( dest, *this )
90 : EllenBinTreePQueue_pop_min< typename base_class::gc >()( dest, *this );
100 return base_class::empty();
105 return base_class::size();
108 typename base_class::stat const& statistics() const
110 return base_class::statistics();
114 } // namespace pqueue
117 #endif // #ifndef __CDSUNIT_STD_ELLEN_BINTREE_PQUEUE_H