42 #define SORT_DEBUG if(0) 93 template<
class T,
class Compare>
96 int deleteInputStream = 0)
100 off_t instreamLength;
102 assert(instream && outstream && cmp);
105 if (instreamLength == 0) {
107 if (deleteInputStream) {
114 instream->
name(&name);
115 cout <<
"AMI_sort: sorting stream" << name <<
", len=" 116 << instreamLength << endl;
125 if (deleteInputStream) {
129 if(runList->
length() == 0) {
131 fprintf(stderr,
"ami_sort: Error - no runs created!\n");
132 instream->
name(&name);
133 cout <<
"ami_sort: instream = " << name << endl;
138 }
else if(runList->
length() == 1) {
147 *outstream = multiMerge<T,Compare>(runList, cmp);
156 cout <<
"AMI_sort: done" << endl << endl;
161 assert((*outstream)->stream_len() == instreamLength);
168 template<
class T,
class Compare>
180 cout <<
"reading: " << *crt << endl;
184 cout <<
"reading: " << *crt << endl;
185 if (cmp.compare(*prev, *crt) != -1)
195 #endif // _AMI_SORT_H AMI_err read_item(T **elt)
int isSorted(AMI_STREAM< T > *str, Compare cmp)
unsigned int length() const
AMI_err seek(off_t offset)
queue< char * > * runFormation(AMI_STREAM< T > *instream, Compare *cmp)
#define assert(condition)
AMI_err name(char **stream_name)
AMI_err AMI_sort(AMI_STREAM< T > *instream, AMI_STREAM< T > **outstream, Compare *cmp, int deleteInputStream=0)