aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2023-07-24 13:23:36 -0700
committerMike Buland <eichlan@xagasoft.com>2023-07-24 13:23:36 -0700
commitb544779d5b759d4ab2b82654e3f53b82ea41bac7 (patch)
treef0e224292a679e7e660b538c3f319af80bb820f1 /src
parent247ea16cad1f78f57bdb00decfba602e3455372f (diff)
downloadlibbu++-b544779d5b759d4ab2b82654e3f53b82ea41bac7.tar.gz
libbu++-b544779d5b759d4ab2b82654e3f53b82ea41bac7.tar.bz2
libbu++-b544779d5b759d4ab2b82654e3f53b82ea41bac7.tar.xz
libbu++-b544779d5b759d4ab2b82654e3f53b82ea41bac7.zip
Added swap to array.
Diffstat (limited to 'src')
-rw-r--r--src/stable/array.h13
-rw-r--r--src/unit/array.unit12
2 files changed, 25 insertions, 0 deletions
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
103 iSize--; 103 iSize--;
104 } 104 }
105 105
106 void swap( int iPos1, int iPos2 )
107 {
108 value tmp = pData[iPos1];
109 pData[iPos1] = pData[iPos2];
110 pData[iPos2] = tmp;
111 }
112
106 valuealloc va; 113 valuealloc va;
107 value *pData; 114 value *pData;
108 long iSize; 115 long iSize;
@@ -732,6 +739,12 @@ namespace Bu
732 core->swapErase( i.iPos ); 739 core->swapErase( i.iPos );
733 } 740 }
734 741
742 void swap( int iPos1, int iPos2 )
743 {
744 _hardCopy();
745 core->swap( iPos1, iPos2 );
746 }
747
735 protected: 748 protected:
736 virtual Core *_copyCore( Core *src ) 749 virtual Core *_copyCore( Core *src )
737 { 750 {
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
109 aStr[1] = "Hello"; 109 aStr[1] = "Hello";
110 aStr[0] = aStr[1].clone(); 110 aStr[0] = aStr[1].clone();
111 } 111 }
112
113 test swap
114 {
115 Bu::Array<Bu::String> aStr( 3 );
116 aStr.append("One");
117 aStr.append("Three");
118 aStr.append("Two");
119
120 aStr.swap( 1, 2 );
121 unitTest( aStr[1] == "Two" );
122 unitTest( aStr[2] == "Three");
123 }
112} 124}