projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
moved AdjustToClientAreaOrigin to wxWindowBase, needed worldwide for wxUniv
[wxWidgets.git]
/
src
/
common
/
dynarray.cpp
diff --git
a/src/common/dynarray.cpp
b/src/common/dynarray.cpp
index 80f70067591e918411024e96968b0c06214e938c..2d8e1623780eb18101892a366b9eb048b60fc184 100644
(file)
--- a/
src/common/dynarray.cpp
+++ b/
src/common/dynarray.cpp
@@
-17,14
+17,14
@@
#pragma implementation "dynarray.h"
#endif
#pragma implementation "dynarray.h"
#endif
-#include
<wx/wxprec.h>
+#include
"wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dynarray.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dynarray.h"
-#include
<wx/intl.h>
+#include
"wx/intl.h"
#include <stdlib.h>
#include <string.h> // for memmove
#include <stdlib.h>
#include <string.h> // for memmove
@@
-73,14
+73,7
@@
wxBaseArray::wxBaseArray(const wxBaseArray& src)
// assignment operator
wxBaseArray& wxBaseArray::operator=(const wxBaseArray& src)
{
// assignment operator
wxBaseArray& wxBaseArray::operator=(const wxBaseArray& src)
{
-#if 0
wxDELETEA(m_pItems);
wxDELETEA(m_pItems);
-#else
- if ( (m_pItems)) {
- delete (m_pItems);
- (m_pItems) = 0;
- }
-#endif
m_nSize = // not src.m_nSize to save memory
m_nCount = src.m_nCount;
m_nSize = // not src.m_nSize to save memory
m_nCount = src.m_nCount;
@@
-141,8
+134,6
@@
void wxBaseArray::Clear()
// pre-allocates memory (frees the previous data!)
void wxBaseArray::Alloc(size_t nSize)
{
// pre-allocates memory (frees the previous data!)
void wxBaseArray::Alloc(size_t nSize)
{
- wxASSERT( nSize > 0 );
-
// only if old buffer was not big enough
if ( nSize > m_nSize ) {
wxDELETEA(m_pItems);
// only if old buffer was not big enough
if ( nSize > m_nSize ) {
wxDELETEA(m_pItems);
@@
-191,8
+182,8
@@
int wxBaseArray::Index(long lItem, bool bFromEnd) const
return wxNOT_FOUND;
}
return wxNOT_FOUND;
}
-// search for a
n item in
a sorted array (binary search)
-
int wxBaseArray::Index
(long lItem, CMPFUNC fnCompare) const
+// search for a
place to insert an item into
a sorted array (binary search)
+
size_t wxBaseArray::IndexForInsert
(long lItem, CMPFUNC fnCompare) const
{
size_t i,
lo = 0,
{
size_t i,
lo = 0,
@@
-207,12
+198,23
@@
int wxBaseArray::Index(long lItem, CMPFUNC fnCompare) const
hi = i;
else if ( res > 0 )
lo = i + 1;
hi = i;
else if ( res > 0 )
lo = i + 1;
- else
- return i;
+ else {
+ lo = i;
+ break;
+ }
}
}
- return
wxNOT_FOUND
;
+ return
lo
;
}
}
+
+// search for an item in a sorted array (binary search)
+int wxBaseArray::Index(long lItem, CMPFUNC fnCompare) const
+{
+ size_t n = IndexForInsert(lItem, fnCompare);
+
+ return n < m_nCount && m_pItems[n] == lItem ? (int)n : wxNOT_FOUND;
+}
+
// add item at the end
void wxBaseArray::Add(long lItem)
{
// add item at the end
void wxBaseArray::Add(long lItem)
{
@@
-223,34
+225,13
@@
void wxBaseArray::Add(long lItem)
// add item assuming the array is sorted with fnCompare function
void wxBaseArray::Add(long lItem, CMPFUNC fnCompare)
{
// add item assuming the array is sorted with fnCompare function
void wxBaseArray::Add(long lItem, CMPFUNC fnCompare)
{
- size_t i,
- lo = 0,
- hi = m_nCount;
- int res;
-
- while ( lo < hi ) {
- i = (lo + hi)/2;
-
- res = (*fnCompare)((const void *)lItem, (const void *)m_pItems[i]);
- if ( res < 0 )
- hi = i;
- else if ( res > 0 )
- lo = i + 1;
- else {
- lo = hi = i;
- break;
- }
- }
-
- wxASSERT( lo == hi ); // I hope I got binary search right :-)
-
- Insert(lItem, lo);
+ Insert(lItem, IndexForInsert(lItem, fnCompare));
}
// add item at the given position
void wxBaseArray::Insert(long lItem, size_t nIndex)
{
}
// add item at the given position
void wxBaseArray::Insert(long lItem, size_t nIndex)
{
- wxCHECK_RET( nIndex <= m_nCount,
"bad index in wxArray::Insert"
);
+ wxCHECK_RET( nIndex <= m_nCount,
wxT("bad index in wxArray::Insert")
);
Grow();
Grow();
@@
-261,9
+242,9
@@
void wxBaseArray::Insert(long lItem, size_t nIndex)
}
// removes item from array (by index)
}
// removes item from array (by index)
-void wxBaseArray::Remove(size_t nIndex)
+void wxBaseArray::Remove
At
(size_t nIndex)
{
{
- wxCHECK_RET( nIndex <= m_nCount,
"bad index in wxArray::Remove"
);
+ wxCHECK_RET( nIndex <= m_nCount,
wxT("bad index in wxArray::RemoveAt")
);
memmove(&m_pItems[nIndex], &m_pItems[nIndex + 1],
(m_nCount - nIndex - 1)*sizeof(long));
memmove(&m_pItems[nIndex], &m_pItems[nIndex + 1],
(m_nCount - nIndex - 1)*sizeof(long));
@@
-276,9
+257,9
@@
void wxBaseArray::Remove(long lItem)
int iIndex = Index(lItem);
wxCHECK_RET( iIndex != wxNOT_FOUND,
int iIndex = Index(lItem);
wxCHECK_RET( iIndex != wxNOT_FOUND,
-
"removing inexistent item in wxArray::Remove"
);
+
wxT("removing inexistent item in wxArray::Remove")
);
- Remove((size_t)iIndex);
+ Remove
At
((size_t)iIndex);
}
// sort array elements using passed comparaison function
}
// sort array elements using passed comparaison function