// 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. // This file is copied from // https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/formatIPv6.cpp // and modified by Doris #include "vec/common/format_ip.h" #include #include #include "vec/core/types.h" namespace doris::vectorized { /** Further we want to generate constexpr array of strings with sizes from sequence of unsigned ints [0..N) * in order to use this arrey for fast conversion of unsigned integers to strings */ namespace detail { template struct ToChars { static const char value[]; static const size_t size; }; template constexpr char ToChars::value[] = {('0' + digits)..., 0}; template constexpr size_t ToChars::size = sizeof...(digits); template struct Decompose : Decompose {}; template struct Decompose<0, digits...> : ToChars {}; template <> struct Decompose<0> : ToChars<0> {}; template struct NumToString : Decompose {}; template consteval std::array, sizeof...(ints)> str_make_array_impl( std::integer_sequence) { return std::array, sizeof...(ints)> { std::pair {NumToString::value, NumToString::size}...}; } } // namespace detail /** str_make_array() - generates static array of std::pair for numbers [0..N), where: * first - null-terminated string representing number * second - size of the string as would returned by strlen() */ template consteval std::array, N> str_make_array() { return detail::str_make_array_impl(std::make_integer_sequence {}); } /// This will generate static array of pair for [0..255] at compile time extern constexpr std::array, 256> one_byte_to_string_lookup_table = str_make_array<256>(); } // namespace doris::vectorized