LCOV - code coverage report
Current view: top level - vset/vtree/aspect - ad_insert_value.hpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 19 22 86.4 %
Date: 2019-09-12 Functions: 13 14 92.9 %

          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_INSERT_VALUE_HPP
       8             : #define VSET_VTREE_ASPECT_INSERT_VALUE_HPP
       9             : 
      10             : #include <vset/vtree/aspect/tags.hpp>
      11             : 
      12             : #include <iostream>
      13             : namespace vset{ namespace vtree{
      14             : 
      15          29 : struct ad_insert_value
      16             : {
      17             :   template<typename T>
      18             :   typename T::iterator
      19       21356 :   operator()(T& t, const typename T::value_type& value)
      20             :   {
      21             :     typedef typename T::container_type container_type;
      22             :     typedef typename container_type::iterator container_iterator;
      23             :     typedef typename T::allocator_type allocator_type;
      24             :     typedef typename allocator_type::value_type array_type;
      25             :     typedef typename array_type::iterator array_iterator;
      26             : 
      27       21356 :     const typename T::key_type& key= t.get_aspect().template get<_get_key_>()(t, value);
      28       21356 :     container_type& container = t.get_container();
      29             :     // находим ближайший подходящий нод
      30       21356 :     container_iterator itr = t.get_aspect().template get<_lower_node_>()(t, key);
      31             : 
      32       21356 :     if ( itr == container.end() )
      33             :     {
      34             :       // Сюда попадем если ни одного нода еще не созданно
      35          28 :       itr = t.get_aspect().template get<_create_node_>()(t, value);
      36             :     }
      37             :     else
      38             :     {
      39             :       // Ищем ближайший свободный но
      40       21328 :       itr = t.get_aspect().template get<_first_proper_node_>()(t, itr);
      41             :     }
      42             : 
      43       21356 :     if ( itr == container.end() )
      44             :     {
      45           0 :       abort();
      46             :     }
      47             : 
      48       21356 :     if ( itr->second->filled() )
      49             :     {
      50          62 :       itr = t.get_aspect().template get<_split_node_>()(t, itr, key);
      51             :     }
      52             : 
      53       21356 :     if ( itr == container.end() )
      54             :     {
      55           0 :       abort();
      56             :     }
      57       21356 :     itr->second->begin();
      58             :     
      59       21356 :     array_iterator aitr = itr->second->insert(value, t.get_aspect().template get<_value_compare_>() );
      60       21356 :     itr = t.get_aspect().template get<_update_node_key_>()(t, itr);
      61       21356 :     if ( itr == container.end() )
      62             :     {
      63           0 :       abort();
      64             :     }
      65       21356 :     itr->second->begin();
      66             :     
      67       21356 :     ++(t.get_aspect().template get<_size_>());
      68             :     
      69       21356 :     return typename T::iterator( itr, std::distance(itr->second->begin(), aitr) );
      70             :   }
      71             : };
      72             :   
      73             : }}
      74             : 
      75             : #endif

Generated by: LCOV version 1.10