Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me this question (C++). Question: These are all necessary method for this question: This is solution I got from Chegg, but it does

Please help me this question (C++).

Question:

image text in transcribed

image text in transcribed

image text in transcribed

These are all necessary method for this question:

image text in transcribed

image text in transcribed

This is solution I got from Chegg, but it does not implement the gather method

image text in transcribed

Also, I got this solution but it is wrong way because the question asks us to implement gather method for NullableArray class:

image text in transcribed

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) For example: Given an input NullableArray and Gather Map: data: {1, 2, 3, 4} nulls: {11} //00001011 gather_map: {, 2, , 3, 1} The expected output NullableArray would be: data: (1, 0, 1, 4, 2} nulls: (29) 1/00011101 template void print_nullable_array(const NullableArray& input) { std::cout (EOF)); std::pair, std::vector> input-pair = read_input_data[int32_t>(input_data); const NullableArray my_nullable_array = std::move(input_pair.first); const std::vector gather_map = std::move (input_pair.second); auto output_array = my_nullable_array.gather(gather_map]); std::cout(output_array); return @; v template std::pair, std::vector> read input_data(const std::string& input_string) { std::pair, std::vector cuint32_t>> output; output.first.data = std::move(read_vector(input_string)); std::string::size_type data_end - input_string.find("}"); auto split_string = input_string.substr(data_end + 2); output.first.nulls = std::move(read_vectorsuint8_t> (split_string)); std::string: :size_type nulls_end = input_string.find("}", data_end + 2); split_string = input_string.substr(nulls_end + 2); output. second = std::move (read_vector(split_string)); return output; } + 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; (Answer):- public static int getLength(T[] arr){ int count = 0; for(Tel : arr) if (el != null) ++count; return count; } public static int getUsedLength(string[] arr) { int count = 0; = for (int i = 0; i

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

How effective is each pitch?

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago