16#if !defined(ON_ARRAY_DEFS_INC_)
17#define ON_ARRAY_DEFS_INC_
19#if defined(ON_COMPILER_MSC)
31#pragma warning(disable:4100)
38#pragma warning(disable:4211)
64 return (T*)
onrealloc(ptr,capacity*
sizeof(T));
113 memcpy( m_a, src.
m_a, m_count*
sizeof(T) );
147 return ((
unsigned int)(m_capacity*
sizeof(T)));
153 return ON_CRC32(current_remainder,m_count*
sizeof(m_a[0]),m_a);
177 return (m_count > 0) ? m_a : 0;
183 return (m_count > 0) ? m_a : 0;
218 return (m_count > 0) ? m_a : 0;
224 return (m_count > 0) ? m_a : 0;
230 return (
i >= 0 &&
i < m_count) ? m_a+
i : 0;
236 return (
i >= 0 &&
i < m_count) ? m_a+
i : 0;
242 return (m_count > 0) ? m_a+(m_count-1) : 0;
248 return (m_count > 0) ? m_a+(m_count-1) : 0;
258 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
259 src_i + ele_cnt > m_count || dest_i > m_count )
262 int capacity = dest_i + ele_cnt;
263 if ( capacity > m_capacity ) {
264 if ( capacity < 2*m_capacity )
265 capacity = 2*m_capacity;
266 SetCapacity( capacity );
269 memmove( &m_a[dest_i], &m_a[src_i], ele_cnt*
sizeof(T) );
275 if ( m_count == m_capacity )
277 int new_capacity = NewCapacity();
278 Reserve( new_capacity );
280 memset( &m_a[m_count], 0,
sizeof(T) );
281 return m_a[m_count++];
287 if ( m_count == m_capacity )
289 const int newcapacity = NewCapacity();
292 const int s = (int)(&x - m_a);
293 if (
s >= 0 &&
s < m_capacity )
301 Reserve( newcapacity );
302 m_a[m_count++] = temp;
306 Reserve(newcapacity);
314 if ( count > 0 && p )
316 if ( count + m_count > m_capacity )
318 int newcapacity = NewCapacity();
319 if ( newcapacity < count + m_count )
320 newcapacity = count + m_count;
321 Reserve( newcapacity );
323 memcpy( m_a + m_count, p, count*
sizeof(T) );
331 if(
i >= 0 &&
i <= m_count )
333 if ( m_count == m_capacity )
335 int newcapacity = NewCapacity();
336 Reserve( newcapacity );
339 Move(
i+1,
i, m_count-1-
i );
353 if (
i >= 0 &&
i < m_count ) {
354 Move(
i,
i+1, m_count-1-
i );
356 memset( &m_a[m_count], 0,
sizeof(T) );
364 memset( m_a, 0, m_capacity*
sizeof(T) );
377 for ( ;
i < j;
i++, j-- ) {
398 for (
int i = 0;
i < m_count;
i++ ) {
399 if (!memcmp(p,m_a+
i,
sizeof(T)))
408 for (
int i = 0;
i < m_count;
i++ ) {
409 if (!compar(key,m_a+
i))
418 const T* found = (key&&m_a&&m_count>0)
419 ? (
const T*)bsearch( key, m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar )
429#if defined(ON_COMPILER_MSC1300)
430 rc = ((int)(found - m_a));
431#elif 8 == ON_SIZEOF_POINTER
465 if ( m_a && m_count > 0 && compar ) {
467 ON_hsort( m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
477 if ( m_a && m_count > 0 && compar ) {
479 qsort( m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
489 if ( m_a && m_count > 0 && compar && index ) {
491 ON_Sort(sa, index, m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
492 else if ( m_count == 1 )
503 if ( m_a && m_count > 0 && compar && index ) {
505 ON_Sort(sa, index, m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
506 else if ( m_count == 1 )
517 if ( m_a && m_count > 0 && index ) {
519 T* buffer = (T*)
onmalloc(m_count*
sizeof(buffer[0]));
520 memcpy( buffer, m_a, m_count*
sizeof(T) );
521 for (
i = 0;
i < m_count;
i++ )
522 memcpy( m_a+
i, buffer+index[
i],
sizeof(T) );
532 if ( m_a && m_capacity > 0 ) {
533 memset( m_a, 0, m_capacity*
sizeof(T) );
540 if ( m_a && m_capacity > 0 ) {
541 memset( m_a, value, m_capacity*
sizeof(T) );
550 if( m_capacity < newcap )
551 SetCapacity( newcap );
557 SetCapacity( m_count );
571 if ( count >= 0 && count <= m_capacity )
579 if ( capacity != m_capacity ) {
581 if ( m_count > capacity )
584 m_a = Realloc( m_a, capacity );
586 if ( capacity > m_capacity ) {
588 memset( m_a + m_capacity, 0, (capacity-m_capacity)*
sizeof(T) );
590 m_capacity = capacity;
594 m_count = m_capacity = 0;
600 m_count = m_capacity = 0;
625 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
626 if (m_count*
sizeof(T) <= cap_size || m_count < 8)
627 return ((m_count <= 2) ? 4 : 2*m_count);
631 int delta_count = 8 + cap_size/
sizeof(T);
632 if ( delta_count > m_count )
633 delta_count = m_count;
634 return (m_count + delta_count);
657 const size_t cap_size = 32*
sizeof(
void*)*1024*1024;
658 if (m_count*
sizeof(T) <= cap_size || m_count < 8)
659 return ((m_count <= 2) ? 4 : 2*m_count);
663 int delta_count = 8 + cap_size/
sizeof(T);
664 if ( delta_count > m_count )
665 delta_count = m_count;
666 return (m_count + delta_count);
708 T* reptr = (T*)
onrealloc(ptr,capacity*
sizeof(T));
709 if ( ptr && reptr && reptr != ptr )
714 for (
i = 0;
i < this->m_count;
i++ )
716 reptr[
i].MemoryRelocate();
732 return (T*)
onrealloc(ptr,capacity*
sizeof(T));
741 for (
i = 0;
i < this->m_count;
i++ )
743 current_remainder = this->m_a[
i].DataCRC(current_remainder);
745 return current_remainder;
795 for (
i = 0;
i < m_count;
i++ ) {
831 return ((
unsigned int)(m_capacity*
sizeof(T)));
855 return (m_count > 0) ? m_a : 0;
861 return (m_count > 0) ? m_a : 0;
895 return (m_count > 0) ? m_a : 0;
901 return (m_count > 0) ? m_a : 0;
907 return (
i >= 0 &&
i < m_count) ? m_a+
i : 0;
913 return (
i >= 0 &&
i < m_count) ? m_a+
i : 0;
919 return (m_count > 0) ? m_a+(m_count-1) : 0;
925 return (m_count > 0) ? m_a+(m_count-1) : 0;
936 if ( ele_cnt <= 0 || src_i < 0 || dest_i < 0 || src_i == dest_i ||
937 src_i + ele_cnt > m_count || dest_i > m_count )
940 int capacity = dest_i + ele_cnt;
941 if ( capacity > m_capacity ) {
942 if ( capacity < 2*m_capacity )
943 capacity = 2*m_capacity;
944 SetCapacity( capacity );
947 memmove( &m_a[dest_i], &m_a[src_i], ele_cnt*
sizeof(T) );
967 if ( m_count == m_capacity )
969 int newcapacity = NewCapacity();
970 Reserve( newcapacity );
975 DestroyElement(m_a[m_count]);
977 ConstructDefaultElement(&m_a[m_count]);
979 return m_a[m_count++];
985 if ( m_count == m_capacity )
987 const int newcapacity = NewCapacity();
990 const int s = (int)(&x - m_a);
991 if (
s >= 0 &&
s < m_capacity )
999 Reserve( newcapacity );
1000 m_a[m_count++] = temp;
1004 Reserve(newcapacity);
1013 if ( count > 0 && p )
1015 if ( count + m_count > m_capacity )
1017 int newcapacity = NewCapacity();
1018 if ( newcapacity < count + m_count )
1019 newcapacity = count + m_count;
1020 Reserve( newcapacity );
1022 for (
i = 0;
i < count;
i++ ) {
1023 m_a[m_count++] = p[
i];
1032 if(
i >= 0 &&
i <= m_count )
1034 if ( m_count == m_capacity )
1036 int newcapacity = NewCapacity();
1037 Reserve( newcapacity );
1039 DestroyElement( m_a[m_count] );
1041 if (
i < m_count-1 ) {
1042 Move(
i+1,
i, m_count-1-
i );
1043 memset( &m_a[
i], 0,
sizeof(T) );
1044 ConstructDefaultElement( &m_a[
i] );
1047 ConstructDefaultElement( &m_a[m_count-1] );
1062 if (
i >= 0 &&
i < m_count )
1064 DestroyElement( m_a[
i] );
1065 memset( &m_a[
i], 0,
sizeof(T) );
1066 Move(
i,
i+1, m_count-1-
i );
1067 memset( &m_a[m_count-1], 0,
sizeof(T) );
1068 ConstructDefaultElement(&m_a[m_count-1]);
1077 for (
i = m_count-1;
i >= 0;
i-- ) {
1078 DestroyElement( m_a[
i] );
1079 memset( &m_a[
i], 0,
sizeof(T) );
1080 ConstructDefaultElement( &m_a[
i] );
1094 for ( ;
i < j;
i++, j-- ) {
1095 memcpy( t, &m_a[
i],
sizeof(T) );
1096 memcpy( &m_a[
i], &m_a[j],
sizeof(T) );
1097 memcpy( &m_a[j], t,
sizeof(T) );
1104 if (
i != j &&
i >= 0 && j >= 0 &&
i < m_count && j < m_count ) {
1106 memcpy( t, &m_a[
i],
sizeof(T) );
1107 memcpy( &m_a[
i], &m_a[j],
sizeof(T) );
1108 memcpy( &m_a[j], t,
sizeof(T) );
1115 for (
int i = 0;
i < m_count;
i++ )
1117 if (!compar(key,m_a+
i))
1126 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;
1127#if defined(ON_COMPILER_MSC1300)
1129 return found ? ((int)(found - m_a)) : -1;
1140 if ( m_a && m_count > 0 && compar )
1143 ON_hsort( m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1153 if ( m_a && m_count > 0 && compar )
1156 qsort( m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1170 if ( this->m_a && this->m_count > 0 && compar )
1172 if ( this->m_count > 1 )
1174 ON_hsort( this->m_a, this->m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1179 for (
i = 0;
i < this->m_count;
i++ )
1181 this->m_a[
i].MemoryRelocate();
1195 if ( this->m_a && this->m_count > 0 && compar )
1197 if ( this->m_count > 1 )
1199 qsort( this->m_a, this->m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1204 for (
i = 0;
i < this->m_count;
i++ )
1206 this->m_a[
i].MemoryRelocate();
1219 if ( m_a && m_count > 0 && compar && index )
1222 ON_Sort(sa, index, m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*))compar );
1223 else if ( m_count == 1 )
1234 if ( m_a && m_count > 0 && compar && index )
1237 ON_Sort(sa, index, m_a, m_count,
sizeof(T), (
int(*)(
const void*,
const void*,
void*))compar, p );
1238 else if ( m_count == 1 )
1249 if ( m_a && m_count > 0 && index )
1252 T* buffer = (T*)
onmalloc(m_count*
sizeof(buffer[0]));
1253 memcpy( buffer, m_a, m_count*
sizeof(T) );
1254 for (
i = 0;
i < m_count;
i++ )
1255 memcpy( m_a+
i, buffer+index[
i],
sizeof(T) );
1266 if ( m_a && m_capacity > 0 ) {
1267 for (
i = m_capacity-1;
i >= 0;
i-- ) {
1268 DestroyElement(m_a[
i]);
1269 memset( &m_a[
i], 0,
sizeof(T) );
1270 ConstructDefaultElement(&m_a[
i]);
1280 if( m_capacity < newcap )
1281 SetCapacity( newcap );
1287 SetCapacity( m_count );
1301 if ( count >= 0 && count <= m_capacity )
1310 if ( capacity < 1 ) {
1312 for (
i = m_capacity-1;
i >= 0;
i-- ) {
1313 DestroyElement(m_a[
i]);
1321 else if ( m_capacity < capacity ) {
1323 m_a = Realloc( m_a, capacity );
1327 memset( m_a + m_capacity, 0, (capacity-m_capacity)*
sizeof(T) );
1328 for (
i = m_capacity;
i < capacity;
i++ ) {
1329 ConstructDefaultElement(&m_a[
i]);
1331 m_capacity = capacity;
1340 else if ( m_capacity > capacity ) {
1342 for (
i = m_capacity-1;
i >= capacity;
i-- ) {
1343 DestroyElement(m_a[
i]);
1345 if ( m_count > capacity )
1347 m_capacity = capacity;
1348 m_a = Realloc( m_a, capacity );
1384#if defined(ON_COMPILER_MSC)
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Definition opennurbs_array.h:760
T * First()
Definition opennurbs_array_defs.h:893
void SetCapacity(int)
Definition opennurbs_array_defs.h:1306
int Count() const
Definition opennurbs_array_defs.h:817
unsigned int SizeOfArray() const
Definition opennurbs_array_defs.h:829
T & AppendNew()
Definition opennurbs_array_defs.h:965
void Shrink()
Definition opennurbs_array_defs.h:1285
T * Array()
Definition opennurbs_array_defs.h:865
int NewCapacity() const
Definition opennurbs_array_defs.h:638
void SetArray(T *)
Definition opennurbs_array_defs.h:887
void Append(const T &)
Definition opennurbs_array_defs.h:983
void Zero()
Definition opennurbs_array_defs.h:1263
T * At(int)
Definition opennurbs_array_defs.h:905
void Move(int, int, int)
Definition opennurbs_array_defs.h:931
bool Permute(const int *)
Definition opennurbs_array_defs.h:1246
T * Last()
Definition opennurbs_array_defs.h:917
virtual T * Realloc(T *, int)
Definition opennurbs_array_defs.h:730
T & operator[](int)
Definition opennurbs_array_defs.h:835
int BinarySearch(const T *, int(*)(const T *, const T *)) const
Definition opennurbs_array_defs.h:1124
ON_ClassArray()
Definition opennurbs_array_defs.h:749
void SetCount(int)
Definition opennurbs_array_defs.h:1299
int Search(const T *, int(*)(const T *, const T *)) const
Definition opennurbs_array_defs.h:1113
void ConstructDefaultElement(T *)
Definition opennurbs_array_defs.h:951
bool Sort(ON::sort_algorithm, int *, int(*)(const T *, const T *)) const
Definition opennurbs_array_defs.h:1216
void Swap(int, int)
Definition opennurbs_array_defs.h:1102
virtual bool QuickSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:1150
ON_ClassArray< T > & operator=(const ON_ClassArray< T > &)
Definition opennurbs_array_defs.h:782
void Destroy()
Definition opennurbs_array_defs.h:1291
void Remove()
Definition opennurbs_array_defs.h:1054
T * KeepArray()
Definition opennurbs_array_defs.h:877
void Empty()
Definition opennurbs_array_defs.h:1074
void DestroyElement(T &)
Definition opennurbs_array_defs.h:959
virtual ~ON_ClassArray()
Definition opennurbs_array_defs.h:776
void Reserve(int)
Definition opennurbs_array_defs.h:1278
T * m_a
Definition opennurbs_array.h:983
void Reverse()
Definition opennurbs_array_defs.h:1086
virtual bool HeapSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:1137
void EmergencyDestroy(void)
Definition opennurbs_array_defs.h:807
void Insert(int, const T &)
Definition opennurbs_array_defs.h:1030
int m_count
Definition opennurbs_array.h:984
int Capacity() const
Definition opennurbs_array_defs.h:823
Definition opennurbs_array.h:998
T * Realloc(T *, int)
Definition opennurbs_array_defs.h:706
~ON_ObjectArray()
Definition opennurbs_array_defs.h:679
ON_ObjectArray()
Definition opennurbs_array_defs.h:674
bool HeapSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:1165
bool QuickSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:1190
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Definition opennurbs_array_defs.h:736
ON_ObjectArray< T > & operator=(const ON_ObjectArray< T > &)
Definition opennurbs_array_defs.h:689
Definition opennurbs_array.h:46
void Shrink()
Definition opennurbs_array_defs.h:555
void Zero()
Definition opennurbs_array_defs.h:530
T * Last()
Definition opennurbs_array_defs.h:240
void Append(const T &)
Definition opennurbs_array_defs.h:285
T * At(int)
Definition opennurbs_array_defs.h:228
int m_count
Definition opennurbs_array.h:290
void SetCount(int)
Definition opennurbs_array_defs.h:569
void Insert(int, const T &)
Definition opennurbs_array_defs.h:329
void Destroy()
Definition opennurbs_array_defs.h:561
void Swap(int, int)
Definition opennurbs_array_defs.h:385
T * m_a
Definition opennurbs_array.h:289
T & operator[](int)
Definition opennurbs_array_defs.h:157
int NewCapacity() const
Definition opennurbs_array_defs.h:606
bool Sort(ON::sort_algorithm, int *, int(*)(const T *, const T *)) const
Definition opennurbs_array_defs.h:486
void SetArray(T *)
Definition opennurbs_array_defs.h:209
ON_SimpleArray()
Definition opennurbs_array_defs.h:68
unsigned int SizeOfArray() const
Definition opennurbs_array_defs.h:145
bool HeapSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:462
void EmergencyDestroy(void)
Definition opennurbs_array_defs.h:123
void Empty()
Definition opennurbs_array_defs.h:361
void Reverse()
Definition opennurbs_array_defs.h:369
bool QuickSort(int(*)(const T *, const T *))
Definition opennurbs_array_defs.h:474
void Move(int, int, int)
Definition opennurbs_array_defs.h:254
void Reserve(int)
Definition opennurbs_array_defs.h:548
void MemSet(unsigned char)
Definition opennurbs_array_defs.h:538
void SetCapacity(int)
Definition opennurbs_array_defs.h:576
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const
Definition opennurbs_array_defs.h:151
int Search(const T &) const
Definition opennurbs_array_defs.h:395
void Remove()
Definition opennurbs_array_defs.h:345
virtual T * Realloc(T *, int)
Definition opennurbs_array_defs.h:62
bool Permute(const int *)
Definition opennurbs_array_defs.h:514
int Count() const
Definition opennurbs_array_defs.h:133
virtual ON_SimpleArray< T > & operator=(const ON_SimpleArray< T > &)
Definition opennurbs_array_defs.h:101
T & AppendNew()
Definition opennurbs_array_defs.h:273
T * First()
Definition opennurbs_array_defs.h:216
T * Array()
Definition opennurbs_array_defs.h:187
int BinarySearch(const T *, int(*)(const T *, const T *)) const
Definition opennurbs_array_defs.h:416
int Capacity() const
Definition opennurbs_array_defs.h:139
virtual ~ON_SimpleArray()
Definition opennurbs_array_defs.h:95
T * KeepArray()
Definition opennurbs_array_defs.h:199
static int ON_CompareDecreasing(const T *a, const T *b)
Definition opennurbs_array_defs.h:1375
static int ON_CompareIncreasing(const T *a, const T *b)
Definition opennurbs_array_defs.h:1364
ON__UINT32 ON_CRC32(ON__UINT32 current_remainder, size_t count, const void *p)
Definition opennurbs_crc.cpp:109
#define ON_ASSERT(cond)
Definition opennurbs_error.h:31
void ON_Sort(ON::sort_algorithm method, int *index, const void *data, size_t count, size_t sizeof_element, int(*compar)(const void *, const void *))
Definition opennurbs_math.cpp:2812
void ON_hsort(void *base, size_t nel, size_t width, int(*compar)(const void *, const void *))
Definition opennurbs_math.cpp:3043
ON_DECL void onfree(void *)
ON_DECL void * onrealloc(void *, size_t)
ON_DECL void * onmalloc(size_t)
char s
Definition opennurbs_string.cpp:32
#define NULL
Definition opennurbs_system.h:256
unsigned long long ON__UINT64
Definition opennurbs_system.h:356
unsigned int ON__UINT32
Definition opennurbs_system.h:326