Beispiel #1
0
void	MultiIndex::testFunction()
{
	std::vector<__int64>	kTick;
	const int iLimit( 1000000 );
	MultiIndexContainer kMultiIndexContainer;
	volatile const __int64 d1( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	for( int i( 0 ); i < iLimit; ++i ) {
		kMultiIndexContainer.insert( MultiIndex( boost::lexical_cast<std::string>( i ), i, i * 10 ) );

		volatile int tmp( 0 );
		++tmp;
	}
	volatile const __int64 d2( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		MultiIndexContainer::nth_index<1>::type& IndexString = kMultiIndexContainer.get<1>();
		for( auto pos( IndexString.cbegin() ); pos != IndexString.cend(); ++pos ) {
			volatile const std::string kString( pos->getString() );
			volatile const int iID( pos->getID() );
			volatile const int iGrade( pos->getGrade() );

			volatile int tmp( 0 );
			++tmp;
		}
	}
	volatile const __int64 d3( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		MultiIndexContainer::nth_index<1>::type& IndexString = kMultiIndexContainer.get<1>();
		const auto it( IndexString.find( boost::lexical_cast<std::string>( 100 ) ) );
		volatile const std::string kString( it->getString() );
		volatile const int iID( it->getID() );
		volatile const int iGrade( it->getGrade() );

		volatile int tmp( 0 );
		++tmp;
	}
	volatile const __int64 d4( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );
	{
		for( int i( 0 ); i < 10; ++i ) {
			kMultiIndexContainer.insert( MultiIndex( boost::lexical_cast<std::string>( i ), i, i * 10 ) );
		}
	}
	volatile const __int64 d5( ::GetTickCount() );
	kTick.push_back( ::GetTickCount() );

	volatile const __int64 t1( kTick.at( 1 ) - kTick.at( 0 ) );
	volatile const __int64 t2( kTick.at( 2 ) - kTick.at( 1 ) );
	volatile const __int64 t3( kTick.at( 3 ) - kTick.at( 2 ) );
	volatile const __int64 t4( kTick.at( 4 ) - kTick.at( 3 ) );

	volatile int tmp( 0 );
	++tmp;

	tmp = 1;

	__noop;
}
void test_serialization(const MultiIndexContainer& m)
{
  using namespace boost::multi_index;

  typedef typename MultiIndexContainer::iterator       iterator;
  typedef typename MultiIndexContainer::const_iterator const_iterator;

  std::ostringstream oss;
  {
    boost::archive::text_oarchive oa(oss);
    oa<<m;

    std::vector<const_iterator> its(m.size());
    const_iterator              it_end=m.end();
    for(const_iterator it=m.begin();it!=it_end;++it){
      its.push_back(it);
      oa<<const_cast<const const_iterator&>(its.back());
    }
    oa<<const_cast<const const_iterator&>(it_end);
  }

  MultiIndexContainer m2;
  std::istringstream iss(oss.str());
  boost::archive::text_iarchive ia(iss);
  ia>>m2;
  BOOST_CHECK(all_indices_equal(m,m2));

  iterator it_end=m2.end();
  for(iterator it=m2.begin();it!=it_end;++it){
    iterator it2;
    ia>>it2;
    BOOST_CHECK(it==it2);

    /* exercise safe mode with this (unchecked) iterator */
    BOOST_CHECK(*it==*it2);
    m2.erase(it,it2);
    m2.erase(it2,it2);
    m2.erase(it2,it);
    iterator it3(++it2);
    iterator it4;
    it4=--it2;
    BOOST_CHECK(it==it4);
    BOOST_CHECK(it==project<0>(m2,it4));
  }
  iterator it2;
  ia>>it2;
  BOOST_CHECK(it_end==it2);
  BOOST_CHECK(it_end==project<0>(m2,it2));
}
Beispiel #3
0
void intersect_by( const MultiIndexContainer& L1,const MultiIndexContainer& L2,MultiIndexContainer &s/*result*/, std::string msg="",
			 Tag* =0 /* fixes a MSVC++ 6.0 bug with implicit template function parms */
				  )
	{
	/* obtain a reference to the index tagged by Tag */

	const typename boost::multi_index::index<MultiIndexContainer,Tag>::type& L1_ID_index=
		get<Tag>(L1);
	const typename boost::multi_index::index<MultiIndexContainer,Tag>::type& L2_ID_index=
		get<Tag>(L2);
	typename boost::multi_index::index<MultiIndexContainer,Tag>::type::iterator  L1_ID_index_it;
	typename boost::multi_index::index<MultiIndexContainer,Tag>::type::iterator  L2_ID_index_it;
	//particlesID_set s;
	s.clear();
	std::set_intersection(
		L1_ID_index.begin(), 
		L1_ID_index.end(), 
		L2_ID_index.begin(), 
		L2_ID_index.end(),
		std::inserter(s, s.begin()), strComparator<Tag>()
		);
	//filter_by_ID();
	
	}
Beispiel #4
0
void test_stable_update()
{
  typedef typename MultiIndexContainer::iterator  iterator;
  typedef typename MultiIndexContainer::size_type size_type;

  MultiIndexContainer c;
  c.insert(0);
  c.insert(1);c.insert(1);
  c.insert(2);c.insert(2);c.insert(2);c.insert(2);
  c.insert(3);
  c.insert(4);c.insert(4);c.insert(4);
  c.insert(5);c.insert(5);
  c.insert(6);
  c.insert(7);
  size_type num_elems=
    c.count(0)+c.count(1)+c.count(2)+c.count(3)+
    c.count(4)+c.count(5)+c.count(6)+c.count(7);

  for(size_type n=c.size();n--;){
    iterator it=boost::next(c.begin(),n);

    c.replace(it,*it);
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    c.modify(it,do_nothing(),do_nothing());
    BOOST_TEST((size_type)std::distance(c.begin(),it)==n);

    for(int i=0;i<=8;++i){
      MultiIndexContainer cpy(c);
      bool b=c.modify(it,assign_value(i),assign_value(*it));
      BOOST_TEST(b||(size_type)std::distance(c.begin(),it)==n);
      BOOST_TEST(c.count(0)+c.count(1)+c.count(2)+c.count(3)+c.count(4)+
                  c.count(5)+c.count(6)+c.count(7)+c.count(8)==num_elems);
      if(b){
        c=cpy;
        it=boost::next(c.begin(),n);
      }
    }
  }
}