diff --git a/test/unordered_test.hpp b/test/unordered_test.hpp index 64d8bdf..29bd705 100644 --- a/test/unordered_test.hpp +++ b/test/unordered_test.hpp @@ -51,11 +51,11 @@ void test_unordered::test_all (value_cont_type& values) typedef typename ContainerDefiner::template container <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; { typename unordered_type::bucket_type buckets [BucketSize]; unordered_type testset - (bucket_traits(pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + (bucket_traits(pointer_traits::pointer_to(buckets[0]), BucketSize)); testset.insert(values.begin(), values.end()); test::test_container(testset); testset.clear(); @@ -76,8 +76,7 @@ void test_unordered::test_all (value_cont_type& values) (&vals[i])->value_ = i; typename unordered_type::bucket_type buckets [BucketSize]; unordered_type testset(bucket_traits( - pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + pointer_traits::pointer_to(buckets[0]), BucketSize)); testset.insert(vals.begin(), vals.end()); test::test_iterator_forward(testset); } @@ -97,6 +96,7 @@ void test_unordered::test_impl() typedef typename ContainerDefiner::template container <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; value_cont_type values (5); for (int i = 0; i < 5; ++i) @@ -104,8 +104,7 @@ void test_unordered::test_impl() typename unordered_type::bucket_type buckets [BucketSize]; unordered_type testset(bucket_traits( - pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + pointer_traits::pointer_to(buckets[0]), BucketSize)); for (int i = 0; i < 5; ++i) testset.insert (values[i]); @@ -125,12 +124,12 @@ void test_unordered::test_sort(value_cont_type& values) typedef typename ContainerDefiner::template container <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; typename unordered_type::bucket_type buckets [BucketSize]; unordered_type testset1 (values.begin(), values.end(), bucket_traits - (pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + (pointer_traits::pointer_to(buckets[0]), BucketSize)); if(unordered_type::incremental){ { int init_values [] = { 4, 5, 1, 2, 2, 3 }; @@ -209,13 +208,13 @@ void test_unordered::test_insert(value_cont_type& values, deta <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; typedef typename unordered_type::iterator iterator; typedef typename unordered_type::key_type key_type; { typename unordered_type::bucket_type buckets [BucketSize]; unordered_type testset(bucket_traits( - pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + pointer_traits::pointer_to(buckets[0]), BucketSize)); testset.insert(&values[0] + 2, &values[0] + 5); @@ -254,8 +253,7 @@ void test_unordered::test_insert(value_cont_type& values, deta //Now with a single bucket typename unordered_type::bucket_type single_bucket[1]; unordered_type testset2(bucket_traits( - pointer_traits:: - pointer_to(single_bucket[0]), 1)); + pointer_traits::pointer_to(single_bucket[0]), 1)); testset2.insert(&values[0], &values[0] + values.size()); BOOST_TEST (testset2.erase(key_type(5)) == 1); BOOST_TEST (testset2.erase(key_type(2)) == 2); @@ -298,8 +296,7 @@ void test_unordered::test_insert(value_cont_type& values, deta //Now with a single bucket typename unordered_type::bucket_type single_bucket[1]; unordered_type testset2(bucket_traits( - pointer_traits:: - pointer_to(single_bucket[0]), 1)); + pointer_traits::pointer_to(single_bucket[0]), 1)); testset2.insert(&values[0], &values[0] + values.size()); BOOST_TEST (testset2.erase(key_type(5)) == 1); BOOST_TEST (testset2.erase(key_type(2)) == 2); @@ -319,8 +316,7 @@ void test_unordered::test_insert(value_cont_type& values, deta for (unsigned int j = 0; j < random_size; ++j) data[j].value_ = random_init[j]; unordered_type testset_new(bucket_traits( - pointer_traits:: - pointer_to(single_bucket[0]), 1)); + pointer_traits::pointer_to(single_bucket[0]), 1)); testset_new.insert(&data[0], &data[0]+max); testset_new.erase(testset_new.iterator_to(data[i])); BOOST_TEST (testset_new.size() == (max -1)); @@ -328,10 +324,8 @@ void test_unordered::test_insert(value_cont_type& values, deta } } { - typename unordered_type::bucket_type buckets [BucketSize]; - const unsigned int NumBucketSize = BucketSize; const unsigned int LoadFactor = 3; - const unsigned int NumIterations = NumBucketSize*LoadFactor; + const unsigned int NumIterations = BucketSize*LoadFactor; value_cont_type random_init(NumIterations);//Preserve memory value_cont_type set_tester; set_tester.reserve(NumIterations); @@ -341,15 +335,17 @@ void test_unordered::test_insert(value_cont_type& values, deta random_init[i].value_ = i*2;//(i/LoadFactor)*LoadFactor; } + typename unordered_type::bucket_type buckets [BucketSize]; + bucket_traits btraits(pointer_traits::pointer_to(buckets[0]), BucketSize); + for(unsigned int initial_pos = 0; initial_pos != (NumIterations+1); ++initial_pos){ for(unsigned int final_pos = initial_pos; final_pos != (NumIterations+1); ++final_pos){ //Create intrusive container inserting values unordered_type testset - ( &random_init[0] - , &random_init[0] + random_init.size() - , bucket_traits(pointer_traits:: - pointer_to(buckets[0]), NumBucketSize)); + ( random_init.data() + , random_init.data() + random_init.size() + , btraits); BOOST_TEST (testset.size() == random_init.size()); @@ -401,15 +397,14 @@ void test_unordered::test_swap(value_cont_type& values) <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; typename unordered_type::bucket_type buckets [BucketSize]; typename unordered_type::bucket_type buckets2 [BucketSize]; unordered_type testset1(&values[0], &values[0] + 2, - bucket_traits(pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + bucket_traits(pointer_traits::pointer_to(buckets[0]), BucketSize)); unordered_type testset2(bucket_traits( - pointer_traits:: - pointer_to(buckets2[0]), BucketSize)); + pointer_traits::pointer_to(buckets2[0]), BucketSize)); testset2.insert (&values[0] + 2, &values[0] + 6); testset1.swap (testset2); @@ -449,11 +444,12 @@ void test_unordered::test_rehash(value_cont_type& values, deta <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; //Build a uset typename unordered_type::bucket_type buckets1 [BucketSize]; typename unordered_type::bucket_type buckets2 [BucketSize*2]; unordered_type testset1(&values[0], &values[0] + values.size(), - bucket_traits(pointer_traits:: + bucket_traits(pointer_traits:: pointer_to(buckets1[0]), BucketSize)); //Test current state BOOST_TEST(testset1.split_count() == BucketSize/2); @@ -482,7 +478,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta // //This incremental rehash should fail because the new size is not twice the original BOOST_TEST(testset1.incremental_rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), BucketSize)) == false); BOOST_TEST(testset1.split_count() == BucketSize); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; @@ -493,7 +489,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta // //This incremental rehash should fail because the new size is not twice the original BOOST_TEST(testset1.incremental_rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets2[0]), BucketSize)) == false); BOOST_TEST(testset1.split_count() == BucketSize); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; @@ -502,7 +498,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta //This incremental rehash should success because the new size is twice the original //and split_count is the same as the old bucket count BOOST_TEST(testset1.incremental_rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets2[0]), BucketSize*2)) == true); BOOST_TEST(testset1.split_count() == BucketSize); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; @@ -511,7 +507,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta //This incremental rehash should also success because the new size is half the original //and split_count is the same as the new bucket count BOOST_TEST(testset1.incremental_rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), BucketSize)) == true); BOOST_TEST(testset1.split_count() == BucketSize); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; @@ -519,7 +515,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta //Shrink rehash testset1.rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), 4)); BOOST_TEST (testset1.incremental_rehash() == false); { int init_values [] = { 4, 5, 1, 2, 2, 3 }; @@ -527,7 +523,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta //Shrink rehash again testset1.rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), 2)); BOOST_TEST (testset1.incremental_rehash() == false); { int init_values [] = { 2, 2, 4, 3, 5, 1 }; @@ -535,7 +531,7 @@ void test_unordered::test_rehash(value_cont_type& values, deta //Growing rehash testset1.rehash(bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), BucketSize)); //Full rehash (no effects) @@ -577,40 +573,37 @@ void test_unordered::test_rehash(value_cont_type& values, deta <>::type unordered_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; typename unordered_type::bucket_type buckets1 [BucketSize]; typename unordered_type::bucket_type buckets2 [2]; typename unordered_type::bucket_type buckets3 [BucketSize*2]; unordered_type testset1(&values[0], &values[0] + 6, bucket_traits( - pointer_traits:: + pointer_traits:: pointer_to(buckets1[0]), BucketSize)); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE( init_values, testset1 ); } testset1.rehash(bucket_traits( - pointer_traits:: - pointer_to(buckets2[0]), 2)); + pointer_traits::pointer_to(buckets2[0]), 2)); { int init_values [] = { 4, 2, 2, 5, 3, 1 }; TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE( init_values, testset1 ); } testset1.rehash(bucket_traits( - pointer_traits:: - pointer_to(buckets3[0]), BucketSize*2)); + pointer_traits::pointer_to(buckets3[0]), BucketSize*2)); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE( init_values, testset1 ); } //Now rehash reducing the buckets testset1.rehash(bucket_traits( - pointer_traits:: - pointer_to(buckets3[0]), 2)); + pointer_traits::pointer_to(buckets3[0]), 2)); { int init_values [] = { 4, 2, 2, 5, 3, 1 }; TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE( init_values, testset1 ); } //Now rehash increasing the buckets testset1.rehash(bucket_traits( - pointer_traits:: - pointer_to(buckets3[0]), BucketSize*2)); + pointer_traits::pointer_to(buckets3[0]), BucketSize*2)); { int init_values [] = { 1, 2, 2, 3, 4, 5 }; TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE( init_values, testset1 ); } @@ -629,13 +622,13 @@ void test_unordered::test_find(value_cont_type& values) typedef typename unordered_type::value_type value_type; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; typedef typename unordered_type::key_of_value key_of_value; const bool is_multikey = boost::intrusive::test::is_multikey_true::value; typename unordered_type::bucket_type buckets[BucketSize]; unordered_type testset(values.begin(), values.end(), bucket_traits( - pointer_traits:: - pointer_to(buckets[0]), BucketSize)); + pointer_traits::pointer_to(buckets[0]), BucketSize)); typedef typename unordered_type::iterator iterator; @@ -668,16 +661,16 @@ void test_unordered::test_clone(value_cont_type& values) typedef std::multiset std_multiset_t; typedef typename unordered_type::bucket_traits bucket_traits; + typedef typename unordered_type::bucket_ptr bucket_ptr; + { //Test with equal bucket arrays typename unordered_type::bucket_type buckets1 [BucketSize]; typename unordered_type::bucket_type buckets2 [BucketSize]; unordered_type testset1 (values.begin(), values.end(), bucket_traits( - pointer_traits:: - pointer_to(buckets1[0]), BucketSize)); + pointer_traits::pointer_to(buckets1[0]), BucketSize)); unordered_type testset2 (bucket_traits( - pointer_traits:: - pointer_to(buckets2[0]), BucketSize)); + pointer_traits::pointer_to(buckets2[0]), BucketSize)); testset2.clone_from(testset1, test::new_cloner(), test::delete_disposer()); BOOST_TEST(testset1 == testset2); @@ -702,11 +695,9 @@ void test_unordered::test_clone(value_cont_type& values) typename unordered_type::bucket_type buckets1 [BucketSize*2]; typename unordered_type::bucket_type buckets2 [BucketSize]; unordered_type testset1 (values.begin(), values.end(), bucket_traits( - pointer_traits:: - pointer_to(buckets1[0]), BucketSize*2)); + pointer_traits::pointer_to(buckets1[0]), BucketSize*2)); unordered_type testset2 (bucket_traits( - pointer_traits:: - pointer_to(buckets2[0]), BucketSize)); + pointer_traits::pointer_to(buckets2[0]), BucketSize)); testset2.clone_from(testset1, test::new_cloner(), test::delete_disposer()); BOOST_TEST(testset1 == testset2); @@ -731,11 +722,9 @@ void test_unordered::test_clone(value_cont_type& values) typename unordered_type::bucket_type buckets1 [BucketSize]; typename unordered_type::bucket_type buckets2 [BucketSize*2]; unordered_type testset1 (values.begin(), values.end(), bucket_traits( - pointer_traits:: - pointer_to(buckets1[0]), BucketSize)); + pointer_traits::pointer_to(buckets1[0]), BucketSize)); unordered_type testset2 (bucket_traits( - pointer_traits:: - pointer_to(buckets2[0]), BucketSize*2)); + pointer_traits::pointer_to(buckets2[0]), BucketSize*2)); testset2.clone_from(testset1, test::new_cloner(), test::delete_disposer()); BOOST_TEST(testset1 == testset2);