///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2014-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include "itestvalue.hpp" using namespace boost::intrusive; BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator) template struct boolean { static const bool value = Value; }; template struct pow2_and_equal_sizes { static const std::size_t a_size = sizeof(A); static const std::size_t b_size = sizeof(B); static const bool a_b_sizes_equal = a_size == b_size; static const bool value = !(a_size & (a_size - 1u)); }; template struct node : Hook {}; //Avoid testing for uncommon architectures void test_sizes(boolean, std::size_t) {} template void test_iterator_sizes(std::size_t size) { typedef typename C::iterator iterator; typedef typename C::const_iterator const_iterator; typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT (::, C, reverse_iterator, iterator) reverse_iterator; typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT (::, C, const_reverse_iterator, const_iterator) const_reverse_iterator; BOOST_TEST_EQ(sizeof(iterator), size); BOOST_TEST_EQ(sizeof(const_iterator), size); BOOST_TEST_EQ(sizeof(iterator), sizeof(reverse_iterator)); BOOST_TEST_EQ(sizeof(const_iterator), size); BOOST_TEST_EQ(sizeof(const_iterator), sizeof(const_reverse_iterator)); } //Test sizes for common 32 and 64 bit architectures void test_sizes(boolean, std::size_t wordsize) { { //list typedef list > > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { typedef list >, constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize); } { typedef list< node< list_base_hook<> >, header_holder_type< heap_node_holder< list_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize); } { typedef list< node< list_base_hook<> >, constant_time_size, header_holder_type< heap_node_holder< list_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*1); test_iterator_sizes(wordsize); } { //slist typedef slist > > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize); } { typedef slist >, constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*1); test_iterator_sizes(wordsize); } { typedef slist >, cache_last > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { //set typedef set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*5); test_iterator_sizes(wordsize); } { typedef set > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize); } { typedef set > > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { typedef set< node< set_base_hook<> >, header_holder_type< heap_node_holder< rbtree_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize); } { typedef set< node< set_base_hook<> >, constant_time_size, header_holder_type< heap_node_holder< rbtree_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*1); test_iterator_sizes(wordsize); } { //avl typedef avl_set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*5); test_iterator_sizes(wordsize); } { typedef avl_set > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize); } { typedef avl_set > > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { typedef avl_set< node< avl_set_base_hook<> >, header_holder_type< heap_node_holder< avltree_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize); } { typedef avl_set< node< avl_set_base_hook<> >, constant_time_size, header_holder_type< heap_node_holder< avltree_node* > > > c; BOOST_TEST_EQ(sizeof(c), wordsize*1); test_iterator_sizes(wordsize); } { //bs typedef bs_set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize); } { typedef bs_set > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { //splay typedef splay_set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize); } { typedef splay_set > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { //scapegoat typedef sg_set > > c; BOOST_TEST_EQ(sizeof(c), (wordsize*5+sizeof(float)*2)); test_iterator_sizes(wordsize); } { //treap typedef treap_set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize); } { typedef treap_set > , constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize); } { //unordered typedef unordered_set > > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize*2); } { typedef unordered_set > , power_2_buckets > c; BOOST_TEST_EQ(sizeof(c), wordsize*3); test_iterator_sizes(wordsize*2); } { typedef unordered_set >, constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize*2); } { typedef unordered_set > >, constant_time_size > c; BOOST_TEST_EQ(sizeof(c), wordsize*2); test_iterator_sizes(wordsize*2); } { typedef unordered_set > >, incremental > c; BOOST_TEST_EQ(sizeof(c), wordsize*4); test_iterator_sizes(wordsize*2); } } int main() { test_sizes(boolean< pow2_and_equal_sizes::value >(), sizeof(std::size_t)); return ::boost::report_errors(); }