17 #if !defined(ON_ARRAY_DEFS_INC_) 18 #define ON_ARRAY_DEFS_INC_ 20 #if defined(ON_COMPILER_MSC) 32 #pragma warning(disable:4100) 39 #pragma warning(disable:4211) 61 return (T*)onrealloc(ptr,capacity*
sizeof(T));
138 return ((
unsigned int)
m_count);
150 return ((
unsigned int)(
m_capacity*
sizeof(T)));
156 return ((
unsigned int)(
sizeof(T)));
163 return ON_CRC32(current_remainder,
m_count*
sizeof(
m_a[0]),
m_a);
169 #if defined(ON_DEBUG) 172 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
181 #if defined(ON_DEBUG) 184 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
194 #if defined(ON_DEBUG) 197 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
206 #if defined(ON_DEBUG) 209 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
218 #if defined(ON_DEBUG) 221 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
230 #if defined(ON_DEBUG) 233 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
243 #if defined(ON_DEBUG) 246 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
255 #if defined(ON_DEBUG) 258 ON_ERROR(
"ON_SimpleArray[i]: i out of range.");
338 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
350 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
356 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
368 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
396 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
400 int capacity = dest_i + ele_cnt;
407 memmove( &
m_a[dest_i], &
m_a[src_i], ele_cnt*
sizeof(T) );
419 return m_a[m_count++];
430 const int s = (int)(&x -
m_a);
452 if ( count > 0 && p )
457 if ( newcapacity < count +
m_count )
515 for ( ; i < j; i++, j-- ) {
536 for (
int i = 0; i <
m_count; i++ ) {
537 if (!memcmp(p,
m_a+i,
sizeof(T)))
546 for (
int i = 0; i <
m_count; i++ ) {
547 if (!compar(key,
m_a+i))
557 ? (
const T*)bsearch( key,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar )
567 #if defined(ON_COMPILER_MSC1300) 568 rc = ((int)(found -
m_a));
569 #elif 8 == ON_SIZEOF_POINTER 573 const ON__UINT64 fptr = (ON__UINT64)found;
574 const ON__UINT64 aptr = (ON__UINT64)
m_a;
575 const ON__UINT64 sz = (ON__UINT64)
sizeof(T);
576 const ON__UINT64 i = (fptr - aptr)/sz;
582 const ON__UINT32 fptr = (ON__UINT32)found;
583 const ON__UINT32 aptr = (ON__UINT32)
m_a;
584 const ON__UINT32 sz = (ON__UINT32)
sizeof(T);
585 const ON__UINT32 i = (fptr - aptr)/sz;
607 ? (
const T*)bsearch( key,
m_a, count,
sizeof(T), (
int(*)(
const void*,
const void*))compar )
617 #if defined(ON_COMPILER_MSC1300) 618 rc = ((int)(found -
m_a));
619 #elif 8 == ON_SIZEOF_POINTER 623 const ON__UINT64 fptr = (ON__UINT64)found;
624 const ON__UINT64 aptr = (ON__UINT64)
m_a;
625 const ON__UINT64 sz = (ON__UINT64)
sizeof(T);
626 const ON__UINT64 i = (fptr - aptr)/sz;
632 const ON__UINT32 fptr = (ON__UINT32)found;
633 const ON__UINT32 aptr = (ON__UINT32)
m_a;
634 const ON__UINT32 sz = (ON__UINT32)
sizeof(T);
635 const ON__UINT32 i = (fptr - aptr)/sz;
655 ON_hsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
667 ON_qsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
677 if (
m_a &&
m_count > 0 && compar && index ) {
679 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
691 if (
m_a &&
m_count > 0 && compar && index ) {
693 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
707 T* buffer = (T*)onmalloc(
m_count*
sizeof(buffer[0]));
710 memcpy(
m_a+i, buffer+index[i],
sizeof(T) );
813 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
819 int delta_count = 8 + cap_size/
sizeof(T);
822 return (
m_count + delta_count);
845 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
851 int delta_count = 8 + cap_size/
sizeof(T);
854 return (
m_count + delta_count);
896 T* reptr = (T*)onrealloc(ptr,capacity*
sizeof(T));
897 if ( ptr && reptr && reptr != ptr )
902 for ( i = 0; i < this->
m_count; i++ )
904 reptr[i].MemoryRelocate();
920 return (T*)onrealloc(ptr,capacity*
sizeof(T));
929 for ( i = 0; i < this->
m_count; i++ )
931 current_remainder = this->
m_a[i].DataCRC(current_remainder);
933 return current_remainder;
983 for ( i = 0; i <
m_count; i++ ) {
1013 return ((
unsigned int)
m_count);
1025 return ((
unsigned int)(
m_capacity*
sizeof(T)));
1031 return ((
unsigned int)(
sizeof(T)));
1037 #if defined(ON_DEBUG) 1040 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1050 #if defined(ON_DEBUG) 1053 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1062 #if defined(ON_DEBUG) 1065 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1074 #if defined(ON_DEBUG) 1077 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1086 #if defined(ON_DEBUG) 1089 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1098 #if defined(ON_DEBUG) 1101 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1110 #if defined(ON_DEBUG) 1113 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1122 #if defined(ON_DEBUG) 1125 ON_ERROR(
"ON_ClassArray[i]: i out of range.");
1204 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
1216 return (i < (
unsigned int)
m_count) ?
m_a+i : 0;
1223 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
1229 return (i < (ON__UINT64)
m_count) ?
m_a+i : 0;
1235 return (i >= 0 && i < (ON__INT64)
m_count) ?
m_a+i : 0;
1241 return (i < (ON__UINT64)
m_count) ?
m_a+i : 0;
1265 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
1269 int capacity = dest_i + ele_cnt;
1280 memmove( (
void*)(&
m_a[dest_i]), (
const void*)(&
m_a[src_i]), ele_cnt*
sizeof(T) );
1323 const int s = (int)(&x -
m_a);
1346 if ( count > 0 && p )
1351 if ( newcapacity < count +
m_count )
1352 newcapacity = count +
m_count;
1355 for ( i = 0; i < count; i++ ) {
1374 if ( i < m_count-1 ) {
1375 Move( i+1, i, m_count-1-i );
1378 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1402 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1406 memset( (
void*)(&
m_a[
m_count-1]), 0,
sizeof(T) );
1416 for ( i =
m_count-1; i >= 0; i-- ) {
1420 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1435 for ( ; i < j; i++, j-- ) {
1436 memcpy( t, &
m_a[i],
sizeof(T) );
1437 memcpy( &
m_a[i], &
m_a[j],
sizeof(T) );
1438 memcpy( &
m_a[j], t,
sizeof(T) );
1445 if ( i != j && i >= 0 && j >= 0 && i <
m_count && j <
m_count ) {
1447 memcpy( t, &
m_a[i],
sizeof(T) );
1448 memcpy( &
m_a[i], &
m_a[j],
sizeof(T) );
1449 memcpy( &
m_a[j], t,
sizeof(T) );
1456 for (
int i = 0; i <
m_count; i++ )
1458 if (!compar(key,
m_a+i))
1467 const T* found = (key&&
m_a&&
m_count>0) ? (
const T*)bsearch( key,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar ) : 0;
1468 #if defined(ON_COMPILER_MSC1300) 1470 return found ? ((int)(found -
m_a)) : -1;
1473 return found ? ((int)((((ON__UINT64)found) - ((ON__UINT64)
m_a))/
sizeof(T))) : -1;
1484 const T* found = (key&&
m_a&&
m_count>0) ? (
const T*)bsearch( key,
m_a, count,
sizeof(T), (
int(*)(
const void*,
const void*))compar ) : 0;
1485 #if defined(ON_COMPILER_MSC1300) 1487 return found ? ((int)(found -
m_a)) : -1;
1490 return found ? ((int)((((ON__UINT64)found) - ((ON__UINT64)
m_a))/
sizeof(T))) : -1;
1501 ON_hsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1514 ON_qsort(
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1528 if ( this->
m_a && this->
m_count > 0 && compar )
1532 ON_hsort( this->
m_a, this->
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1537 for ( i = 0; i < this->
m_count; i++ )
1539 this->
m_a[i].MemoryRelocate();
1553 if ( this->
m_a && this->
m_count > 0 && compar )
1557 ON_qsort( this->
m_a, this->
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1562 for ( i = 0; i < this->
m_count; i++ )
1564 this->
m_a[i].MemoryRelocate();
1580 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1595 ON_Sort(sa, index,
m_a,
m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
1610 T* buffer = (T*)onmalloc(
m_count*
sizeof(buffer[0]));
1612 for (i = 0; i <
m_count; i++ )
1613 memcpy(
m_a+i, buffer+index[i],
sizeof(T) );
1629 memset( (
void*)(&
m_a[i]), 0,
sizeof(T) );
1670 if ( capacity < 1 ) {
1706 for ( i =
m_capacity-1; i >= capacity; i-- ) {
1728 int ON_CompareIncreasing(
const T* a,
const T* b)
1739 int ON_CompareDecreasing(
const T* a,
const T* b)
1748 #if defined(ON_COMPILER_MSC) 1749 #pragma warning(pop)
void EmergencyDestroy(void)
virtual ~ON_SimpleArray()
unsigned int UnsignedCount() const
virtual ON_SimpleArray< T > & operator=(const ON_SimpleArray< T > &)
bool Permute(const int *)
int BinarySearch(const T *, int(*)(const T *, const T *)) const
bool Sort(ON::sort_algorithm sort_algorithm, int *, int(*)(const T *, const T *)) const
unsigned int SizeOfElement() const
virtual bool QuickSort(int(*)(const T *, const T *))
void ConstructDefaultElement(T *)
virtual T * Realloc(T *, int)
virtual bool HeapSort(int(*)(const T *, const T *))
void Insert(int, const T &)
void MemSet(unsigned char)
bool QuickSort(int(*)(const T *, const T *))
void Insert(int, const T &)
bool QuickSort(int(*)(const T *, const T *))
bool HeapSort(int(*)(const T *, const T *))
ON_ClassArray< T > & operator=(const ON_ClassArray< T > &)
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
bool Permute(const int *)
virtual T * Realloc(T *, int)
int BinarySearch(const T *, int(*)(const T *, const T *)) const
int Search(const T *, int(*)(const T *, const T *)) const
unsigned int UnsignedCount() const
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
bool Sort(ON::sort_algorithm sort_algorithm, int *, int(*)(const T *, const T *)) const
unsigned int SizeOfArray() const
ON_ObjectArray< T > & operator=(const ON_ObjectArray< T > &)
unsigned int SizeOfElement() const
unsigned int SizeOfArray() const
int Search(const T &) const
void EmergencyDestroy(void)
bool HeapSort(int(*)(const T *, const T *))