Commit 1239c6ca authored by Stanislav Bohm's avatar Stanislav Bohm

RF: DataVector refactored

parent 1489cf96
......@@ -15,7 +15,7 @@ namespace loom {
class Worker;
class Data;
typedef std::vector<std::shared_ptr<Data>*> DataVector;
typedef std::vector<std::shared_ptr<Data>> DataVector;
/** Base class for task instance - an actual state of computation of a task */
class TaskInstance
......
......@@ -9,7 +9,7 @@ void ArrayMakeTask::start(DataVector &inputs)
size_t size = inputs.size();
auto items = std::make_unique<std::shared_ptr<Data>[]>(size);
for (size_t i = 0; i < size; i++) {
items[i] = *(inputs[i]);
items[i] = inputs[i];
}
std::shared_ptr<Data> output = std::make_shared<Array>(size, std::move(items));
finish(output);
......
......@@ -11,7 +11,7 @@ void GetTask::start(DataVector &inputs)
assert(inputs.size() == 1);
assert(task->get_config().size() == sizeof(size_t));
const size_t *index = reinterpret_cast<const size_t*>(task->get_config().data());
std::shared_ptr<Data> &input = *(inputs[0]);
std::shared_ptr<Data> &input = inputs[0];
auto result = input->get_at_index(*index);
finish(result);
}
......@@ -21,7 +21,7 @@ void SliceTask::start(DataVector &inputs)
assert(inputs.size() == 1);
assert(task->get_config().size() == sizeof(size_t) * 2);
const size_t *index = reinterpret_cast<const size_t*>(task->get_config().data());
std::shared_ptr<Data> &input = *(inputs[0]);
std::shared_ptr<Data> &input = inputs[0];
auto result = input->get_slice(index[0], index[1]);
finish(result);
}
......@@ -30,7 +30,7 @@ void SizeTask::start(DataVector &inputs)
{
size_t size = 0;
for (auto &d : inputs) {
size += (*d)->get_size();
size += d->get_size();
}
std::shared_ptr<Data> output = std::make_shared<RawData>();
RawData &data = static_cast<RawData&>(*output);
......@@ -42,7 +42,7 @@ void LengthTask::start(DataVector &inputs)
{
size_t length = 0;
for (auto &d : inputs) {
length += (*d)->get_length();
length += d->get_length();
}
std::shared_ptr<Data> output = std::make_shared<RawData>();
RawData &data = static_cast<RawData&>(*output);
......
......@@ -29,7 +29,7 @@ bool MergeTask::run_in_thread(DataVector &input_data)
}
size_t size = 0;
for (auto& data : inputs) {
size += (*data)->get_size();
size += data->get_size();
if (size > 20000) {
return true;
}
......@@ -40,7 +40,7 @@ bool MergeTask::run_in_thread(DataVector &input_data)
std::shared_ptr<Data> MergeTask::run() {
size_t size = 0;
for (auto& data : inputs) {
size += (*data)->get_size();
size += data->get_size();
}
std::shared_ptr<Data> output = std::make_shared<RawData>();
RawData &data = static_cast<RawData&>(*output);
......@@ -48,8 +48,8 @@ std::shared_ptr<Data> MergeTask::run() {
char *dst = output->get_raw_data(worker);
for (auto& data : inputs) {
char *mem = (*data)->get_raw_data(worker);
size_t size = (*data)->get_size();
char *mem = data->get_raw_data(worker);
size_t size = data->get_size();
assert(mem || size == 0);
memcpy(dst, mem, size);
dst += size;
......@@ -69,7 +69,7 @@ void SplitTask::start(DataVector &inputs)
char split_char = '\n';
std::vector<size_t> indices;
auto input = *inputs[0];
auto& input = inputs[0];
char *ptr = input->get_raw_data(worker);
size_t size = input->get_size();
......
......@@ -69,9 +69,8 @@ void RunTask::start(DataVector &inputs)
assert(msg.map_inputs_size() <= static_cast<int>(inputs.size()));
for (int i = 0; i < msg.map_inputs_size(); i++) {
auto& input = *inputs[i];
std::string path = get_path(msg.map_inputs(i));
std::string filename = input->get_filename();
std::string filename = inputs[i]->get_filename();
assert(!filename.empty());
llog->debug("Creating symlink of '{}'", msg.map_inputs(i));
if (symlink(filename.c_str(), path.c_str())) {
......
......@@ -199,7 +199,7 @@ void Worker::start_task(std::unique_ptr<Task> task)
DataVector input_data;
for (Id id : t->get_inputs()) {
input_data.push_back(&get_data(id));
input_data.push_back(get_data(id));
}
t->start(input_data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment