Question: Please help me implement gather method. Thank you very much. For example: Given an input NullableArray and Gather Map: data: {1,2,3,4} nulls: {11} //00001011 gather_map:

Please help me implement gather method. Thank you very much.

Please help me implement gather method. Thank you very much. For example:

Given an input NullableArray and Gather Map: data: {1,2,3,4} nulls: {11} //00001011

For example: Given an input NullableArray and Gather Map:

data: {1,2,3,4}

nulls: {11} //00001011

gather_map: {0,2,0,3,1}

The expected output NullableArray would be:

data: {1,0,1,4,2}

nulls: {29} //00011101

This is solution I got from the previous question, but it does not implement gather method.

gather_map: {0,2,0,3,1} The expected output NullableArray would be: data: {1,0,1,4,2} nulls: {29}

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!