Line data Source code
1 : //
2 : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #include <fas/testing.hpp>
8 : #include <vset/memory/manager.hpp>
9 : #include <vset/allocators/allocator.hpp>
10 : #include <vset/comparators/offset_compare.hpp>
11 : #include <vset/comparators/compare_list.hpp>
12 : #include <vset/comparators/compare_member.hpp>
13 : #include <vset/multiset.hpp>
14 : #include "multiset_test_impl.hpp"
15 :
16 :
17 3 : UNIT(multiset_mmap_cmp, "")
18 : {
19 : using namespace fas::testing;
20 1 : t << flush;
21 1 : t << is_true<assert>( multiset_test() ) << FAS_FL;
22 1 : }
23 :
24 : struct item
25 : {
26 : int item1;
27 : int item2;
28 64 : item(): item1(0), item2(){}
29 18 : item(int i1, int i2): item1(i1), item2(i2){}
30 : };
31 :
32 : typedef vset::compare_list< fas::type_list_n<
33 : vset::compare_member<item, int, &item::item1>,
34 : vset::compare_member<item, int, &item::item2, std::greater<int> >
35 : >::type
36 : > item_cmp;
37 2 : struct item_cmp_t: item_cmp{};
38 :
39 : #ifdef NDEBUG
40 : #define TEST_COUNT 50
41 : #else
42 : #define TEST_COUNT 3
43 : #endif
44 :
45 : typedef size_t offset_t;
46 : typedef vset::memory::manager< ::vset::memory::strategy::fsb_inmem<item, ::vset::memory::fsb::aspect_offset> > int_data;
47 : struct int_data_t: int_data{};
48 : typedef vset::offset_compare< offset_t, int_data_t, item_cmp_t > offset_greater;
49 : typedef vset::multiset< offset_t, offset_greater, vset::allocator<2> > int_index;
50 :
51 3 : UNIT(multiset_mmap_lu, "")
52 : {
53 : using namespace fas::testing;
54 1 : t << nothing;
55 :
56 1 : int_data data;
57 2 : int_index index( offset_greater( data.end() ) );
58 1 : int_data::pointer val = data.allocate(1);
59 4 : for (int i = 0; i < TEST_COUNT; ++i)
60 12 : for (int j = 0; j < TEST_COUNT; ++j)
61 : {
62 9 : int_data::pointer ins = data.allocate(1);
63 9 : *ins = item(i, -j);
64 9 : index.insert( ins.get_offset() );
65 : }
66 :
67 1 : int_data::pointer ptr = data.end();
68 4 : for (int i = 0; i < TEST_COUNT; ++i)
69 12 : for (int j = 0; j < TEST_COUNT; ++j)
70 : {
71 9 : *val = item(i, -j);
72 :
73 9 : int_index::iterator lower = index.lower_bound( val.get_offset() );
74 9 : int_index::iterator upper = index.upper_bound( val.get_offset() );
75 9 : t << equal<expect, size_t>( std::distance(lower, upper), 1 ) << FAS_FL;
76 9 : --upper;
77 9 : ptr.set_offset(*lower);
78 9 : item a = *ptr;
79 9 : ptr.set_offset(*upper);
80 9 : item b = *ptr;
81 9 : t << equal<expect>(a.item1, b.item1) << FAS_FL;
82 9 : t << equal<expect>(a.item2, b.item2) << FAS_FL;
83 1 : }
84 :
85 : /*
86 : int_index::iterator beg = index.begin();
87 : for ( ; beg != index.end(); ++beg)
88 : {
89 : ptr.set_offset(*beg);
90 : item a = *ptr;
91 : t << message("a= ") << a.item1 << ", " << a.item2;
92 : }*/
93 1 : }
94 :
95 1 : BEGIN_SUITE(multiset_mmap_cmp_suite, "")
96 : ADD_UNIT(multiset_mmap_cmp)
97 : ADD_UNIT(multiset_mmap_lu)
98 7 : END_SUITE(multiset_mmap_cmp_suite)
|