46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
@q $Id: fine_container.cweb 1833 2008-05-18 20:22:39Z kamenik $ @>
|
|
@q Copyright 2005, Ondra Kamenik @>
|
|
|
|
@ Start of {\tt stack\_container.cpp} file.
|
|
|
|
@c
|
|
#include "fine_container.h"
|
|
|
|
#include <cmath>
|
|
|
|
@<|SizeRefinement| constructor code@>;
|
|
|
|
@ Here we construct the vector of new sizes of containers (before
|
|
|nc|) and copy all remaining sizes behind |nc|.
|
|
|
|
@<|SizeRefinement| constructor code@>=
|
|
SizeRefinement::SizeRefinement(const IntSequence& s, int nc, int max)
|
|
{
|
|
new_nc = 0;
|
|
for (int i = 0; i < nc; i++) {
|
|
int nr = s[i]/max;
|
|
if (s[i] % max != 0)
|
|
nr++;
|
|
#ifndef _MSC_VER
|
|
int ss = (nr>0) ? (int)round(((double)s[i])/nr) : 0;
|
|
#else // MSVC doesn't respect C99 standard and doesn't define round(); use floor(x+0.5) instead
|
|
int ss = (nr>0) ? (int)floor((((double)s[i])/nr) + 0.5) : 0;
|
|
#endif
|
|
for (int j = 0; j < nr - 1; j++) {
|
|
rsizes.push_back(ss);
|
|
ind_map.push_back(i);
|
|
new_nc++;
|
|
}
|
|
rsizes.push_back(s[i]-(nr-1)*ss);
|
|
ind_map.push_back(i);
|
|
new_nc++;
|
|
}
|
|
|
|
for (int i = nc; i < s.size(); i++) {
|
|
rsizes.push_back(s[i]);
|
|
ind_map.push_back(i);
|
|
}
|
|
}
|
|
|
|
@ End of {\tt stack\_container.cpp} file.
|