Skip to content

Commit a530537

Browse files
committed
simplifications
1 parent 74e75f8 commit a530537

File tree

1 file changed

+6
-67
lines changed

1 file changed

+6
-67
lines changed

thresh/cxArray.h

+6-67
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* -*-C++-*-
2-
32
!!! NOTE: this version has been hacked up to work with SwitchActor.
43
54
This file is part of a set of general purpose libraries to extend C++,
@@ -21,11 +20,8 @@
2120
2221
_CC_NO_INLINE_LOOPS -> 1 if compiler does NOT inline loops,
2322
0 (default) if inlining of loops is done.
24-
25-
BUGS:
2623
*/
27-
#ifndef _cxArray_h
28-
#define _cxArray_h
24+
#pragma once
2925

3026
#define SA_HACK 1 // 1 to use the hacks for SwitchActor.
3127

@@ -114,7 +110,6 @@ inline void cxBitCopyRange(T* dst, T* src, int start, int end)
114110
memmove(dst, src, sizeof(T)*(end-start));
115111
}
116112

117-
118113
//----------------------------------------------------------------------
119114
// class array
120115
// type safe and access safe array data type
@@ -132,30 +127,20 @@ class cxBaseAB
132127
cxBaseAB() {}
133128
// this function should return non-zero if the destructor should be called.
134129
// when old data arrays are deleted, or when ~cxArrayB is called.
135-
#if 1
136130
static int destroyArray() { return 1; }
137-
#else
138-
static const int destroyArray() { return 1; }
139-
#endif
140131
// static int destroyArray(cxArrayB<T,AB>&)
141132

142133
// this function should return non-zero if the assignment operator
143134
// should be used to copy elements between old and new arrays.
144135
// Other bitwise copy (using mem moves) will be used.
145-
#if 1
146136
static int assignToCopy() { return 1; }
147-
#else
148-
static const int assignToCopy() { return 1; }
149-
#endif
150137

151138
static void assertionFailed(const char* test, const char* file, int line)
152139
{
153140
#ifdef VSS_IRIX
154141
__assert(test,file,line);
155142
#endif
156143
}
157-
158-
159144
};
160145
class cxHeapAB : public cxBaseAB, public cxHeapMB { };
161146
class cxNewDeleteAB : public cxBaseAB, public cxNewDeleteMB { };
@@ -396,7 +381,6 @@ class cxArrayB
396381
ostream& dumpOn(ostream& os, unsigned int printCount=10);
397382
};
398383

399-
400384
/*------------------------------------------------------------
401385
This function will call the destructors for every element
402386
of the array.
@@ -543,10 +527,6 @@ template <class T,class AB> class cxArrayIterB
543527
}
544528
};
545529

546-
547-
548-
549-
550530
//----------------------------------------------------------------------
551531
// class cxArray implementation
552532
//----------------------------------------------------------------------
@@ -589,16 +569,13 @@ template <class T,class AB> cxArrayB<T,AB>::cxArrayB(const cxArrayB<T,AB> & sour
589569
data[i] = source.data[i];
590570
}
591571

592-
593-
594572
template <class T,class AB> cxArrayB<T,AB>::~cxArrayB()
595573
{
596574
// free the dynamic memory buffer
597575
CXA_delete(AB,data,T,size);
598576
//data = 0;
599577
}
600578

601-
602579
template <class T,class AB> cxArrayB<T,AB> & cxArrayB<T,AB>::operator=
603580
(const cxArrayB<T,AB> & right)
604581
{
@@ -617,8 +594,6 @@ template <class T,class AB> cxArrayB<T,AB> & cxArrayB<T,AB>::operator=
617594
return *this;
618595
}
619596

620-
621-
622597
#if 1 // attempting trySetCapacity
623598
// Set the capacity of array to exactly newSize. Create new array
624599
// if the new size is different from the requested size, and copy
@@ -636,14 +611,12 @@ unsigned int cxArrayB<T,AB>::trySetCapacity(unsigned int newSize)
636611
// first create the new data area
637612
T* newData = 0;
638613
if (newSize > 0) {
639-
640614
#if 1
641615
newData = CXA_new(AB, T, newSize);
642616
#else
643617
cxVoidp mp = AB::alloc(sizeof(T)*newSize);
644618
newData = new(mp) T[newSize];
645619
#endif
646-
647620
if (newData==0) {
648621
return size;
649622
// !!! Change this? to some out-of-mem check or error handler?
@@ -688,7 +661,6 @@ unsigned int cxArrayB<T,AB>::setCapacity(unsigned int newSize)
688661
return size;
689662
}
690663

691-
692664
#else
693665
// Set the capacity of array to exactly newSize. Create new array
694666
// if the new size is different from the requested size, and copy
@@ -738,8 +710,6 @@ unsigned int cxArrayB<T,AB>::setCapacity(unsigned int newSize)
738710
}
739711
#endif
740712

741-
742-
743713
// Set the count and expand the capacity of the array if needed.
744714
template <class T,class AB> void cxArrayB<T,AB>::count(int newCount)
745715
{
@@ -748,7 +718,6 @@ template <class T,class AB> void cxArrayB<T,AB>::count(int newCount)
748718
numElements = newCount;
749719
}
750720

751-
752721
// This increases the array capacity, if needed, by successively doubling
753722
// the current size, until it meets or exceeds the minSize.
754723
template <class T,class AB> void cxArrayB<T,AB>::expandTo(unsigned int minSize)
@@ -814,7 +783,6 @@ template <class T,class AB> void cxArrayB<T,AB>::shift(int idx, int numToShift)
814783
numElements += numToShift;
815784
}
816785

817-
818786
/*
819787
Fill a range of positions with a value.
820788
j points one PAST the last index to be filled.
@@ -844,7 +812,6 @@ void cxArrayB<T,AB>::atDeleteWith(int idx, int numToDel, const T& fillVal)
844812
data[i] = fillVal;
845813
}
846814

847-
848815
//extern void *memmove(void *, const void *, size_t sz);
849816

850817
/* Copy elements from src, from indexes srcStart to srcEnd-1,
@@ -947,7 +914,6 @@ template <class T,class AB> ostream& cxArrayB<T,AB>::dumpOn(ostream& os, unsigne
947914
return os;
948915
}
949916

950-
951917
template <class T,class AB>
952918
void cxArrayB<T,AB>::dumpAll()
953919
{
@@ -965,7 +931,6 @@ void cxArrayB<T,AB>::dump()
965931
this, size, numElements, data);
966932
}
967933

968-
969934
#if !SA_HACK
970935
/*
971936
Search forward from startIdx, up to and not including endIdx,
@@ -1040,8 +1005,6 @@ int cxArrayB<T,AB>::removeFirst(const T& elm)
10401005
}
10411006
#endif
10421007

1043-
1044-
10451008
//----------------------------------------------------------------------
10461009
// class cxArrayIterB implementation
10471010
//----------------------------------------------------------------------
@@ -1107,47 +1070,25 @@ template <class T,class AB> void cxArrayIterB<T,AB>::initIdx(int startIdx)
11071070
}
11081071
}
11091072

1110-
1111-
// *******************************************************
11121073
// template functions
11131074
// Cfront demands these are in a different file,
11141075
// g++ and borland want them in this file.
1115-
// *******************************************************
1116-
1117-
# ifdef __GNUG__
1118-
1076+
#ifdef __GNUG__
11191077
//# include <array.c>
1120-
1121-
# endif
1122-
1123-
# ifndef __GNUG__
1124-
1078+
#else
11251079
template <class VecType, class EleType>
11261080
int binarySearch(VecType data, EleType ele, unsigned int max);
1127-
11281081
template <class T,class AB> void swap( cxArrayB<T,AB> & data, int i, int j);
1129-
11301082
template <class T,class AB> void bubbleSort(cxArrayB<T,AB> & data);
1131-
11321083
template <class T,class AB> void selectionSort(cxArrayB<T,AB> & data);
1133-
11341084
template <class T,class AB> void insertionSort(cxArrayB<T,AB> & data);
1135-
1136-
template <class T,class AB>
1137-
int partition(cxArrayB<T,AB> & v, int low, int high, int pivotIndex);
1138-
1139-
template <class T,class AB>
1140-
T findElement(cxArrayB<T,AB> & v, int N, int low, int high);
1141-
1142-
template <class T,class AB>
1143-
void quackSort(cxArrayB<T,AB> & v, int low, int high);
1144-
1085+
template <class T,class AB> int partition(cxArrayB<T,AB> & v, int low, int high, int pivotIndex);
1086+
template <class T,class AB> T findElement(cxArrayB<T,AB> & v, int N, int low, int high);
1087+
template <class T,class AB> void quackSort(cxArrayB<T,AB> & v, int low, int high);
11451088
template <class T,class AB>
11461089
void quackSort(cxArrayB<T,AB> & v);
1147-
11481090
# endif
11491091

1150-
11511092
/* instantiation of cxArray with allocation from the heap.
11521093
This will probably be most common instantiation.
11531094
*/
@@ -1180,5 +1121,3 @@ class cxArrayIter : public cxArrayIterB<T,cxDefaultAB>
11801121
cxArrayIter(cxArray<T>& anArray, int startIdx)
11811122
: base(anArray, startIdx) {}
11821123
};
1183-
1184-
#endif /* _cxArray_h */

0 commit comments

Comments
 (0)