2018-11-11 12:38:04 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
2018-12-26 17:11:15 +01:00
|
|
|
|
2018-11-11 12:38:04 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
|
|
|
namespace td {
|
2018-12-26 17:11:15 +01:00
|
|
|
|
2018-11-11 12:38:04 +01:00
|
|
|
class Bitmask {
|
|
|
|
public:
|
|
|
|
struct Decode {};
|
|
|
|
struct Ones {};
|
|
|
|
Bitmask() = default;
|
|
|
|
Bitmask(Decode, Slice data);
|
|
|
|
Bitmask(Ones, int64 count);
|
2018-12-27 10:12:24 +01:00
|
|
|
std::string encode(int32 prefix_count = -1) const;
|
2018-12-26 17:11:15 +01:00
|
|
|
int64 get_ready_prefix_size(int64 offset, int64 part_size, int64 file_size) const;
|
2018-12-27 09:34:36 +01:00
|
|
|
int64 get_total_size(int64 part_size, int64 file_size) const;
|
2018-12-26 17:11:15 +01:00
|
|
|
bool get(int64 offset_part) const;
|
2018-11-11 12:38:04 +01:00
|
|
|
|
2018-12-26 17:11:15 +01:00
|
|
|
int64 get_ready_parts(int64 offset_part) const;
|
2018-11-11 12:38:04 +01:00
|
|
|
|
|
|
|
std::vector<int32> as_vector() const;
|
2018-12-26 17:11:15 +01:00
|
|
|
void set(int64 offset_part);
|
2018-11-11 12:38:04 +01:00
|
|
|
int64 size() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline StringBuilder &operator<<(StringBuilder &sb, const Bitmask &mask) {
|
|
|
|
for (int64 i = 0; i < mask.size(); i++) {
|
2018-12-26 17:11:15 +01:00
|
|
|
sb << (mask.get(i) ? '1' : '0');
|
2018-11-11 12:38:04 +01:00
|
|
|
}
|
2018-12-26 17:11:15 +01:00
|
|
|
return sb;
|
2018-11-11 12:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|