Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me implement the gather method. This is the solution I got from the previous answer, but it does not work because it did

Please help me implement the gather method. This is the solution I got from the previous answer, but it does not work because it did not implement the gather method. The problem you are asked to solve is implement a gather method for the NullableArray.

image text in transcribed

image text in transcribed

This is the solution:

image text in transcribed

Thanks for your help. I really appreciate it.

Language: C++ Autocomplete Ready O ? 1. NullableArray Gather You are given a templated class NullableArray which is used to represent a 1D array of data whose values can possibly be null. Null values are represented using a least-significant bit (LSB) ordered bitmap where a set bit (1) represents a valid value and an unset bit (0) represents a null value. NullableArray has two members: data which is a vector of type T to hold the values, and nulls which is a vector of type uint8_t to hold the bitmap. 1 > #include 47 template 48 class NullableArray { 49 public: 50 std::vector data; 51 std::vector nulls; 52 53 // Implement the gather method here 54 }; 55 56 57 58 > template ... The problem you are asked to solve is to implement a gather method for the NullableArray class. This method is expected to take a vector of type uint32_t to use as the gather map and returns a new NullableArray of the same type as the calling NullableArray, In the input NullableArray and Gather Map: The data vector's values are undefined when the NullableArray value is null based on the null bitmap The null bitmap's additional bits are undefined when not corresponding to values in the data vector Values in the gather map will never be larger than the size of the input NullableArray In the output NullableArray: The data vector's values should be set to o wherever the output values are null The null bitmap is required to be the minimum size necessary to indicate the corresponding null values The null bitmap is required to have any additional bits not corresponding to values in the data vector be unset (0) template std::vector read_vector(const std::string& input_string) { std::vector output; std::string:: size_type data_start = input_string.find("{"); std::string:: size_type data_end = input_string.find("}"); std::string::Size_type comma_pos; std::string:: size_type next_comma_pos; bool hit_end = false; comma_pos = data_start; while (!hit_end) { next_comma_pos = input_string.find(",", comma_pos + 1); if (next_comma_pos > data_end) { hit_end = true; next_comma_pos = input_string.find("}", comma_pos); } std::string num = input_string. substr(comma_pos + 1, (next_comma_pos - 1 - comma_pos)); if (num. substr(0, 1) == "") { num = num. substr(1); } if (num.size()) { T value = static_cast(std::stoll(num)); output.push_back(value); comma_pos = next_comma_pos; } } return output; } template class NullableArray { public: std::vector data; std::vector nulls; std::vector gather

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions