aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/MyVector.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/MyVector.h
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'CPP/Common/MyVector.h')
-rw-r--r--CPP/Common/MyVector.h34
1 files changed, 24 insertions, 10 deletions
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h
index 9ee7105..a772785 100644
--- a/CPP/Common/MyVector.h
+++ b/CPP/Common/MyVector.h
@@ -258,7 +258,7 @@ public:
258 { 258 {
259 if (index != 0) 259 if (index != 0)
260 { 260 {
261 T temp = _items[index]; 261 const T temp = _items[index];
262 memmove(_items + 1, _items, (size_t)index * sizeof(T)); 262 memmove(_items + 1, _items, (size_t)index * sizeof(T));
263 _items[0] = temp; 263 _items[0] = temp;
264 } 264 }
@@ -268,15 +268,29 @@ public:
268 T& operator[](unsigned index) { return _items[index]; } 268 T& operator[](unsigned index) { return _items[index]; }
269 const T& operator[](int index) const { return _items[(unsigned)index]; } 269 const T& operator[](int index) const { return _items[(unsigned)index]; }
270 T& operator[](int index) { return _items[(unsigned)index]; } 270 T& operator[](int index) { return _items[(unsigned)index]; }
271
272 const T* ConstData() const { return _items; }
273 T* NonConstData() const { return _items; }
274 T* NonConstData() { return _items; }
275
276 const T* Data() const { return _items; }
277 T* Data() { return _items; }
278
279 const T& FrontItem() const { return _items[0]; }
280 T& FrontItem() { return _items[0]; }
281 /*
282 const T Front() const { return _items[0]; }
283 T Front() { return _items[0]; }
271 const T& Front() const { return _items[0]; } 284 const T& Front() const { return _items[0]; }
272 T& Front() { return _items[0]; } 285 T& Front() { return _items[0]; }
286 */
273 const T& Back() const { return _items[(size_t)_size - 1]; } 287 const T& Back() const { return _items[(size_t)_size - 1]; }
274 T& Back() { return _items[(size_t)_size - 1]; } 288 T& Back() { return _items[(size_t)_size - 1]; }
275 289
276 /* 290 /*
277 void Swap(unsigned i, unsigned j) 291 void Swap(unsigned i, unsigned j)
278 { 292 {
279 T temp = _items[i]; 293 const T temp = _items[i];
280 _items[i] = _items[j]; 294 _items[i] = _items[j];
281 _items[j] = temp; 295 _items[j] = temp;
282 } 296 }
@@ -368,7 +382,7 @@ public:
368 382
369 static void SortRefDown(T* p, unsigned k, unsigned size, int (*compare)(const T*, const T*, void *), void *param) 383 static void SortRefDown(T* p, unsigned k, unsigned size, int (*compare)(const T*, const T*, void *), void *param)
370 { 384 {
371 T temp = p[k]; 385 const T temp = p[k];
372 for (;;) 386 for (;;)
373 { 387 {
374 unsigned s = (k << 1); 388 unsigned s = (k << 1);
@@ -389,16 +403,16 @@ public:
389 unsigned size = _size; 403 unsigned size = _size;
390 if (size <= 1) 404 if (size <= 1)
391 return; 405 return;
392 T* p = (&Front()) - 1; 406 T* p = _items - 1;
393 { 407 {
394 unsigned i = size >> 1; 408 unsigned i = size >> 1;
395 do 409 do
396 SortRefDown(p, i, size, compare, param); 410 SortRefDown(p, i, size, compare, param);
397 while (--i != 0); 411 while (--i);
398 } 412 }
399 do 413 do
400 { 414 {
401 T temp = p[size]; 415 const T temp = p[size];
402 p[size--] = p[1]; 416 p[size--] = p[1];
403 p[1] = temp; 417 p[1] = temp;
404 SortRefDown(p, 1, size, compare, param); 418 SortRefDown(p, 1, size, compare, param);
@@ -408,7 +422,7 @@ public:
408 422
409 static void SortRefDown2(T* p, unsigned k, unsigned size) 423 static void SortRefDown2(T* p, unsigned k, unsigned size)
410 { 424 {
411 T temp = p[k]; 425 const T temp = p[k];
412 for (;;) 426 for (;;)
413 { 427 {
414 unsigned s = (k << 1); 428 unsigned s = (k << 1);
@@ -429,16 +443,16 @@ public:
429 unsigned size = _size; 443 unsigned size = _size;
430 if (size <= 1) 444 if (size <= 1)
431 return; 445 return;
432 T* p = (&Front()) - 1; 446 T* p = _items - 1;
433 { 447 {
434 unsigned i = size >> 1; 448 unsigned i = size >> 1;
435 do 449 do
436 SortRefDown2(p, i, size); 450 SortRefDown2(p, i, size);
437 while (--i != 0); 451 while (--i);
438 } 452 }
439 do 453 do
440 { 454 {
441 T temp = p[size]; 455 const T temp = p[size];
442 p[size--] = p[1]; 456 p[size--] = p[1];
443 p[1] = temp; 457 p[1] = temp;
444 SortRefDown2(p, 1, size); 458 SortRefDown2(p, 1, size);