Exemple #1
0
int main()
{
    typedef std::vector<MyClass>::iterator VectIt;
    typedef std::vector<MyClass>::reverse_iterator VectRit;

    //Create several MyClass objects, each one with a different value
    std::vector<MyClass> values;
    for(int i = 0; i < 100; ++i)  values.push_back(MyClass(i));

    BaseSet baseset;
    MemberMultiset membermultiset;

    //Check that size optimization is activated in the base hook
    assert(sizeof(set_base_hook<optimize_size<true> >) == 3*sizeof(void*));
    //Check that size optimization is deactivated in the member hook
    assert(sizeof(set_member_hook<>) > 3*sizeof(void*));

    //Now insert them in the reverse order in the base hook set
    for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it) {
        baseset.insert(*it);
        membermultiset.insert(*it);
    }

    //Now test sets
    {
        BaseSet::reverse_iterator rbit(baseset.rbegin()), rbitend(baseset.rend());
        MemberMultiset::iterator mit(membermultiset.begin()), mitend(membermultiset.end());
        VectIt it(values.begin()), itend(values.end());

        //Test the objects inserted in the base hook set
        for(; it != itend; ++it, ++rbit)
            if(&*rbit != &*it)   return 1;

        //Test the objects inserted in the member hook set
        for(it = values.begin(); it != itend; ++it, ++mit)
            if(&*mit != &*it) return 1;
    }
    return 0;
}
Exemple #2
0
int main() {
	typedef std::vector<MyClass>::iterator VectIt;
	typedef std::vector<MyClass>::reverse_iterator VectRit;

	BaseSet baseset;
	MemberMultiset membermultiset;

#define N (10*1000*1000)
	std::vector<MyClass> values;
	for(int i = 0; i < N; ++i)  values.push_back(MyClass(i));

	//Check that size optimization is activated in the base hook 
	assert(sizeof(avl_set_base_hook<optimize_size<true> >) == 3*sizeof(void*));
	//Check that size optimization is deactivated in the member hook 
	assert(sizeof(avl_set_member_hook<>) > 3*sizeof(void*));

	for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
		baseset.insert(*it);
//		membermultiset.insert(*it);
	}

	return 0;
}
int main()
{
   typedef std::vector<MyClass>::iterator VectIt;
   typedef std::vector<MyClass>::reverse_iterator VectRit;

   //Create several MyClass objects, each one with a different value
   std::vector<MyClass> values;
   for(int i = 0; i < 100; ++i)  values.push_back(MyClass(i));

   BaseSet baseset;
   MemberMultiset membermultiset;
   
   //Now insert them in the reverse order in the base hook sg_set
   for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
      baseset.insert(*it);
      membermultiset.insert(*it);
   }

   //Change balance factor
   membermultiset.balance_factor(0.9f);

   //Now test sg_sets
   {
      BaseSet::reverse_iterator rbit(baseset.rbegin()), rbitend(baseset.rend());
      MemberMultiset::iterator mit(membermultiset.begin()), mitend(membermultiset.end());
      VectIt it(values.begin()), itend(values.end());

      //Test the objects inserted in the base hook sg_set
      for(; it != itend; ++it, ++rbit)
         if(&*rbit != &*it)   return 1;

      //Test the objects inserted in the member hook sg_set
      for(it = values.begin(); it != itend; ++it, ++mit)
         if(&*mit != &*it) return 1;
   }
   return 0;
}
int main()
{
   typedef std::vector<MyClass>::iterator VectIt;

   //Create several MyClass objects, each one with a different value
   std::vector<MyClass> values;
   for(int i = 0; i < 100; ++i)  values.push_back(MyClass(i, (i % 10)));

   BaseSet baseset;
   MemberMultiset membermultiset;
   
   //Now insert them in the sets
   for(VectIt it(values.begin()), itend(values.end()); it != itend; ++it){
      baseset.insert(*it);
      membermultiset.insert(*it);
   }

   //Now test treap_sets
   {
      BaseSet::reverse_iterator rbit(baseset.rbegin()), rbitend(baseset.rend());
      MemberMultiset::iterator mit(membermultiset.begin()), mitend(membermultiset.end());
      VectIt it(values.begin()), itend(values.end());

      //Test the objects inserted in the base hook treap_set
      for(; it != itend; ++it, ++rbit)
         if(&*rbit != &*it)   return 1;

      //Test the objects inserted in the member hook treap_set
      for(it = values.begin(); it != itend; ++it, ++mit)
         if(&*mit != &*it) return 1;

      //Test priority order
      for(int i = 0; i < 100; ++i){
         if(baseset.top()->get_priority() != static_cast<unsigned int>(i/10))
            return 1;
         if(membermultiset.top()->get_priority() != 9u - static_cast<unsigned int>(i/10))
            return 1;
         baseset.erase(baseset.top());
         membermultiset.erase(membermultiset.top());
      }
   }
   return 0;
}