Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testDynArray.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33# include <cerrno>
34# include <climits>
35# include <cstdlib>
36# include <ctime>
37# include <iostream>
38# include <cmath>
39
40# include <tpl_dynarray_set.H>
41
42
43# include <cassert>
44using namespace std;
45
46# define RAND( x ) (unsigned long) ( x * ( rand() / (RAND_MAX+1.0) ) )
47
48
49# include <cassert>
50using namespace Aleph;
51# include <cassert>
52using namespace std;
53
54struct Test
55{
56 char a1;
57 char a2;
58};
59
60
61int main(int argc,char *argv[])
62{
63 unsigned long seed,index;
64 unsigned long i, value, val;
65
66 unsigned long NUM_ITE = 1000;
67 if (argc > 1)
68 {
69 char * endptr = nullptr;
70 errno = 0;
71 const unsigned long parsed = strtoul(argv[1], &endptr, 10);
72 if (errno != 0 or endptr == argv[1] or *endptr != '\0'
73 or parsed > static_cast<unsigned long>(INT_MAX))
74 {
75 cerr << "Invalid iteration count: " << argv[1] << endl;
76 return 1;
77 }
79 }
80
81 if (argc > 2)
82 seed = atol(argv[2]);
83 else
84 seed = std::time(nullptr);
85
86 srand (seed);
87
89
90 t[10]->a1 = 'a';
91 t[10]->a2 = 'b';
92
93 cout << t[10]->a1 << t[10000]->a1 << endl;
94
95 cout << "./testDynArray " << NUM_ITE << " " << seed << endl;
96
97 try
98 {
99 {
100 DynArray<unsigned long> v1(8,8,8), v2(NUM_ITE);
101
102 for(i = 0; i < NUM_ITE; i++)
103 {
104 value = RAND(NUM_ITE);
105 index = RAND(NUM_ITE);
106 v1[index] = value;
107 v2[index] = v1[index];
108 val = v1[index];
109 value = v2[index];
110 cout << "(" << val << ") (" << value << ") ";
111 assert(v2[index] == v1[index]);
112 }
113
114 {
116
118
119 v4 = v1;
120
121 v4.swap(v2);
122 }
123
124 v2.reserve(0, 2*NUM_ITE);
125
126 }
127 DynArray<unsigned long> v(10, 10, 6);
128
129 v.reserve(0, 2*NUM_ITE);
130
131 v.reserve(NUM_ITE, 4*NUM_ITE);
132 }
133 catch(const std::overflow_error&)
134 {
135 cout << "Overflow!" << endl;
136 }
137 catch(const std::bad_alloc&)
138 {
139 cout << "Not enough memory!" << endl;
140 }
141 catch(const std::invalid_argument&)
142 {
143 cout << "invalid_argument!" << endl;
144 }
145 catch (const std::exception & e)
146 {
147 cout << e.what() << endl;
148 }
149 cout << endl;
150
151 {
152 DynArray<int> s(12,10,4);
153
154 s.append(10);
155
156 cout << s.access(0) << " ****************" << endl;
157
158 cout << s.access(0) << " ****************" << endl;
159
160 s.append(16);
161
162 cout << s[1] << " ****************" << endl;
163
164 }
165
166 {
167 DynArray_Set<int> s(12,10,4);
168
169 s.append(10);
170
171 cout << s[0] << " ****************" << endl;
172
173 cout << s.access(0) << " ****************" << endl;
174
175 s.append(16);
176
177 cout << s[1] << " ****************" << endl;
178
179 }
180
182 for (size_t i = 0; i < NUM_ITE; ++i)
183 a.touch(i) = i;
184
185 for (DynArray<int>::Iterator it(a); it.has_curr(); it.next())
186 cout << it.get_curr() << " ";
187 cout << endl;
188
190 for (it.reset_last(); it.has_curr(); it.prev())
191 cout << it.get_curr() << " ";
192 cout << endl;
193}
194
195
196
197
198
199
200
201
202
203
204
int main()
size_t size_t int32_t value
Definition ca-c-api.h:116
Iterator on the items of array.
void reset_last() noexcept
Reset the iterator to the last item.
void prev()
Move the current a position backward.
bool has_curr() const noexcept
Check whether the iterator refers to an item.
T & get_curr() const
Return the current item.
Set-like container backed by a dynamic array.
T & touch(const size_t i)
Touch the entry i.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
T & append()
Allocate a new entry to the end of array.
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
char a1
char a2
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
STL namespace.
#define RAND(x)
ValueArg< size_t > seed
Definition testHash.C:53
Array-based dynamic set.