summaryrefslogtreecommitdiff
path: root/src/BitfieldMan.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-08-22 23:05:06 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-08-22 23:05:06 +0900
commitf7aeb86ccc321889c0695556448c23715fe3686b (patch)
tree9b80a89bf13e10af41430aa1f85bd6c79d8f0a0f /src/BitfieldMan.cc
parent205afd20fdcf19784546cd49b718a69cb3d03ba2 (diff)
Added --download-result option.
Added --download-result=OPT option. This option changes the way "Download Results" is formatted. If OPT is 'default', print GID, status, average download speed and path/URI. If multiple files are involved, path/URI of first requested file is printed and remaining ones are omitted. If OPT is 'full', print GID, status, average download speed, percentage of progress and path/URI. The percentage of progress and path/URI are printed for each requested file in each row.
Diffstat (limited to 'src/BitfieldMan.cc')
-rw-r--r--src/BitfieldMan.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc
index 5535af14..9b1033ab 100644
--- a/src/BitfieldMan.cc
+++ b/src/BitfieldMan.cc
@@ -60,7 +60,7 @@ BitfieldMan::BitfieldMan(size_t blockLength, uint64_t totalLength)
cachedFilteredTotalLength_(0)
{
if(blockLength_ > 0 && totalLength_ > 0) {
- blocks_ = totalLength_/blockLength_+(totalLength_%blockLength_ ? 1 : 0);
+ blocks_ = (totalLength_+blockLength_-1)/blockLength_;
bitfieldLength_ = blocks_/8+(blocks_%8 ? 1 : 0);
bitfield_ = new unsigned char[bitfieldLength_];
useBitfield_ = new unsigned char[bitfieldLength_];
@@ -772,6 +772,39 @@ bool BitfieldMan::isBitSetOffsetRange(uint64_t offset, uint64_t length) const
return true;
}
+uint64_t BitfieldMan::getOffsetCompletedLength
+(uint64_t offset,
+ uint64_t length) const
+{
+ uint64_t res = 0;
+ if(length == 0 || totalLength_ <= offset) {
+ return 0;
+ }
+ if(totalLength_ < offset+length) {
+ length = totalLength_-offset;
+ }
+ size_t start = offset/blockLength_;
+ size_t end = (offset+length-1)/blockLength_;
+ if(start == end) {
+ if(isBitSet(start)) {
+ res = length;
+ }
+ } else {
+ if(isBitSet(start)) {
+ res += (start+1)*blockLength_-offset;
+ }
+ for(size_t i = start+1; i <= end-1; ++i) {
+ if(isBitSet(i)) {
+ res += blockLength_;
+ }
+ }
+ if(isBitSet(end)) {
+ res += offset+length-end*blockLength_;
+ }
+ }
+ return res;
+}
+
uint64_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
{
if(startingIndex < 0 || blocks_ <= startingIndex) {