Divide too big to maintain (flat_)tree into (flat_)map and (flat_)set tests.

This commit is contained in:
Ion Gaztañaga
2026-01-11 01:45:18 +01:00
parent 8c7e4a4fba
commit e760874846
4 changed files with 234 additions and 135 deletions

117
test/flat_map_test.cpp Normal file
View File

@@ -0,0 +1,117 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2004-2026. 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/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <map>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include "print_container.hpp"
#include "movable_int.hpp"
#include "map_test.hpp"
#include "emplace_test.hpp"
/////////////////////////////////////////////////////////////////
//
// This example repeats the same operations with std::map and
// shmem_map using the node allocator
// and compares the values of both containers
//
/////////////////////////////////////////////////////////////////
using namespace boost::interprocess;
//Customize managed_shared_memory class
typedef basic_managed_shared_memory
<char,
//simple_seq_fit<mutex_family>,
rbtree_best_fit<mutex_family>,
iset_index
> my_managed_shared_memory;
//Alias allocator type
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
shmem_pair_allocator_t;
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
shmem_movable_pair_allocator_t;
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
shmem_move_copy_pair_allocator_t;
//Alias map types
typedef std::map<int, int> MyStdMap;
typedef std::multimap<int, int> MyStdMultiMap;
typedef boost::container::flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
typedef boost::container::flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
typedef boost::container::flat_map<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMap;
typedef boost::container::flat_multimap<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
typedef boost::container::flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
typedef boost::container::flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
int main()
{
using namespace boost::interprocess::test;
if (0 != map_test<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyShmMap>" << std::endl;
return 1;
}
if (0 != map_test_copyable<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyShmMap>" << std::endl;
return 1;
}
// if (0 != map_test<my_managed_shared_memory
// ,MyMovableShmMap
// ,MyStdMap
// ,MyMovableShmMultiMap
// ,MyStdMultiMap>()){
// return 1;
// }
if (0 != map_test<my_managed_shared_memory
,MyMoveCopyShmMap
,MyStdMap
,MyMoveCopyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
return 1;
}
//#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
if(!boost::interprocess::test::test_emplace<boost::container::flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
//#endif //!defined(__GNUC__)
return 0;
}

View File

@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
// (C) Copyright Ion Gaztanaga 2004-2026. 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)
//
@@ -11,14 +11,10 @@
#include <set>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/indexes/flat_map_index.hpp>
#include "print_container.hpp"
#include "dummy_test_allocator.hpp"
#include "movable_int.hpp"
#include "set_test.hpp"
#include "map_test.hpp"
#include "emplace_test.hpp"
/////////////////////////////////////////////////////////////////
@@ -44,10 +40,6 @@ typedef allocator<int, my_managed_shared_memory::segment_manager>
shmem_allocator_t;
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
shmem_movable_allocator_t;
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
shmem_pair_allocator_t;
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
shmem_movable_pair_allocator_t;
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
shmem_move_copy_allocator_t;
@@ -55,30 +47,17 @@ typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segm
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
shmem_copy_allocator_t;
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
shmem_move_copy_pair_allocator_t;
//Alias set types
typedef std::set<int> MyStdSet;
typedef std::multiset<int> MyStdMultiSet;
typedef std::map<int, int> MyStdMap;
typedef std::multimap<int, int> MyStdMultiMap;
typedef boost::container::flat_set<int, std::less<int>, shmem_allocator_t> MyShmSet;
typedef boost::container::flat_multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
typedef boost::container::flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
typedef boost::container::flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
typedef boost::container::flat_set<test::movable_int, std::less<test::movable_int>
,shmem_movable_allocator_t> MyMovableShmSet;
typedef boost::container::flat_multiset<test::movable_int,std::less<test::movable_int>
,shmem_movable_allocator_t> MyMovableShmMultiSet;
typedef boost::container::flat_map<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMap;
typedef boost::container::flat_multimap<test::movable_int, test::movable_int
,std::less<test::movable_int>
,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
typedef boost::container::flat_set<test::movable_and_copyable_int, std::less<test::movable_and_copyable_int>
,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
@@ -90,13 +69,6 @@ typedef boost::container::flat_set<test::copyable_int, std::less<test::copyable_
typedef boost::container::flat_multiset<test::copyable_int,std::less<test::copyable_int>
,shmem_copy_allocator_t> MyCopyShmMultiSet;
typedef boost::container::flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
typedef boost::container::flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
int main()
{
using namespace boost::interprocess::test;
@@ -146,49 +118,9 @@ int main()
return 1;
}
if (0 != map_test<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyShmMap>" << std::endl;
return 1;
}
if (0 != map_test_copyable<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyShmMap>" << std::endl;
return 1;
}
// if (0 != map_test<my_managed_shared_memory
// ,MyMovableShmMap
// ,MyStdMap
// ,MyMovableShmMultiMap
// ,MyStdMultiMap>()){
// return 1;
// }
if (0 != map_test<my_managed_shared_memory
,MyMoveCopyShmMap
,MyStdMap
,MyMoveCopyShmMultiMap
,MyStdMultiMap>()){
std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
return 1;
}
//#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
if(!boost::interprocess::test::test_emplace<boost::container::flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::flat_set<test::EmplaceInt>, SetOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::flat_multiset<test::EmplaceInt>, SetOptions>())

116
test/map_test.cpp Normal file
View File

@@ -0,0 +1,116 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2004-2012. 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/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <map>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/container/map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/indexes/map_index.hpp>
#include <boost/interprocess/indexes/iset_index.hpp>
#include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
#include "print_container.hpp"
#include "movable_int.hpp"
#include "map_test.hpp"
#include "emplace_test.hpp"
///////////////////////////////////////////////////////////////////
// //
// This example repeats the same operations with std::map and //
// shmem_map using the node allocator //
// and compares the values of both containers //
// //
///////////////////////////////////////////////////////////////////
using namespace boost::interprocess;
//Customize managed_shared_memory class
typedef basic_managed_shared_memory
<char,
simple_seq_fit<mutex_family, offset_ptr<void> >,
map_index
> my_managed_shared_memory;
//We will work with narrow characters for shared memory objects
//Alias an integer node allocator type
typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
shmem_node_pair_allocator_t;
typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
shmem_movable_node_pair_allocator_t;
typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
shmem_move_copy_node_pair_allocator_t;
//Alias standard types
typedef std::map<int, int> MyStdMap;
typedef std::multimap<int, int> MyStdMultiMap;
//Alias non-movable types
typedef boost::container::map<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMap;
typedef boost::container::multimap<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMultiMap;
//Alias movable types
typedef boost::container::map<test::movable_int, test::movable_int,
std::less<test::movable_int>,
shmem_movable_node_pair_allocator_t> MyMovableShmMap;
typedef boost::container::multimap<test::movable_int, test::movable_int,
std::less<test::movable_int>,
shmem_movable_node_pair_allocator_t> MyMovableShmMultiMap;
typedef boost::container::map<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMap;
typedef boost::container::multimap<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMultiMap;
int main ()
{
using namespace boost::interprocess::ipcdetail;
if (0 != test::map_test<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
if(0 != test::map_test_copyable<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
// if (0 != test::map_test<my_managed_shared_memory
// ,MyMovableShmMap
// ,MyStdMap
// ,MyMovableShmMultiMap
// ,MyStdMultiMap>()){
// return 1;
// }
if (0 != test::map_test<my_managed_shared_memory
,MyMoveCopyShmMap
,MyStdMap
,MyMoveCopyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
if(!boost::interprocess::test::test_emplace<boost::container::map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
return 0;
}

View File

@@ -10,16 +10,13 @@
#include <set>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/container/set.hpp>
#include <boost/container/map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/indexes/map_index.hpp>
#include <boost/interprocess/indexes/iset_index.hpp>
#include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
#include "print_container.hpp"
#include "movable_int.hpp"
#include "dummy_test_allocator.hpp"
#include "set_test.hpp"
#include "map_test.hpp"
#include "emplace_test.hpp"
///////////////////////////////////////////////////////////////////
@@ -43,30 +40,20 @@ typedef basic_managed_shared_memory
//Alias an integer node allocator type
typedef allocator<int, my_managed_shared_memory::segment_manager>
shmem_allocator_t;
typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
shmem_node_pair_allocator_t;
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
shmem_movable_allocator_t;
typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
shmem_movable_node_pair_allocator_t;
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
shmem_move_copy_allocator_t;
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
shmem_copy_allocator_t;
typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
shmem_move_copy_node_pair_allocator_t;
//Alias standard types
typedef std::set<int> MyStdSet;
typedef std::multiset<int> MyStdMultiSet;
typedef std::map<int, int> MyStdMap;
typedef std::multimap<int, int> MyStdMultiMap;
//Alias non-movable types
typedef boost::container::set<int, std::less<int>, shmem_allocator_t> MyShmSet;
typedef boost::container::multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
typedef boost::container::map<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMap;
typedef boost::container::multimap<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMultiMap;
//Alias movable types
typedef boost::container::set<test::movable_int, std::less<test::movable_int>
@@ -74,12 +61,6 @@ typedef boost::container::set<test::movable_int, std::less<test::movable_int>
typedef boost::container::multiset<test::movable_int,
std::less<test::movable_int>,
shmem_movable_allocator_t> MyMovableShmMultiSet;
typedef boost::container::map<test::movable_int, test::movable_int,
std::less<test::movable_int>,
shmem_movable_node_pair_allocator_t> MyMovableShmMap;
typedef boost::container::multimap<test::movable_int, test::movable_int,
std::less<test::movable_int>,
shmem_movable_node_pair_allocator_t> MyMovableShmMultiMap;
typedef boost::container::set<test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
@@ -95,16 +76,6 @@ typedef boost::container::multiset<test::copyable_int,
std::less<test::copyable_int>,
shmem_copy_allocator_t> MyCopyShmMultiSet;
typedef boost::container::map<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMap;
typedef boost::container::multimap<test::movable_and_copyable_int
,test::movable_and_copyable_int
,std::less<test::movable_and_copyable_int>
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMultiMap;
int main ()
{
using namespace boost::interprocess::ipcdetail;
@@ -149,48 +120,11 @@ int main ()
return 1;
}
if (0 != test::map_test<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
if(0 != test::map_test_copyable<my_managed_shared_memory
,MyShmMap
,MyStdMap
,MyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
// if (0 != test::map_test<my_managed_shared_memory
// ,MyMovableShmMap
// ,MyStdMap
// ,MyMovableShmMultiMap
// ,MyStdMultiMap>()){
// return 1;
// }
if (0 != test::map_test<my_managed_shared_memory
,MyMoveCopyShmMap
,MyStdMap
,MyMoveCopyShmMultiMap
,MyStdMultiMap>()){
return 1;
}
const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
if(!boost::interprocess::test::test_emplace<boost::container::set<test::EmplaceInt>, SetOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::multiset<test::EmplaceInt>, SetOptions>())
return 1;
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
if(!boost::interprocess::test::test_emplace<boost::container::map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
if(!boost::interprocess::test::test_emplace<boost::container::multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
return 1;
return 0;
}