<commit_before>#include "libtorrent/piece_picker.hpp"
#include "libtorrent/policy.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <algorithm>
#include <vector>

#include "test.hpp"

using namespace libtorrent;

std::vector<bool> string2vec(char const* have_str)
{
	const int num_pieces = strlen(have_str);
	std::vector<bool> have(num_pieces, false);
	for (int i = 0; i < num_pieces; ++i)
		if (have_str[i] != ' ')  have[i] = true;
	return have;
}

// availability is a string where each character is the
// availability of that piece, '1', '2' etc.
// have_str is a string where each character represents a
// piece, ' ' means we don't have the piece and any other
// character means we have it
boost::shared_ptr<piece_picker> setup_picker(
	char const* availability
	, char const* have_str
	, char const* priority
	, char const* partial)
{
	const int blocks_per_piece = 4;
	const int num_pieces = strlen(availability);
	assert(int(strlen(have_str)) == num_pieces);

	boost::shared_ptr<piece_picker> p(new piece_picker(blocks_per_piece, num_pieces * blocks_per_piece));

	std::vector<bool> have = string2vec(have_str);

	std::vector<piece_picker::downloading_piece> unfinished;
	piece_picker::downloading_piece pp;
	piece_picker::block_info blocks[blocks_per_piece * num_pieces];

	for (int i = 0; i < num_pieces; ++i)
	{
		if (partial[i] == 0) break;

		pp.index = i;
		pp.info = blocks + i * blocks_per_piece;

		if (partial[i] == ' ') continue;
		int blocks = 0;
		if (partial[i] >= '0' && partial[i] <= '9')
			blocks = partial[i] - '0';
		else
			blocks = partial[i] - 'a' + 10;

		if (blocks & 1)
			pp.info[0].state = piece_picker::block_info::state_finished;
		if (blocks & 2)
			pp.info[1].state = piece_picker::block_info::state_finished;
		if (blocks & 4)
			pp.info[2].state = piece_picker::block_info::state_finished;
		if (blocks & 8)
			pp.info[3].state = piece_picker::block_info::state_finished;
		unfinished.push_back(pp);<commit_msg>fixed piece_picker test<commit_after>#include "libtorrent/piece_picker.hpp"
#include "libtorrent/policy.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <algorithm>
#include <vector>

#include "test.hpp"

using namespace libtorrent;

std::vector<bool> string2vec(char const* have_str)
{
	const int num_pieces = strlen(have_str);
	std::vector<bool> have(num_pieces, false);
	for (int i = 0; i < num_pieces; ++i)
		if (have_str[i] != ' ')  have[i] = true;
	return have;
}

// availability is a string where each character is the
// availability of that piece, '1', '2' etc.
// have_str is a string where each character represents a
// piece, ' ' means we don't have the piece and any other
// character means we have it
boost::shared_ptr<piece_picker> setup_picker(
	char const* availability
	, char const* have_str
	, char const* priority
	, char const* partial)
{
	const int blocks_per_piece = 4;
	const int num_pieces = strlen(availability);
	assert(int(strlen(have_str)) == num_pieces);

	boost::shared_ptr<piece_picker> p(new piece_picker(blocks_per_piece, num_pieces * blocks_per_piece));

	std::vector<bool> have = string2vec(have_str);

	std::vector<piece_picker::downloading_piece> unfinished;
	piece_picker::downloading_piece pp;
	std::vector<piece_picker::block_info> blocks(blocks_per_piece * num_pieces);

	for (int i = 0; i < num_pieces; ++i)
	{
		if (partial[i] == 0) break;

		if (partial[i] == ' ') continue;
		pp.index = i;
		pp.info = &blocks[i * blocks_per_piece];

		int blocks = 0;
		if (partial[i] >= '0' && partial[i] <= '9')
			blocks = partial[i] - '0';
		else
			blocks = partial[i] - 'a' + 10;

		if (blocks & 1)
			pp.info[0].state = piece_picker::block_info::state_finished;
		if (blocks & 2)
			pp.info[1].state = piece_picker::block_info::state_finished;
		if (blocks & 4)
			pp.info[2].state = piece_picker::block_info::state_finished;
		if (blocks & 8)
			pp.info[3].state = piece_picker::block_info::state_finished;
		unfinished.push_back(pp);
{'fraction_non_alphanumeric': 0.14389937106918238, 'fraction_numerical': 0.011069182389937107, 'mean_word_length': 4.890370370370371, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6582717', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1402, 'n_words': 354}