]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/pb_ds/regression/associative_containers.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / pb_ds / regression / associative_containers.cc
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
cbe34bb5 3// Copyright (C) 2005-2017 Free Software Foundation, Inc.
4569a895
AT
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
748086b7 8// Foundation; either version 3, or (at your option) any later
4569a895
AT
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
748086b7
JJ
17// along with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
4569a895 19
4569a895
AT
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 assoc_link_regression_test_1.cpp
34 * A linkage regression test.
35 */
36
37
38#include <ext/pb_ds/assoc_container.hpp>
39#include <iostream>
40#include <cassert>
41
42using namespace std;
5e11f978 43using namespace __gnu_pbds;
4569a895
AT
44
45/**
46 * The following function performs a sequence of operations on an
47 * associative container object mapping integers to characters.
48 */
49template<typename Cntnr>
50void
51some_op_sequence(Cntnr& r_c)
52{
53 assert(r_c.empty());
54 assert(r_c.size() == 0);
55
56 r_c.insert(make_pair(1, 'a'));
57
58 r_c[2] = 'b';
59
60 assert(!r_c.empty());
61 assert(r_c.size() == 2);
62
63 cout << "Key 1 is mapped to " << r_c[1] << endl;
64 cout << "Key 2 is mapped to " << r_c[2] << endl;
65
66 cout << endl << "All value types in the container:" << endl;
67 for (typename Cntnr::const_iterator it = r_c.begin(); it != r_c.end(); ++it)
68 cout << it->first << " -> " << it->second << endl;
69
70 cout << endl;
71
72 r_c.clear();
73
74 assert(r_c.empty());
75 assert(r_c.size() == 0);
76}
77
78void
79assoc_link_regression_test_0()
80{
81 {
82 // Perform operations on a collision-chaining hash map.
83 cc_hash_table<int, char> c;
84 some_op_sequence(c);
85 }
86
87 {
88 // Perform operations on a general-probing hash map.
89 gp_hash_table<int, char> c;
90 some_op_sequence(c);
91 }
92
93 {
94 // Perform operations on a red-black tree map.
95 tree<int, char> c;
96 some_op_sequence(c);
97 }
98
99 {
100 // Perform operations on a splay tree map.
101 tree<int, char, less<int>, splay_tree_tag> c;
102 some_op_sequence(c);
103 }
104
105 {
106 // Perform operations on a splay tree map.
107 tree<int, char, less<int>, ov_tree_tag> c;
108 some_op_sequence(c);
109 }
110
111 {
112 // Perform operations on a list-update map.
113 list_update<int, char> c;
114 some_op_sequence(c);
115 }
116}
117
118
119void
120assoc_link_regression_test_1()
121{
122 {
123 // Perform operations on a collision-chaining hash map.
124 cc_hash_table<int, char> c;
125 some_op_sequence(c);
126 }
127
128 {
129 // Perform operations on a general-probing hash map.
130 gp_hash_table<int, char> c;
131 some_op_sequence(c);
132 }
133
134 {
135 // Perform operations on a red-black tree map.
136 tree<int, char> c;
137 some_op_sequence(c);
138 }
139
140 {
141 // Perform operations on a splay tree map.
142 tree<int, char, less<int>, splay_tree_tag> c;
143 some_op_sequence(c);
144 }
145
146 {
147 // Perform operations on a splay tree map.
148 tree<int, char, less<int>, ov_tree_tag> c;
149 some_op_sequence(c);
150 }
151
152 {
153 // Perform operations on a list-update map.
154 list_update<int, char> c;
155 some_op_sequence(c);
156 }
157}
158
159int
160main()
161{
162 assoc_link_regression_test_0();
163 assoc_link_regression_test_1();
164 return 0;
165}