84 unsigned long maxsize;
98 im_buffer(
long n): maxsize(n), size(0), sorted(false) {
102 sprintf(str,
"im_buffer: allocate %ld\n",(
long)(maxsize*
sizeof(T)));
105 data =
new T[maxsize];
114 if (data)
delete [] data;
121 unsigned long insert(T*x,
unsigned long n);
134 bool is_full()
const {
return (size == maxsize);}
141 assert((i>=0) && (i < size));
153 assert((i>=0) && (i < size));
175 void reset(
unsigned long start,
unsigned long n);
183 for (
int i=0; i < b.size; i++) {
184 s << b.data[i] <<
", ";
198 void sort_rec(
unsigned long start,
unsigned long end);
201 unsigned long partition(
unsigned long start,
unsigned long end);
211 MEMORY_LOG(
"im_buffer: copy constructor start\n");
216 for (
unsigned long i=0; i<size; i++) {
219 MEMORY_LOG(
"im_buffer: copy constructor end\n");
228 if (size == maxsize) {
233 data =
new T [maxsize];
251 for (
unsigned long i=0; i<n; i++) {
272 qsort((T*)data, size,
sizeof(T), T::qscompare);
284 q = partition(start, end);
295 assert((start <= end) && (end < size) && (start >=0));
299 T pivot =
get_item(start), lit, rit;
300 unsigned long l = start - 1,
r = end + 1;
337 assert((start >= 0) && (start + n <= size));
340 memmove(data, data + start, n*
sizeof(T));
353 memmove(data, data + n, (size-n)*
sizeof(T));
369 data =
new T [maxsize];
381 for (
int i=1; i < size; i++) {
392 cout << min.getPriority() <<
".." 393 << max.getPriority();
394 cout <<
" (sz=" << size <<
")";
405 for (
unsigned long i=0; i < size; i++) {
406 cout << data[i].getPriority() <<
",";
425 for (
unsigned long i=0; i< size; i++) {
AMI_err write_item(const T &elt)
T get_item(unsigned long i) const
#define assert(condition)
void set_item(unsigned long i, T &item)
unsigned long get_buf_len() const
void MEMORY_LOG(const std::string &str)
unsigned long get_buf_maxlen() const
AMI_STREAM< T > * save2str() const
void shift_left(unsigned long n)
friend ostream & operator<<(ostream &s, const im_buffer &b)