MCPcopy Create free account
hub / github.com/Parchive/par2cmdline / ComputeBlockSize

Method ComputeBlockSize

src/commandline.cpp:1246–1343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1244
1245
1246bool CommandLine::ComputeBlockSize() {
1247
1248 if (blocksize == 0) {
1249 // compute value from blockcount
1250
1251 if (blockcount < extrafiles.size())
1252 {
1253 // The block count cannot be less than the number of files.
1254
1255 std::cerr << "Block count (" << blockcount <<
1256 ") cannot be smaller than the number of files(" << extrafiles.size() << "). " << std::endl;
1257 return false;
1258 }
1259 else if (blockcount == extrafiles.size())
1260 {
1261 // If the block count is the same as the number of files, then the block
1262 // size is the size of the largest file (rounded up to a multiple of 4).
1263
1264 u64 largestfilesize = 0;
1265 for (std::vector<std::string>::const_iterator i=extrafiles.begin(); i!=extrafiles.end(); i++)
1266 {
1267 u64 filesize = filesize_cache.get(*i);
1268 if (filesize > largestfilesize)
1269 {
1270 largestfilesize = filesize;
1271 }
1272 }
1273 blocksize = (largestfilesize + 3) & ~3;
1274 }
1275 else
1276 {
1277 u64 totalsize = 0;
1278 for (std::vector<std::string>::const_iterator i=extrafiles.begin(); i!=extrafiles.end(); i++)
1279 {
1280 totalsize += (filesize_cache.get(*i) + 3) / 4;
1281 }
1282
1283 if (blockcount > totalsize)
1284 {
1285 blocksize = 4;
1286 }
1287 else
1288 {
1289 // Absolute lower bound and upper bound on the source block size that will
1290 // result in the requested source block count.
1291 u64 lowerBound = totalsize / blockcount;
1292 u64 upperBound = (totalsize + blockcount - extrafiles.size() - 1) / (blockcount - extrafiles.size());
1293
1294 u64 count = 0;
1295 u64 size;
1296
1297 do
1298 {
1299 size = (lowerBound + upperBound)/2;
1300
1301 count = 0;
1302 for (std::vector<std::string>::const_iterator i=extrafiles.begin(); i!=extrafiles.end(); i++)
1303 {

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected