From b544779d5b759d4ab2b82654e3f53b82ea41bac7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 24 Jul 2023 13:23:36 -0700 Subject: Added swap to array. --- src/stable/array.h | 13 +++++++++++++ src/unit/array.unit | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/stable/array.h b/src/stable/array.h index 86b57d9..885594b 100644 --- a/src/stable/array.h +++ b/src/stable/array.h @@ -103,6 +103,13 @@ namespace Bu iSize--; } + void swap( int iPos1, int iPos2 ) + { + value tmp = pData[iPos1]; + pData[iPos1] = pData[iPos2]; + pData[iPos2] = tmp; + } + valuealloc va; value *pData; long iSize; @@ -732,6 +739,12 @@ namespace Bu core->swapErase( i.iPos ); } + void swap( int iPos1, int iPos2 ) + { + _hardCopy(); + core->swap( iPos1, iPos2 ); + } + protected: virtual Core *_copyCore( Core *src ) { diff --git a/src/unit/array.unit b/src/unit/array.unit index e9f2bdf..e2c08eb 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit @@ -109,4 +109,16 @@ suite Array aStr[1] = "Hello"; aStr[0] = aStr[1].clone(); } + + test swap + { + Bu::Array aStr( 3 ); + aStr.append("One"); + aStr.append("Three"); + aStr.append("Two"); + + aStr.swap( 1, 2 ); + unitTest( aStr[1] == "Two" ); + unitTest( aStr[2] == "Three"); + } } -- cgit v1.2.3