| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
// Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the terms |
| 7 |
// of the GNU General Public License as published by the Free Software |
| 8 |
// Foundation; either version 3, or (at your option) any later |
| 9 |
// version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, but |
| 12 |
// WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
// General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License |
| 17 |
// along with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
|
| 21 |
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. |
| 22 |
|
| 23 |
// Permission to use, copy, modify, sell, and distribute this software |
| 24 |
// is hereby granted without fee, provided that the above copyright |
| 25 |
// notice appears in all copies, and that both that copyright notice |
| 26 |
// and this permission notice appear in supporting documentation. None |
| 27 |
// of the above authors, nor IBM Haifa Research Laboratories, make any |
| 28 |
// representation about the suitability of this software for any |
| 29 |
// purpose. It is provided "as is" without express or implied |
| 30 |
// warranty. |
| 31 |
|
| 32 |
/** |
| 33 |
* @file common_type.hpp |
| 34 |
* Contains types used for regression tests. |
| 35 |
*/ |
| 36 |
|
| 37 |
#ifndef PB_DS_RAND_REGRESSION_TEST_COMMON_TYPE_HPP |
| 38 |
#define PB_DS_RAND_REGRESSION_TEST_COMMON_TYPE_HPP |
| 39 |
|
| 40 |
#include <vector> |
| 41 |
#include <regression/basic_type.hpp> |
| 42 |
#include <common_type/assoc/common_type.hpp> |
| 43 |
#include <common_type/priority_queue/common_type.hpp> |
| 44 |
|
| 45 |
namespace __gnu_pbds |
| 46 |
{ |
| 47 |
namespace test |
| 48 |
{ |
| 49 |
typedef __gnu_cxx::throw_allocator_random<basic_type> alloc_type; |
| 50 |
|
| 51 |
struct hash |
| 52 |
{ |
| 53 |
typedef alloc_type::rebind<basic_type>::other basic_type_rebind; |
| 54 |
typedef basic_type_rebind::const_reference const_reference; |
| 55 |
typedef basic_type::const_iterator const_iterator; |
| 56 |
|
| 57 |
size_t |
| 58 |
operator()(const_reference r_key) const |
| 59 |
{ |
| 60 |
size_t ret = 0; |
| 61 |
for (const_iterator it = r_key.begin(); it != r_key.end(); ++it) |
| 62 |
ret = ret * 5 + static_cast<size_t>(*it); |
| 63 |
return ret; |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
typedef __gnu_pbds::trie_string_access_traits<basic_type, 'a', 'a' + basic_type::distinct_chars - 1, false, alloc_type> access_traits_t; |
| 68 |
|
| 69 |
template<typename Data_Type> |
| 70 |
struct tree_types |
| 71 |
{ |
| 72 |
private: |
| 73 |
typedef typename tree_common_types<basic_type, Data_Type, std::less<basic_type>, __gnu_pbds::null_node_update, alloc_type>::regression_tl no_order_statistics_tl_t; |
| 74 |
|
| 75 |
typedef typename tree_common_types<basic_type, Data_Type, std::less<basic_type>, __gnu_pbds::tree_order_statistics_node_update, alloc_type>::regression_tl order_statistics_tl_t; |
| 76 |
|
| 77 |
public: |
| 78 |
typedef typename __gnu_cxx::typelist::append<no_order_statistics_tl_t, order_statistics_tl_t>::type tl_t; |
| 79 |
|
| 80 |
typedef no_order_statistics_tl_t min_tl_t; |
| 81 |
}; |
| 82 |
|
| 83 |
template<typename Data_Type> |
| 84 |
struct trie_types |
| 85 |
{ |
| 86 |
private: |
| 87 |
typedef typename trie_common_types<basic_type, Data_Type, access_traits_t, __gnu_pbds::pat_trie_tag, __gnu_pbds::null_node_update, alloc_type>::regression_tl no_updates_tl_t; |
| 88 |
|
| 89 |
typedef typename trie_common_types<basic_type, Data_Type, access_traits_t, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_order_statistics_node_update, alloc_type>::regression_tl order_statistics_tl_t; |
| 90 |
|
| 91 |
typedef typename trie_common_types<basic_type, Data_Type, access_traits_t, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update, alloc_type>::regression_tl prefix_search_tl_t; |
| 92 |
|
| 93 |
public: |
| 94 |
typedef typename __gnu_cxx::typelist::append<no_updates_tl_t, typename __gnu_cxx::typelist::append<prefix_search_tl_t, order_statistics_tl_t>::type>::type tl_t; |
| 95 |
|
| 96 |
typedef no_updates_tl_t min_tl_t; |
| 97 |
}; |
| 98 |
|
| 99 |
template<typename Data_Type> |
| 100 |
struct hash_types |
| 101 |
{ |
| 102 |
typedef typename hash_common_types<basic_type, Data_Type, hash, std::equal_to<basic_type>, alloc_type>::regression_tl tl_t; |
| 103 |
|
| 104 |
typedef tl_t min_tl_t; |
| 105 |
}; |
| 106 |
|
| 107 |
template<typename Data_Type> |
| 108 |
struct lu_types |
| 109 |
{ |
| 110 |
typedef typename lu_common_types<basic_type, Data_Type, std::equal_to<basic_type>, alloc_type>::regression_tl tl_t; |
| 111 |
|
| 112 |
typedef tl_t min_tl_t; |
| 113 |
}; |
| 114 |
|
| 115 |
// Sequence types. |
| 116 |
typedef pq_common_types<basic_type, std::less<basic_type>, alloc_type> pq_types; |
| 117 |
|
| 118 |
typedef pq_types::regression_tl pq_tl_t; |
| 119 |
typedef pq_tl_t min_pq_tl_t; |
| 120 |
|
| 121 |
template<typename _Tp, typename _Alloc> |
| 122 |
struct vector_adaptor : public std::vector<_Tp, _Alloc> |
| 123 |
{ |
| 124 |
private: |
| 125 |
typedef std::vector<_Tp, _Alloc> base_type; |
| 126 |
|
| 127 |
public: |
| 128 |
typedef typename base_type::value_type value_type; |
| 129 |
typedef typename base_type::pointer pointer; |
| 130 |
typedef typename base_type::const_pointer const_pointer; |
| 131 |
typedef typename base_type::reference reference; |
| 132 |
typedef typename base_type::const_reference const_reference; |
| 133 |
typedef typename base_type::iterator iterator; |
| 134 |
typedef typename base_type::const_iterator const_iterator; |
| 135 |
typedef typename base_type::reverse_iterator reverse_iterator; |
| 136 |
typedef typename base_type::const_reverse_iterator const_reverse_iterator; |
| 137 |
typedef typename base_type::size_type size_type; |
| 138 |
typedef typename base_type::difference_type difference_type; |
| 139 |
typedef typename base_type::allocator_type allocator_type; |
| 140 |
|
| 141 |
typedef __gnu_pbds::sequence_tag container_category; |
| 142 |
typedef std::less<_Tp> cmp_fn; |
| 143 |
|
| 144 |
const cmp_fn& |
| 145 |
get_cmp_fn() const |
| 146 |
{ return _M_cmp; } |
| 147 |
|
| 148 |
vector_adaptor() { } |
| 149 |
vector_adaptor(iterator) { } |
| 150 |
vector_adaptor(iterator, iterator) { } |
| 151 |
vector_adaptor(iterator, iterator, const cmp_fn&) { } |
| 152 |
vector_adaptor(const cmp_fn& other) { } |
| 153 |
|
| 154 |
using base_type::push_back; |
| 155 |
using base_type::pop_back; |
| 156 |
|
| 157 |
// erase_if |
| 158 |
|
| 159 |
cmp_fn _M_cmp; |
| 160 |
|
| 161 |
}; |
| 162 |
|
| 163 |
typedef vector_adaptor<basic_type, alloc_type> vector_type; |
| 164 |
typedef __gnu_cxx::typelist::create1<vector_type>::type vector_tl_t; |
| 165 |
|
| 166 |
// Associative types. |
| 167 |
typedef tree_types<null_type>::tl_t tree_set_tl_t; |
| 168 |
typedef tree_types<null_type>::min_tl_t min_tree_set_tl_t; |
| 169 |
typedef tree_types<basic_type>::tl_t tree_map_tl_t; |
| 170 |
typedef tree_types<basic_type>::min_tl_t min_tree_map_tl_t; |
| 171 |
|
| 172 |
typedef hash_types<null_type>::tl_t hash_set_tl_t; |
| 173 |
typedef hash_types<null_type>::min_tl_t min_hash_set_tl_t; |
| 174 |
typedef hash_types<basic_type>::tl_t hash_map_tl_t; |
| 175 |
typedef hash_types<basic_type>::min_tl_t min_hash_map_tl_t; |
| 176 |
|
| 177 |
typedef lu_types<null_type>::tl_t lu_set_tl_t; |
| 178 |
typedef lu_types<null_type>::min_tl_t min_lu_set_tl_t; |
| 179 |
typedef lu_types<basic_type>::tl_t lu_map_tl_t; |
| 180 |
typedef lu_types<basic_type>::min_tl_t min_lu_map_tl_t; |
| 181 |
|
| 182 |
typedef trie_types<null_type>::tl_t trie_set_tl_t; |
| 183 |
typedef trie_types<null_type>::min_tl_t min_trie_set_tl_t; |
| 184 |
typedef trie_types<basic_type>::tl_t trie_map_tl_t; |
| 185 |
typedef trie_types<basic_type>::min_tl_t min_trie_map_tl_t; |
| 186 |
} // namespace test |
| 187 |
} // namespace __gnu_pbds |
| 188 |
|
| 189 |
#endif |