LCOV - code coverage report
Current view: top level - vset/vtree/aspect - ad_upper_node.hpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 23 25 92.0 %
Date: 2019-09-12 Functions: 10 12 83.3 %

          Line data    Source code
       1             : //
       2             : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
       3             : //
       4             : // Copyright: See COPYING file that comes with this distribution
       5             : //
       6             : 
       7             : #ifndef VSET_VTREE_ASPECT_UPPER_NODE_HPP
       8             : #define VSET_VTREE_ASPECT_UPPER_NODE_HPP
       9             : 
      10             : #include <vset/vtree/aspect/tags.hpp>
      11             : 
      12             : namespace vset{ namespace vtree{
      13             : 
      14          29 : struct ad_upper_node
      15             : {
      16             :   template<typename T>
      17             :   typename T::container_type::iterator
      18       27770 :   operator()(T& t, const typename T::key_type& value)
      19             :   {
      20             :     typedef typename T::container_type container_type;
      21             :     typedef typename container_type::iterator container_iterator;
      22       27770 :     container_type& container = t.get_container();
      23             : 
      24       27770 :     container_iterator itr = t.get_aspect().template get<_lower_node_>()(t, value);
      25       83321 :     for ( ; itr!=container.end()
      26       27782 :       && !t.get_aspect().template get<_compare_>()(value, itr->first.first)
      27       27769 :       && !t.get_aspect().template get<_compare_>()(itr->first.first, value)
      28             :       ; ++itr )
      29             :     {
      30             :     }
      31             : 
      32       27770 :     if ( itr != container.end() )
      33             :     {
      34       23790 :       if ( itr != container.begin() && t.get_aspect().template get<_compare_>()(value, itr->first.first) )
      35             :       {
      36          12 :         --itr;
      37             :       }
      38             :     }
      39             :     else
      40             :     {
      41        3980 :       if ( !container.empty() )
      42             :       {
      43        3980 :         itr = (++container.rbegin()).base();
      44             :       }
      45             :     }
      46       27770 :     return  itr;
      47             :   }
      48             : 
      49             :   template<typename T>
      50             :   typename T::container_type::const_iterator
      51           7 :   operator()(const T& t, const typename T::key_type& value) const
      52             :   {
      53             :     typedef typename T::container_type container_type;
      54             :     typedef typename container_type::const_iterator const_container_iterator;
      55           7 :     const container_type& container = t.get_container();
      56             : 
      57           7 :     const_container_iterator itr = t.get_aspect().template get<_lower_node_>()(t, value);
      58          25 :     for ( ; itr != container.cend()
      59          11 :       && !t.get_aspect().template get<_compare_>()(value, itr->first.first)
      60           7 :       && !t.get_aspect().template get<_compare_>()(itr->first.first, value)
      61             :       ; ++itr )
      62             :     {
      63             :     }
      64             : 
      65           7 :     if ( itr != container.cend() )
      66             :     {
      67           7 :       if ( itr != container.cbegin() && t.get_aspect().template get<_compare_>()(value, itr->first.first) )
      68             :       {
      69           3 :         --itr;
      70             :       }
      71             :     }
      72             :     else
      73             :     {
      74           0 :       if ( !container.empty() )
      75             :       {
      76           0 :         itr = (++container.crbegin()).base();
      77             :       }
      78             :     }
      79           7 :     return itr;
      80             :   }
      81             : };
      82             : 
      83             : }}
      84             : 
      85             : #endif

Generated by: LCOV version 1.10