aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-06 09:32:19 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-06 09:32:19 +0000
commit3cef0a39bc70308fd5a1fb3783c5f4ca716aca80 (patch)
treef3f161169d64f18b3820131ea431e68ac4b2486d
parent2408f61837aaaba5590d290008721186ea9f011e (diff)
downloadlibbu++-3cef0a39bc70308fd5a1fb3783c5f4ca716aca80.tar.gz
libbu++-3cef0a39bc70308fd5a1fb3783c5f4ca716aca80.tar.bz2
libbu++-3cef0a39bc70308fd5a1fb3783c5f4ca716aca80.tar.xz
libbu++-3cef0a39bc70308fd5a1fb3783c5f4ca716aca80.zip
I corrected a peculiar heap corner case that caused an infinite loop.
Diffstat (limited to '')
-rw-r--r--src/heap.h2
-rw-r--r--src/list.h4
-rw-r--r--src/tests/heap.cpp3
3 files changed, 7 insertions, 2 deletions
diff --git a/src/heap.h b/src/heap.h
index 523c8e2..60c39ac 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -95,6 +95,8 @@ namespace Bu
95 for( int j = iFill; j >= 0; ) 95 for( int j = iFill; j >= 0; )
96 { 96 {
97 int k = (j-1)/2; 97 int k = (j-1)/2;
98 if( j == k )
99 break;
98 if( cmp( aItem[k], aItem[j] ) ) 100 if( cmp( aItem[k], aItem[j] ) )
99 break; 101 break;
100 102
diff --git a/src/list.h b/src/list.h
index f76c505..2e6280c 100644
--- a/src/list.h
+++ b/src/list.h
@@ -240,7 +240,7 @@ namespace Bu
240 return *this; 240 return *this;
241 } 241 }
242 242
243 bool operator==( const MyType &rhs ) 243 bool operator==( const MyType &rhs ) const
244 { 244 {
245 if( getSize() != rhs.getSize() ) 245 if( getSize() != rhs.getSize() )
246 return false; 246 return false;
@@ -255,7 +255,7 @@ namespace Bu
255 return true; 255 return true;
256 } 256 }
257 257
258 bool operator!=( const MyType &rhs ) 258 bool operator!=( const MyType &rhs ) const
259 { 259 {
260 return !(*this == rhs); 260 return !(*this == rhs);
261 } 261 }
diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp
index b1f510a..9a2daf0 100644
--- a/src/tests/heap.cpp
+++ b/src/tests/heap.cpp
@@ -73,6 +73,8 @@ int main()
73 73
74 hStr.enqueue("George"); 74 hStr.enqueue("George");
75 printHeap( hStr, j++ ); 75 printHeap( hStr, j++ );
76 hStr.enqueue("George");
77 printHeap( hStr, j++ );
76 hStr.enqueue("Sam"); 78 hStr.enqueue("Sam");
77 printHeap( hStr, j++ ); 79 printHeap( hStr, j++ );
78 hStr.enqueue("Abby"); 80 hStr.enqueue("Abby");
@@ -96,6 +98,7 @@ int main()
96 Bu::List<Bu::FString> lStr; 98 Bu::List<Bu::FString> lStr;
97 99
98 lStr.insertSorted("George"); 100 lStr.insertSorted("George");
101 lStr.insertSorted("George");
99 lStr.insertSorted("Sam"); 102 lStr.insertSorted("Sam");
100 lStr.insertSorted("Abby"); 103 lStr.insertSorted("Abby");
101 lStr.insertSorted("Zorro"); 104 lStr.insertSorted("Zorro");