Definition at line 23 of file IntArray.h.
◆ IntArray() [1/2]
IntArray::IntArray |
( |
int |
start_size = 0 | ) |
|
Definition at line 27 of file IntArray.cpp.
28{
29 count = start_size;
30 size = (count + alloc) / alloc * alloc;
31 items = new int [size];
32}
◆ IntArray() [2/2]
IntArray::IntArray |
( |
const IntArray & |
source | ) |
|
Definition at line 34 of file IntArray.cpp.
35{
36 count = source.count;
37 size = source.size;
38 items = new int [size];
39
40 for (int i = 0; i < count; i++)
41 items[i] = source.items[i];
42}
◆ ~IntArray()
Definition at line 44 of file IntArray.cpp.
45{
46 delete [] items;
47}
◆ Add() [1/2]
void IntArray::Add |
( |
const IntArray & |
rhs | ) |
|
Definition at line 313 of file IntArray.cpp.
314{
315 if (Length() != v.Length())
316 error("IntArray::Add - vectors have different lengths\n"
317 "IntArrays - Left[%d] += Right[%d] ",
318 Length(), v.Length());
319
320 for (int i = 0; i < Length(); i++)
321 items[i] += v[i];
322}
◆ Add() [2/2]
void IntArray::Add |
( |
int |
term | ) |
|
Definition at line 249 of file IntArray.cpp.
250{
251 for (int i = 0; i < count; i++)
252 items[i] += term;
253}
◆ Append() [1/2]
int IntArray::Append |
( |
const IntArray & |
rhs | ) |
|
Definition at line 77 of file IntArray.cpp.
78{
79 Grow(count + rhs.count);
80 for (int i = 0; i < rhs.count; i++)
81 items[count + i] = rhs.items[i];
82 count += rhs.count;
83 return count;
84}
◆ Append() [2/2]
int IntArray::Append |
( |
int |
value | ) |
|
Definition at line 70 of file IntArray.cpp.
71{
72 Grow(count + 1);
73 items[count++] = value;
74 return count;
75}
◆ BinarySearch()
int IntArray::BinarySearch |
( |
int |
value | ) |
const |
Definition at line 178 of file IntArray.cpp.
179{
180 int start = 0;
181 int stop = count - 1;
182
183 while (start <= stop)
184 {
185 int mid = (start + stop) / 2;
186
187 if (items[mid] == value)
188 return mid;
189
190 if (items[mid] > value)
191 stop = mid - 1;
192 else
193 start = mid + 1;
194 }
195
196 return -1;
197}
◆ Clear()
Definition at line 118 of file IntArray.h.
119 {
120 count = 0;
121 }
◆ Count()
int IntArray::Count |
( |
| ) |
const |
|
inline |
Definition at line 166 of file IntArray.h.
167 {
168 return count;
169 }
◆ CountIfGreater()
int IntArray::CountIfGreater |
( |
int |
treshold | ) |
const |
Definition at line 227 of file IntArray.cpp.
228{
229 int result = 0;
230
231 for (int i = 0; i < count; i++)
232 if (items[i] > threshold)
233 result++;
234
235 return result;
236}
◆ CountIfGreaterOrEqual()
int IntArray::CountIfGreaterOrEqual |
( |
int |
treshold | ) |
const |
Definition at line 238 of file IntArray.cpp.
239{
240 int result = 0;
241
242 for (int i = 0; i < count; i++)
243 if (items[i] >= treshold)
244 result++;
245
246 return result;
247}
◆ Delete()
int IntArray::Delete |
( |
int |
index | ) |
|
Definition at line 98 of file IntArray.cpp.
99{
100 count--;
101 if (count - index)
102 memmove(items + index, items + index + 1, sizeof(int) *(count - index));
103 return count;
104}
◆ Dimension()
void IntArray::Dimension |
( |
int |
new_count | ) |
|
|
inline |
Definition at line 113 of file IntArray.h.
114 {
115 Grow(new_count);
116 count = new_count;
117 }
◆ Divide()
void IntArray::Divide |
( |
int |
denominator | ) |
|
Definition at line 261 of file IntArray.cpp.
262{
263 for (int i = 0; i < count; i++)
264 items[i] /= denominator;
265}
◆ DoubleProduct()
double IntArray::DoubleProduct |
( |
| ) |
|
Definition at line 387 of file IntArray.cpp.
388{
389 double product = 1.0;
390
391 for (int i = 0; i < count; i++)
392 product *= items[i];
393
394 return product;
395}
◆ dSum() [1/3]
double IntArray::dSum |
( |
| ) |
const |
|
inline |
Definition at line 133 of file IntArray.h.
134 {
135 return dSum(0, count - 1);
136 }
◆ dSum() [2/3]
double IntArray::dSum |
( |
int |
start | ) |
const |
|
inline |
Definition at line 137 of file IntArray.h.
138 {
139 return dSum(start, count - 1);
140 }
◆ dSum() [3/3]
double IntArray::dSum |
( |
int |
start, |
|
|
int |
end |
|
) |
| const |
Definition at line 134 of file IntArray.cpp.
135{
136 double result = 0;
137
138 for (int i = start; i <= end; i++)
139 result += items[i];
140
141 return result;
142}
◆ dSumProduct()
double IntArray::dSumProduct |
( |
const IntArray & |
weight | ) |
const |
Definition at line 414 of file IntArray.cpp.
415{
416 if (count != weight.count)
417 error("IntArray::dSumProduct called with different sized arrays\n");
418
419 double sum = 0.0;
420 for (int i = 0; i < count; i++)
421 sum += items[i] * weight[i];
422
423 return sum;
424}
◆ FastFind()
int IntArray::FastFind |
( |
int |
value | ) |
const |
|
inline |
Definition at line 97 of file IntArray.h.
98 {
99 return BinarySearch(value);
100 }
◆ Find()
int IntArray::Find |
( |
int |
value | ) |
const |
Definition at line 170 of file IntArray.cpp.
171{
172 for (int i = 0; i < count; i++)
173 if (value == items[i])
174 return i;
175 return -1;
176}
◆ Hash()
int IntArray::Hash |
( |
int |
initval = 0 | ) |
|
Definition at line 397 of file IntArray.cpp.
398{
399 return hash((unsigned char *) items, sizeof(int) * count, initval);
400}
◆ InnerProduct()
int IntArray::InnerProduct |
( |
IntArray & |
v | ) |
|
Definition at line 324 of file IntArray.cpp.
325{
326 if (Length() != v.Length())
327 error("IntArray::InnerProduct - vectors have different dimensions\n"
328 "IntArrays - Left[%d] * Right[%d] ",
329 Length(), v.Length());
330
331 int sum = 0;
332 for (int i = 0; i < Length(); i++)
333 sum += items[i] * v[i];
334
335 return sum;
336}
◆ InsertAt()
void IntArray::InsertAt |
( |
int |
index, |
|
|
int |
value |
|
) |
| |
Definition at line 106 of file IntArray.cpp.
107{
108 Grow(count + 1);
109 if (count - index)
110 memmove(items + index + 1, items + index, sizeof(int) *(count - index));
111 items[index] = value;
112 count++;
113}
◆ isAscending()
bool IntArray::isAscending |
( |
| ) |
|
Definition at line 297 of file IntArray.cpp.
298{
299 for (int i = 1; i < count; i++)
300 if (items[i] < items[i - 1])
301 return false;
302 return true;
303}
◆ isDescending()
bool IntArray::isDescending |
( |
| ) |
|
Definition at line 305 of file IntArray.cpp.
306{
307 for (int i = 1; i < count; i++)
308 if (items[i] > items[i - 1])
309 return false;
310 return true;
311}
◆ Last()
int & IntArray::Last |
( |
| ) |
const |
|
inline |
Definition at line 86 of file IntArray.h.
87 {
88 return items[count - 1];
89 }
◆ Length()
int IntArray::Length |
( |
| ) |
const |
|
inline |
Definition at line 109 of file IntArray.h.
110 {
111 return count;
112 }
◆ Max() [1/3]
int IntArray::Max |
( |
| ) |
const |
|
inline |
Definition at line 146 of file IntArray.h.
147 {
148 return Max(0, count - 1);
149 }
◆ Max() [2/3]
int IntArray::Max |
( |
int |
start | ) |
const |
|
inline |
Definition at line 150 of file IntArray.h.
151 {
152 return Max(start, count - 1);
153 }
◆ Max() [3/3]
int IntArray::Max |
( |
int |
start, |
|
|
int |
end |
|
) |
| const |
Definition at line 144 of file IntArray.cpp.
145{
146 if (start >= count) return 0;
147
148 int result = items[start];
149
150 for (int i = start + 1; i <= end; i++)
151 if (result < items[i])
152 result = items[i];
153
154 return result;
155}
◆ Min() [1/3]
int IntArray::Min |
( |
| ) |
const |
|
inline |
Definition at line 156 of file IntArray.h.
157 {
158 return Min(0, count - 1);
159 }
◆ Min() [2/3]
int IntArray::Min |
( |
int |
start | ) |
const |
|
inline |
Definition at line 160 of file IntArray.h.
161 {
162 return Min(start, count - 1);
163 }
◆ Min() [3/3]
int IntArray::Min |
( |
int |
start, |
|
|
int |
end |
|
) |
| const |
Definition at line 157 of file IntArray.cpp.
158{
159 if (start >= count) return 0;
160
161 int result = items[start];
162
163 for (int i = start + 1; i <= end; i++)
164 if (result > items[i])
165 result = items[i];
166
167 return result;
168}
◆ Multiply()
void IntArray::Multiply |
( |
int |
factor | ) |
|
Definition at line 255 of file IntArray.cpp.
256{
257 for (int i = 0; i < count; i++)
258 items[i] *= factor;
259}
◆ operator int *()
IntArray::operator int * |
( |
| ) |
|
|
inline |
Definition at line 182 of file IntArray.h.
183 {
184 return items;
185 }
◆ operator!=()
bool IntArray::operator!= |
( |
const IntArray & |
rhs | ) |
const |
Definition at line 289 of file IntArray.cpp.
290{
291 return !(*this == rhs);
292}
◆ operator*=()
IntArray & IntArray::operator*= |
( |
int |
rhs | ) |
|
|
inline |
Definition at line 209 of file IntArray.h.
210 {
211 Multiply(rhs);
212 return *this;
213 }
◆ operator+=() [1/2]
Definition at line 203 of file IntArray.h.
204 {
205 Add(rhs);
206 return *this;
207 }
◆ operator+=() [2/2]
IntArray & IntArray::operator+= |
( |
int |
rhs | ) |
|
|
inline |
Definition at line 197 of file IntArray.h.
198 {
199 Add(rhs);
200 return *this;
201 }
◆ operator-=()
IntArray & IntArray::operator-= |
( |
int |
rhs | ) |
|
|
inline |
Definition at line 215 of file IntArray.h.
216 {
217 Add(-rhs);
218 return *this;
219 }
◆ operator/=()
IntArray & IntArray::operator/= |
( |
int |
rhs | ) |
|
|
inline |
Definition at line 221 of file IntArray.h.
222 {
223 Divide(rhs);
224 return *this;
225 }
◆ operator=()
Definition at line 115 of file IntArray.cpp.
116{
117 Grow(rhs.count);
118 count = rhs.count;
119 for (int i = 0; i < count; i++)
120 items[i] = rhs.items[i];
121 return *this;
122}
◆ operator==()
bool IntArray::operator== |
( |
const IntArray & |
rhs | ) |
const |
Definition at line 277 of file IntArray.cpp.
278{
279 if (count != rhs.count)
280 return false;
281
282 for (int i = 0; i < rhs.count; i++)
283 if (items[i] != rhs.items[i])
284 return false;
285
286 return true;
287}
◆ operator[]() [1/6]
int & IntArray::operator[] |
( |
char |
index | ) |
|
|
inline |
Definition at line 52 of file IntArray.h.
53 {
54 return items[int(index)];
55 }
◆ operator[]() [2/6]
int IntArray::operator[] |
( |
char |
index | ) |
const |
|
inline |
Definition at line 56 of file IntArray.h.
57 {
58 return items[int(index)];
59 }
◆ operator[]() [3/6]
int & IntArray::operator[] |
( |
double |
fraction | ) |
|
|
inline |
Definition at line 62 of file IntArray.h.
63 {
64 return items[(int)(count * fraction)];
65 }
◆ operator[]() [4/6]
int IntArray::operator[] |
( |
double |
fraction | ) |
const |
|
inline |
Definition at line 66 of file IntArray.h.
67 {
68 return items[(int)(count * fraction)];
69 }
◆ operator[]() [5/6]
int & IntArray::operator[] |
( |
int |
index | ) |
|
|
inline |
Definition at line 41 of file IntArray.h.
42 {
43 return items[index];
44 }
◆ operator[]() [6/6]
int IntArray::operator[] |
( |
int |
index | ) |
const |
|
inline |
Definition at line 45 of file IntArray.h.
46 {
47 return items[index];
48 }
◆ Peek()
int IntArray::Peek |
( |
| ) |
const |
|
inline |
Definition at line 82 of file IntArray.h.
83 {
84 return items[count - 1];
85 }
◆ Pop()
Definition at line 78 of file IntArray.h.
79 {
80 return items[--count];
81 }
◆ Print() [1/4]
Definition at line 239 of file IntArray.h.
240 {
241 Print(stdout);
242 }
◆ Print() [2/4]
void IntArray::Print |
( |
const char * |
label | ) |
|
|
inline |
Definition at line 243 of file IntArray.h.
244 {
245 Print(stdout, label);
246 }
◆ Print() [3/4]
void IntArray::Print |
( |
FILE * |
output | ) |
|
Definition at line 353 of file IntArray.cpp.
354{
355 Print(output, "Array of Integers");
356}
◆ Print() [4/4]
void IntArray::Print |
( |
FILE * |
output, |
|
|
const char * |
label |
|
) |
| |
Definition at line 358 of file IntArray.cpp.
359{
360 fprintf(output, "%s [%d elements]: ", label, count);
361
362 for (int i = 0; i < count; i++)
363 fprintf(output, "%d ", items[i]);
364
365 fprintf(output, "\n");
366}
◆ Product()
int IntArray::Product |
( |
| ) |
|
Definition at line 377 of file IntArray.cpp.
378{
379 int product = 1;
380
381 for (int i = 0; i < count; i++)
382 product *= items[i];
383
384 return product;
385}
◆ Push()
void IntArray::Push |
( |
int |
value | ) |
|
|
inline |
Definition at line 74 of file IntArray.h.
75 {
76 Append(value);
77 }
◆ PushIfNew()
void IntArray::PushIfNew |
( |
int |
value | ) |
|
Definition at line 368 of file IntArray.cpp.
369{
370 for (int i = 0; i < count; i++)
371 if (items[i] == value)
372 return;
373
374 Push(value);
375}
◆ Reverse()
void IntArray::Reverse |
( |
| ) |
|
Definition at line 221 of file IntArray.cpp.
222{
223 for (int i = 0, j = count - 1; i < j; i++, j--)
224 Swap(i, j);
225}
◆ Set()
void IntArray::Set |
( |
int |
value | ) |
|
Definition at line 86 of file IntArray.cpp.
87{
88 for (int i = 0; i < count; i++)
89 items[i] = value;
90}
◆ SetSequence()
void IntArray::SetSequence |
( |
int |
start = 0 , |
|
|
int |
increment = 1 |
|
) |
| |
Definition at line 92 of file IntArray.cpp.
93{
94 for (int i = 0; i < count; i++, start += increment)
95 items[i] = start;
96}
◆ Sort() [1/2]
Definition at line 210 of file IntArray.cpp.
211{
212 QuickSort(items, count, sizeof(int), COMPAREFUNC Compare);
213}
◆ Sort() [2/2]
void IntArray::Sort |
( |
IntArray & |
freeRider | ) |
|
Definition at line 215 of file IntArray.cpp.
216{
217 QuickSort2(items, freeRider.items, count, sizeof(int), COMPAREFUNC Compare);
218}
◆ Stack()
void IntArray::Stack |
( |
const IntArray & |
rhs | ) |
|
Definition at line 267 of file IntArray.cpp.
268{
269 int end = count;
270
271 Dimension(count + a.count);
272
273 for (int i = 0; i < a.count; i++)
274 items[i + end] = a[i];
275}
◆ Subtract()
void IntArray::Subtract |
( |
int |
term | ) |
|
|
inline |
Definition at line 188 of file IntArray.h.
189 {
190 Add(-term);
191 }
◆ Sum() [1/3]
int IntArray::Sum |
( |
| ) |
const |
|
inline |
Definition at line 123 of file IntArray.h.
124 {
125 return Sum(0, count - 1);
126 }
◆ Sum() [2/3]
int IntArray::Sum |
( |
int |
start | ) |
const |
|
inline |
Definition at line 127 of file IntArray.h.
128 {
129 return Sum(start, count - 1);
130 }
◆ Sum() [3/3]
int IntArray::Sum |
( |
int |
start, |
|
|
int |
end |
|
) |
| const |
Definition at line 124 of file IntArray.cpp.
125{
126 int result = 0;
127
128 for (int i = start; i <= end; i++)
129 result += items[i];
130
131 return result;
132}
◆ SumProduct()
int IntArray::SumProduct |
( |
const IntArray & |
weight | ) |
const |
Definition at line 402 of file IntArray.cpp.
403{
404 if (count != weight.count)
405 error("IntArray::SumProduct called with different sized arrays\n");
406
407 int sum = 0;
408 for (int i = 0; i < count; i++)
409 sum += items[i] * weight[i];
410
411 return sum;
412}
◆ Swap() [1/2]
void IntArray::Swap |
( |
int |
i, |
|
|
int |
j |
|
) |
| |
|
inline |
Definition at line 173 of file IntArray.h.
174 {
175 int tmp = items[i];
176 items[i] = items[j];
177 items[j] = tmp;
178 }
◆ Swap() [2/2]
Definition at line 338 of file IntArray.cpp.
339{
340 int * temp = rhs.items;
341 rhs.items = items;
342 items = temp;
343
344 int swap = rhs.count;
345 rhs.count = count;
346 count = swap;
347
348 swap = rhs.size;
349 rhs.size = size;
350 size = swap;
351}
◆ Zero()
Definition at line 199 of file IntArray.cpp.
200{
201 for (int i = 0; i < count; i++)
202 items[i] = 0;
203}
◆ alloc
The documentation for this class was generated from the following files: