ademakov commented on code in PR #988: URL: https://github.com/apache/ignite-3/pull/988#discussion_r941157059
########## modules/platforms/cpp/schema/BinaryTupleBuilder.h: ########## @@ -0,0 +1,378 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "BinaryTupleSchema.h" +#include "common/Types.h" + +#include <cassert> +#include <cstring> + +namespace ignite { + +/** + * @brief Binary tuple builder. + * + * A tuple builder is used to create one or more binary tuples for a given schema. + * + * Building a tuple takes two passes. On the first pass the builder finds the tuple + * layout. On the second pass it actually fills the tuple data. + * + * More precisely a tuple is built with the following call sequence: + * + * 1. Initialize the builder with the @ref start call. + * 2. Supply all elements with one or more @ref claim calls in the order that + * corresponds to the tuple schema. + * 3. Determine tuple layout with the @ref layout call. + * 4. Supply all elements again with one or more @ref append calls in the same + * order with the same values. + * 5. Finally, the resulting binary tuple is obtained with the @ref build call. + */ +class BinaryTupleBuilder { + IntT elementCount; /**< Total number of elements. */ + + IntT elementIndex; /**< Index of the next element to add. */ + + IntT nullElements; /**< The number of null elements. */ + + SizeT valueAreaSize; /**< Total size of all values. */ + + SizeT entrySize; /**< Size of an offset table entry. */ + + std::byte *nextEntry; /**< Position for the next offset table entry. */ + + std::byte *valueBase; /**< Position of the value area.*/ + + std::byte *nextValue; /**< Position for the next value. */ + + std::vector<std::byte> binaryTuple; /**< Internal buffer for tuple generation. */ + +public: + /** + * @brief constructs a new Tuple Builder object + * + * @param schema Binary tuple schema. + */ + explicit BinaryTupleBuilder(IntT elementCount) noexcept; + + /** + * @brief starts a new tuple + */ + void start() noexcept; + + /** + * @brief assigns a null value for the next element + */ + void claim(std::nullopt_t /*null*/) noexcept { Review Comment: Usually small functions go to headers for take advantage of inlining. Function templates go to headers even if they are not small. In some cases you might want to use a header-only library for very basic stuff. Here some code is copied from another (private) repo and not yet fully converted to a uniform style. I'm going to fix a couple of such issues now. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
