File: test_data.h

package info (click to toggle)
libcds 2.3.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,632 kB
  • sloc: cpp: 135,002; ansic: 7,234; perl: 243; sh: 237; makefile: 6
file content (106 lines) | stat: -rw-r--r-- 2,558 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2006-2018 Maxim Khizhinsky
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef CDSUNIT_PQUEUE_TEST_DATA_H
#define CDSUNIT_PQUEUE_TEST_DATA_H

#include <cds_test/fixture.h>
#include <memory>

namespace cds_test {

    class PQueueTest : public ::cds_test::fixture
    {
    public:
        typedef int     key_type;

        struct value_type {
            key_type    k;
            int         v;

            value_type()
            {}

            value_type( value_type const& kv )
                : k( kv.k )
                , v( kv.v )
            {}

            value_type( key_type key )
                : k( key )
                , v( key )
            {}

            value_type( key_type key, int val )
                : k( key )
                , v( val )
            {}

            value_type( std::pair<key_type, int> const& p )
                : k( p.first )
                , v( p.second )
            {}
        };

        struct compare {
            int operator()( value_type k1, value_type k2 ) const
            {
                return k1.k - k2.k;
            }
        };

        struct less {
            bool operator()( value_type k1, value_type k2 ) const
            {
                return k1.k < k2.k;
            }
        };

        enum {
            c_nMinValue = -123,
            c_nCapacity = 1024
        };

    protected:
        template <typename T>
        class data_array
        {
            std::unique_ptr<T[]> pFirst;
            T *     pLast;

        public:
            data_array( size_t nSize )
                : pFirst( new T[nSize] )
                , pLast( pFirst.get() + nSize )
            {
                key_type i = c_nMinValue;
                for ( T * p = pFirst.get(); p != pLast; ++p, ++i )
                    p->k = p->v = i;

                shuffle( pFirst.get(), pLast );
            }

            T * begin() { return pFirst.get(); }
            T * end()   { return pLast; }
            size_t size() const
            {
                return pLast - pFirst;
            }
        };
    };
} // namespace cds_test

namespace std {
    template<>
    struct less<cds_test::PQueueTest::value_type>
    {
        bool operator()( cds_test::PQueueTest::value_type const& v1, cds_test::PQueueTest::value_type const& v2 ) const
        {
            return cds_test::PQueueTest::less()(v1, v2);
        }
    };
}

#endif // CDSUNIT_PQUEUE_FCPQUEUE_H