75 unsigned long maxsize;
89 im_buffer(
long n) : maxsize(n), size(0), sorted(false)
94 snprintf(str,
sizeof(str),
"im_buffer: allocate %ld\n",
95 (
long)(maxsize *
sizeof(T)));
98 data =
new T[maxsize];
116 unsigned long insert(T *
x,
unsigned long n);
129 bool is_full()
const {
return (size == maxsize); }
150 assert((i >= 0) && (i < size));
174 void reset(
unsigned long start,
unsigned long n);
183 for (
int i = 0; i <
b.size; i++) {
184 s <<
b.data[i] <<
", ";
197 void sort_rec(
unsigned long start,
unsigned long end);
200 unsigned long partition(
unsigned long start,
unsigned long end);
209 MEMORY_LOG(
"im_buffer: copy constructor start\n");
214 for (
unsigned long i = 0; i < size; i++) {
217 MEMORY_LOG(
"im_buffer: copy constructor end\n");
226 if (size == maxsize) {
231 data =
new T[maxsize];
249 for (
unsigned long i = 0; i < n; i++) {
270 qsort((T *)data, size,
sizeof(T), T::qscompare);
284 sort_rec(q + 1, end);
294 assert((start <= end) && (end < size) && (start >= 0));
298 T pivot = get_item(start), lit, rit;
299 unsigned long l = start - 1,
r = end + 1;
305 }
while (get_item(
r) > pivot);
309 }
while (get_item(
l) < pivot);
337 assert(start + n <= size);
340 memmove(data, data + start, n *
sizeof(T));
353 memmove(data, data + n, (size - n) *
sizeof(T));
370 data =
new T[maxsize];
383 for (
int i = 1; i < size; i++) {
394 cout <<
min.getPriority() <<
".." <<
max.getPriority();
395 cout <<
" (sz=" << size <<
")";
406 for (
unsigned long i = 0; i < size; i++) {
407 cout << data[i].getPriority() <<
",";
425 for (
unsigned long i = 0; i < size; i++) {
AMI_err write_item(const T &elt)
void set_item(unsigned long i, T &item)
void shift_left(unsigned long n)
AMI_STREAM< T > * save2str() const
T get_item(unsigned long i) const
unsigned long get_buf_maxlen() const
friend ostream & operator<<(ostream &s, const im_buffer &b)
unsigned long get_buf_len() const
#define assert(condition)
void MEMORY_LOG(const std::string &str)
void partition(T *data, size_t n, size_t &pivot, CMPR &cmp)