summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <[email protected]>2025-10-06 18:10:38 +0300
committervvvv <[email protected]>2025-10-06 18:31:49 +0300
commit661b176173dc1b3773c7739fa917a49f49d89378 (patch)
tree30aa9a71ea9016436c841da32c76568689c3fefa
parent2608f5acf0d8ae86b0d668b33262fa6a6b3baefc (diff)
YQL-20086 types
init commit_hash:f9e4bd83d745532d51e4440381d9cfb73d8b64d3
-rw-r--r--yql/essentials/types/binary_json/format.h2
-rw-r--r--yql/essentials/types/binary_json/read.cpp12
-rw-r--r--yql/essentials/types/binary_json/read.h6
-rw-r--r--yql/essentials/types/binary_json/ut/container_ut.cpp33
-rw-r--r--yql/essentials/types/binary_json/ut/entry_ut.cpp21
-rw-r--r--yql/essentials/types/binary_json/ut/identity_ut.cpp40
-rw-r--r--yql/essentials/types/binary_json/ut/valid_ut.cpp8
-rw-r--r--yql/essentials/types/binary_json/ut/ya.make2
-rw-r--r--yql/essentials/types/binary_json/ut_benchmark/write.cpp18
-rw-r--r--yql/essentials/types/binary_json/ut_benchmark/ya.make2
-rw-r--r--yql/essentials/types/binary_json/write.cpp11
-rw-r--r--yql/essentials/types/binary_json/write.h5
-rw-r--r--yql/essentials/types/dynumber/cast.h2
-rw-r--r--yql/essentials/types/dynumber/dynumber.cpp134
-rw-r--r--yql/essentials/types/dynumber/dynumber.h2
-rw-r--r--yql/essentials/types/dynumber/ut/dynumber_ut.cpp316
-rw-r--r--yql/essentials/types/dynumber/ut/ya.make2
-rw-r--r--yql/essentials/types/dynumber/ya.make2
-rw-r--r--yql/essentials/types/uuid/uuid.cpp8
-rw-r--r--yql/essentials/types/uuid/uuid.h21
-rw-r--r--yql/essentials/types/uuid/ya.make2
21 files changed, 345 insertions, 304 deletions
diff --git a/yql/essentials/types/binary_json/format.h b/yql/essentials/types/binary_json/format.h
index 36479ba68d8..a10d3d62c53 100644
--- a/yql/essentials/types/binary_json/format.h
+++ b/yql/essentials/types/binary_json/format.h
@@ -139,4 +139,4 @@ static_assert(sizeof(TMeta) == sizeof(ui32));
*/
using TBinaryJson = TBuffer;
-} \ No newline at end of file
+} // namespace NKikimr::NBinaryJson
diff --git a/yql/essentials/types/binary_json/read.cpp b/yql/essentials/types/binary_json/read.cpp
index 2d4b40c04b8..d31a4f854cc 100644
--- a/yql/essentials/types/binary_json/read.cpp
+++ b/yql/essentials/types/binary_json/read.cpp
@@ -152,13 +152,11 @@ TBinaryJsonReader::TBinaryJsonReader(TStringBuf buffer)
Y_ENSURE(
Header_.Version == CURRENT_VERSION,
TStringBuilder() << "Version in BinaryJson `" << static_cast<ui64>(Header_.Version) << "` "
- << "does not match current version `" << static_cast<ui64>(CURRENT_VERSION) << "`"
- );
+ << "does not match current version `" << static_cast<ui64>(CURRENT_VERSION) << "`");
Y_ENSURE(
Header_.StringOffset < Buffer_.size(),
- "StringOffset must be inside buffer"
- );
+ "StringOffset must be inside buffer");
// Tree starts right after Header
TreeStart_ = sizeof(Header_);
@@ -324,7 +322,7 @@ void ReadContainerToJson(const TContainerCursor& cursor, TJsonWriter& writer) {
}
}
-}
+} // namespace
TString SerializeToJson(const TBinaryJson& binaryJson) {
return SerializeToJson(TStringBuf(binaryJson.Data(), binaryJson.Size()));
@@ -575,7 +573,7 @@ private:
TStringBuf Buffer_;
};
-}
+} // namespace
TMaybe<TStringBuf> IsValidBinaryJsonWithError(TStringBuf buffer) {
return TBinaryJsonValidator(buffer).ValidateWithError();
@@ -585,4 +583,4 @@ bool IsValidBinaryJson(TStringBuf buffer) {
return !IsValidBinaryJsonWithError(buffer).Defined();
}
-}
+} // namespace NKikimr::NBinaryJson
diff --git a/yql/essentials/types/binary_json/read.h b/yql/essentials/types/binary_json/read.h
index 5bdeac34fb7..879f0e0a36f 100644
--- a/yql/essentials/types/binary_json/read.h
+++ b/yql/essentials/types/binary_json/read.h
@@ -17,7 +17,7 @@ class TContainerCursor;
* @brief Reads values inside BinaryJson. `Read...` methods of this class are not intended for direct use.
* Consider using `GetRootCursor` method to get more convenient interface over BinaryJson data
*/
-class TBinaryJsonReader : public TSimpleRefCount<TBinaryJsonReader> {
+class TBinaryJsonReader: public TSimpleRefCount<TBinaryJsonReader> {
public:
template <typename... Args>
static TIntrusivePtr<TBinaryJsonReader> Make(Args&&... args) {
@@ -55,7 +55,7 @@ private:
T ReadPOD(ui32 offset) const {
static_assert(std::is_pod_v<T>, "Type must be POD");
Y_ENSURE(offset + sizeof(T) <= Buffer_.size(),
- TStringBuilder() << "Not enough space in buffer to read value (" << offset << " + " << sizeof(T) << " > " << Buffer_.size() << ")");
+ TStringBuilder() << "Not enough space in buffer to read value (" << offset << " + " << sizeof(T) << " > " << Buffer_.size() << ")");
return ReadUnaligned<T>(Buffer_.data() + offset);
}
@@ -187,4 +187,4 @@ bool IsValidBinaryJson(TStringBuf buffer);
TMaybe<TStringBuf> IsValidBinaryJsonWithError(TStringBuf buffer);
-}
+} // namespace NKikimr::NBinaryJson
diff --git a/yql/essentials/types/binary_json/ut/container_ut.cpp b/yql/essentials/types/binary_json/ut/container_ut.cpp
index 869d2323bdd..8c3b05146a5 100644
--- a/yql/essentials/types/binary_json/ut/container_ut.cpp
+++ b/yql/essentials/types/binary_json/ut/container_ut.cpp
@@ -5,7 +5,7 @@
using namespace NKikimr::NBinaryJson;
-class TBinaryJsonContainerTest : public TBinaryJsonTestBase {
+class TBinaryJsonContainerTest: public TBinaryJsonTestBase {
public:
TBinaryJsonContainerTest()
: TBinaryJsonTestBase()
@@ -13,12 +13,12 @@ public:
}
UNIT_TEST_SUITE(TBinaryJsonContainerTest);
- UNIT_TEST(TestGetType);
- UNIT_TEST(TestGetSize);
- UNIT_TEST(TestGetElement);
- UNIT_TEST(TestArrayIterator);
- UNIT_TEST(TestLookup);
- UNIT_TEST(TestObjectIterator);
+ UNIT_TEST(TestGetType);
+ UNIT_TEST(TestGetSize);
+ UNIT_TEST(TestGetElement);
+ UNIT_TEST(TestArrayIterator);
+ UNIT_TEST(TestLookup);
+ UNIT_TEST(TestObjectIterator);
UNIT_TEST_SUITE_END();
void TestGetType() {
@@ -174,15 +174,16 @@ public:
"five": "string",
"six": [],
"seven": {}
- })", {
- {"one", "123"},
- {"two", "null"},
- {"three", "false"},
- {"four", "true"},
- {"five", "\"string\""},
- {"six", "[]"},
- {"seven", "{}"},
- }},
+ })",
+ {
+ {"one", "123"},
+ {"two", "null"},
+ {"three", "false"},
+ {"four", "true"},
+ {"five", "\"string\""},
+ {"six", "[]"},
+ {"seven", "{}"},
+ }},
};
for (const auto& testCase : testCases) {
diff --git a/yql/essentials/types/binary_json/ut/entry_ut.cpp b/yql/essentials/types/binary_json/ut/entry_ut.cpp
index 247fc5034cf..84047333cb4 100644
--- a/yql/essentials/types/binary_json/ut/entry_ut.cpp
+++ b/yql/essentials/types/binary_json/ut/entry_ut.cpp
@@ -5,7 +5,7 @@
using namespace NKikimr::NBinaryJson;
-class TBinaryJsonEntryTest : public TBinaryJsonTestBase {
+class TBinaryJsonEntryTest: public TBinaryJsonTestBase {
public:
TBinaryJsonEntryTest()
: TBinaryJsonTestBase()
@@ -13,11 +13,11 @@ public:
}
UNIT_TEST_SUITE(TBinaryJsonEntryTest);
- UNIT_TEST(TestGetType);
- UNIT_TEST(TestGetContainer);
- UNIT_TEST(TestGetString);
- UNIT_TEST(TestGetNumber);
- UNIT_TEST(TestOutOfBounds);
+ UNIT_TEST(TestGetType);
+ UNIT_TEST(TestGetContainer);
+ UNIT_TEST(TestGetString);
+ UNIT_TEST(TestGetNumber);
+ UNIT_TEST(TestOutOfBounds);
UNIT_TEST_SUITE_END();
void TestGetType() {
@@ -97,10 +97,10 @@ public:
void TestOutOfBounds() {
const TVector<std::pair<TString, double>> testCases = {
- { "1e100000000", std::numeric_limits<double>::infinity() },
- { "-1e100000000", -std::numeric_limits<double>::infinity() },
- { "1.797693135e+308", std::numeric_limits<double>::infinity() },
- { "-1.797693135e+308", -std::numeric_limits<double>::infinity() },
+ {"1e100000000", std::numeric_limits<double>::infinity()},
+ {"-1e100000000", -std::numeric_limits<double>::infinity()},
+ {"1.797693135e+308", std::numeric_limits<double>::infinity()},
+ {"-1.797693135e+308", -std::numeric_limits<double>::infinity()},
};
for (const auto& testCase : testCases) {
@@ -118,4 +118,3 @@ public:
};
UNIT_TEST_SUITE_REGISTRATION(TBinaryJsonEntryTest);
-
diff --git a/yql/essentials/types/binary_json/ut/identity_ut.cpp b/yql/essentials/types/binary_json/ut/identity_ut.cpp
index 4179293287b..025024d2b3f 100644
--- a/yql/essentials/types/binary_json/ut/identity_ut.cpp
+++ b/yql/essentials/types/binary_json/ut/identity_ut.cpp
@@ -7,7 +7,7 @@
using namespace NKikimr;
-class TBinaryJsonIdentityTest : public TBinaryJsonTestBase {
+class TBinaryJsonIdentityTest: public TBinaryJsonTestBase {
public:
TBinaryJsonIdentityTest()
: TBinaryJsonTestBase()
@@ -15,28 +15,28 @@ public:
}
UNIT_TEST_SUITE(TBinaryJsonIdentityTest);
- UNIT_TEST(TestReadToJsonDom);
- UNIT_TEST(TestSerializeToJson);
- UNIT_TEST(TestSerializeDomToBinaryJson);
+ UNIT_TEST(TestReadToJsonDom);
+ UNIT_TEST(TestSerializeToJson);
+ UNIT_TEST(TestSerializeDomToBinaryJson);
UNIT_TEST_SUITE_END();
const TVector<TString> TestCases = {
- "false",
- "true",
- "null",
- "\"test string\"",
- "\"\"",
- "1.2345",
- "1",
- "-23",
- "0",
- "0.12345",
- "{}",
- "{\"a\":1}",
- "[]",
- "[1]",
- R"([{"key":[true,false,null,"first","second","second","third"]},"fourth",0.34])",
- };
+ "false",
+ "true",
+ "null",
+ "\"test string\"",
+ "\"\"",
+ "1.2345",
+ "1",
+ "-23",
+ "0",
+ "0.12345",
+ "{}",
+ "{\"a\":1}",
+ "[]",
+ "[1]",
+ R"([{"key":[true,false,null,"first","second","second","third"]},"fourth",0.34])",
+ };
void TestReadToJsonDom() {
for (const TStringBuf json : TestCases) {
diff --git a/yql/essentials/types/binary_json/ut/valid_ut.cpp b/yql/essentials/types/binary_json/ut/valid_ut.cpp
index 30783758770..4115b7299f9 100644
--- a/yql/essentials/types/binary_json/ut/valid_ut.cpp
+++ b/yql/essentials/types/binary_json/ut/valid_ut.cpp
@@ -12,7 +12,7 @@
using namespace NKikimr::NBinaryJson;
-class TBinaryJsonValidnessTest : public TBinaryJsonTestBase {
+class TBinaryJsonValidnessTest: public TBinaryJsonTestBase {
public:
TBinaryJsonValidnessTest()
: TBinaryJsonTestBase()
@@ -20,9 +20,9 @@ public:
}
UNIT_TEST_SUITE(TBinaryJsonValidnessTest);
- UNIT_TEST(TestValidness);
- UNIT_TEST(TestRandom);
- UNIT_TEST(TestVersionCheck);
+ UNIT_TEST(TestValidness);
+ UNIT_TEST(TestRandom);
+ UNIT_TEST(TestVersionCheck);
UNIT_TEST_SUITE_END();
void TestValidness() {
diff --git a/yql/essentials/types/binary_json/ut/ya.make b/yql/essentials/types/binary_json/ut/ya.make
index 49ef9c24a04..8c5ce8701df 100644
--- a/yql/essentials/types/binary_json/ut/ya.make
+++ b/yql/essentials/types/binary_json/ut/ya.make
@@ -1,5 +1,7 @@
UNITTEST_FOR(yql/essentials/types/binary_json)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
container_ut.cpp
identity_ut.cpp
diff --git a/yql/essentials/types/binary_json/ut_benchmark/write.cpp b/yql/essentials/types/binary_json/ut_benchmark/write.cpp
index f82b1c1c3d8..51efaee89c3 100644
--- a/yql/essentials/types/binary_json/ut_benchmark/write.cpp
+++ b/yql/essentials/types/binary_json/ut_benchmark/write.cpp
@@ -9,7 +9,7 @@
// ya test -r -D BENCHMARK_MAKE_LARGE_PART
#ifndef BENCHMARK_MAKE_LARGE_PART
-#define BENCHMARK_MAKE_LARGE_PART 0
+ #define BENCHMARK_MAKE_LARGE_PART 0
#endif
using namespace NKikimr::NBinaryJson;
@@ -36,15 +36,15 @@ TString GetTestJsonString() {
}
static void BenchWriteSimdJson(benchmark::State& state) {
- TString value = GetTestJsonString();
- TStringBuf buf(value);
- for (auto _ : state) {
- auto result = SerializeToBinaryJson(buf);
- benchmark::DoNotOptimize(result);
- benchmark::ClobberMemory();
- }
+ TString value = GetTestJsonString();
+ TStringBuf buf(value);
+ for (auto _ : state) {
+ auto result = SerializeToBinaryJson(buf);
+ benchmark::DoNotOptimize(result);
+ benchmark::ClobberMemory();
+ }
}
-}
+} // namespace
BENCHMARK(BenchWriteSimdJson)->MinTime(1);
diff --git a/yql/essentials/types/binary_json/ut_benchmark/ya.make b/yql/essentials/types/binary_json/ut_benchmark/ya.make
index b4b94af4ecd..17060e862aa 100644
--- a/yql/essentials/types/binary_json/ut_benchmark/ya.make
+++ b/yql/essentials/types/binary_json/ut_benchmark/ya.make
@@ -1,5 +1,7 @@
G_BENCHMARK()
+ENABLE(YQL_STYLE_CPP)
+
TAG(ya:fat)
SIZE(LARGE)
TIMEOUT(600)
diff --git a/yql/essentials/types/binary_json/write.cpp b/yql/essentials/types/binary_json/write.cpp
index 225e54c23e2..12232898037 100644
--- a/yql/essentials/types/binary_json/write.cpp
+++ b/yql/essentials/types/binary_json/write.cpp
@@ -415,10 +415,12 @@ private:
/**
* @brief Callbacks for textual JSON parser. Essentially wrapper around TJsonIndex methods
*/
-class TBinaryJsonCallbacks : public TJsonCallbacks {
+class TBinaryJsonCallbacks: public TJsonCallbacks {
public:
TBinaryJsonCallbacks(bool throwException, bool allowInf)
- : TJsonCallbacks(/* throwException */ throwException), AllowInf_(allowInf) {
+ : TJsonCallbacks(/* throwException */ throwException)
+ , AllowInf_(allowInf)
+ {
}
bool OnNull() override {
@@ -723,7 +725,7 @@ template <typename TOnDemandValue>
return simdjson::SUCCESS;
#undef RETURN_IF_NOT_SUCCESS
}
-}
+} // namespace
std::variant<TBinaryJson, TString> SerializeToBinaryJsonImpl(const TStringBuf json, bool allowInf) {
std::variant<TBinaryJson, TString> res;
@@ -760,5 +762,4 @@ TBinaryJson SerializeToBinaryJson(const NUdf::TUnboxedValue& value) {
return std::move(serializer).Serialize();
}
-}
-
+} // namespace NKikimr::NBinaryJson
diff --git a/yql/essentials/types/binary_json/write.h b/yql/essentials/types/binary_json/write.h
index 61dea9bfb40..819cb002375 100644
--- a/yql/essentials/types/binary_json/write.h
+++ b/yql/essentials/types/binary_json/write.h
@@ -8,7 +8,7 @@
namespace NYql::NUdf {
class TUnboxedValue;
-};
+}; // namespace NYql::NUdf
namespace NKikimr::NBinaryJson {
@@ -21,5 +21,4 @@ std::variant<TBinaryJson, TString> SerializeToBinaryJson(const TStringBuf json,
* @brief Translates DOM layout from `yql/library/dom` library into BinaryJson
*/
TBinaryJson SerializeToBinaryJson(const NYql::NUdf::TUnboxedValue& value);
-}
-
+} // namespace NKikimr::NBinaryJson
diff --git a/yql/essentials/types/dynumber/cast.h b/yql/essentials/types/dynumber/cast.h
index 2625ec446fc..b8d1f158192 100644
--- a/yql/essentials/types/dynumber/cast.h
+++ b/yql/essentials/types/dynumber/cast.h
@@ -111,4 +111,4 @@ TMaybe<T> TryFromDyNumber(TStringBuf buffer) {
return result;
}
-}
+} // namespace NKikimr::NDyNumber
diff --git a/yql/essentials/types/dynumber/dynumber.cpp b/yql/essentials/types/dynumber/dynumber.cpp
index 2e4b997f07b..1344cf0b346 100644
--- a/yql/essentials/types/dynumber/dynumber.cpp
+++ b/yql/essentials/types/dynumber/dynumber.cpp
@@ -11,24 +11,31 @@ namespace NKikimr::NDyNumber {
bool IsValidDyNumber(TStringBuf buffer) {
const auto size = buffer.size();
- if (!size)
+ if (!size) {
return false;
+ }
switch (const auto data = buffer.data(); *data) {
case '\x00':
- if (size < 2U || size > 21U)
+ if (size < 2U || size > 21U) {
return false;
- for (auto i = 2U; i < size; ++i)
- if ((data[i] & '\x0F') < '\x06' || ((data[i] >> '\x04') & '\x0F') < '\x06')
+ }
+ for (auto i = 2U; i < size; ++i) {
+ if ((data[i] & '\x0F') < '\x06' || ((data[i] >> '\x04') & '\x0F') < '\x06') {
return false;
+ }
+ }
break;
case '\x01':
return 1U == size;
case '\x02':
- if (size < 2U || size > 21U)
+ if (size < 2U || size > 21U) {
return false;
- for (auto i = 2U; i < size; ++i)
- if ((data[i] & '\x0F') > '\x09' || ((data[i] >> '\x04') & '\x0F') > '\x09')
+ }
+ for (auto i = 2U; i < size; ++i) {
+ if ((data[i] & '\x0F') > '\x09' || ((data[i] >> '\x04') & '\x0F') > '\x09') {
return false;
+ }
+ }
break;
default:
return false;
@@ -37,8 +44,9 @@ bool IsValidDyNumber(TStringBuf buffer) {
}
bool IsValidDyNumberString(TStringBuf str) {
- if (str.empty())
+ if (str.empty()) {
return false;
+ }
auto s = str.data();
auto l = str.size();
const bool neg = '-' == *s;
@@ -46,8 +54,9 @@ bool IsValidDyNumberString(TStringBuf str) {
++s;
--l;
}
- if (!l)
+ if (!l) {
return false;
+ }
bool hasDot = false;
auto beforeDot = 0U;
auto nonZeroAfterDot = 0U;
@@ -58,28 +67,34 @@ bool IsValidDyNumberString(TStringBuf str) {
for (auto i = 0U; i < l; ++i) {
const auto c = s[i];
const bool isZero = '0' == c;
- if (!hasDot && isZero && !beforeDot)
+ if (!hasDot && isZero && !beforeDot) {
continue;
+ }
if (c == '.') {
- if (hasDot)
+ if (hasDot) {
return false;
+ }
hasDot = true;
continue;
}
- if (c =='e' || c == 'E') {
- if (++i >= l)
+ if (c == 'e' || c == 'E') {
+ if (++i >= l) {
return false;
- if (!TryFromString(s + i, l - i, ePower))
+ }
+ if (!TryFromString(s + i, l - i, ePower)) {
return false;
+ }
break;
}
- if (!std::isdigit(c))
+ if (!std::isdigit(c)) {
return false;
+ }
if (!hasDot) {
++beforeDot;
} else {
- if (!isZero)
+ if (!isZero) {
hasNonZeroAfterDot = true;
+ }
if (hasNonZeroAfterDot) {
if (isZero) {
++tailZeros;
@@ -89,28 +104,33 @@ bool IsValidDyNumberString(TStringBuf str) {
}
} else {
++zeroAfterDot;
- if (beforeDot)
+ if (beforeDot) {
++tailZeros;
+ }
}
}
}
auto effectivePower = ePower;
- if (beforeDot)
+ if (beforeDot) {
effectivePower += beforeDot;
- else if (hasNonZeroAfterDot)
+ } else if (hasNonZeroAfterDot) {
effectivePower -= zeroAfterDot;
- else
+ } else {
return true;
- if (beforeDot + zeroAfterDot + nonZeroAfterDot > 38U)
+ }
+ if (beforeDot + zeroAfterDot + nonZeroAfterDot > 38U) {
return false;
- if (effectivePower < -129 || effectivePower > 126)
+ }
+ if (effectivePower < -129 || effectivePower > 126) {
return false;
+ }
return true;
}
TMaybe<TString> ParseDyNumberString(TStringBuf str) {
- if (str.empty())
+ if (str.empty()) {
return Nothing();
+ }
auto s = str.data();
auto l = str.size();
const bool neg = '-' == *s;
@@ -118,8 +138,9 @@ TMaybe<TString> ParseDyNumberString(TStringBuf str) {
++s;
--l;
}
- if (!l)
+ if (!l) {
return Nothing();
+ }
bool hasDot = false;
auto beforeDot = 0U;
auto nonZeroAfterDot = 0U;
@@ -133,23 +154,28 @@ TMaybe<TString> ParseDyNumberString(TStringBuf str) {
for (auto i = 0U; i < l; ++i) {
const auto c = s[i];
const bool isZero = '0' == c;
- if (!hasDot && isZero && !beforeDot)
+ if (!hasDot && isZero && !beforeDot) {
continue;
+ }
if (c == '.') {
- if (hasDot)
+ if (hasDot) {
return Nothing();
+ }
hasDot = true;
continue;
}
- if (c =='e' || c == 'E') {
- if (++i >= l)
+ if (c == 'e' || c == 'E') {
+ if (++i >= l) {
return Nothing();
- if (!TryFromString(s + i, l - i, ePower))
+ }
+ if (!TryFromString(s + i, l - i, ePower)) {
return Nothing();
+ }
break;
}
- if (!std::isdigit(c))
+ if (!std::isdigit(c)) {
return Nothing();
+ }
if (!hasDot) {
++beforeDot;
if (isZero) {
@@ -161,8 +187,9 @@ TMaybe<TString> ParseDyNumberString(TStringBuf str) {
data.emplace_back(c - '0');
}
} else {
- if (!isZero)
+ if (!isZero) {
hasNonZeroAfterDot = true;
+ }
if (hasNonZeroAfterDot) {
if (isZero) {
++tailZeros;
@@ -178,37 +205,44 @@ TMaybe<TString> ParseDyNumberString(TStringBuf str) {
}
} else {
++zeroAfterDot;
- if (beforeDot)
+ if (beforeDot) {
++tailZeros;
+ }
}
}
}
auto effectivePower = ePower;
- if (beforeDot)
+ if (beforeDot) {
effectivePower += beforeDot;
- else if (hasNonZeroAfterDot)
+ } else if (hasNonZeroAfterDot) {
effectivePower -= zeroAfterDot;
- else
+ } else {
return "\x01";
- if (beforeDot + zeroAfterDot + nonZeroAfterDot > 38U)
+ }
+ if (beforeDot + zeroAfterDot + nonZeroAfterDot > 38U) {
return Nothing();
- if (effectivePower < -129 || effectivePower > 126)
+ }
+ if (effectivePower < -129 || effectivePower > 126) {
return Nothing();
- if (data.size() % 2U)
+ }
+ if (data.size() % 2U) {
data.emplace_back('\x00');
-
+ }
+
TString result;
result.reserve(2U + (data.size() >> 1U));
if (neg) {
result.append('\x00');
result.append(char(126 - effectivePower));
- for (auto i = 0U; i < data.size(); i += 2U)
- result.append((('\x0F' - data[i]) << '\x04') | ('\x0F' - data[i + 1]));
+ for (auto i = 0U; i < data.size(); i += 2U) {
+ result.append((('\x0F' - data[i]) << '\x04') | ('\x0F' - data[i + 1]));
+ }
} else {
result.append('\x02');
result.append(char(effectivePower + 129));
- for (auto i = 0U; i < data.size(); i += 2U)
- result.append((data[i] << '\x04') | data[i + 1]);
+ for (auto i = 0U; i < data.size(); i += 2U) {
+ result.append((data[i] << '\x04') | data[i + 1]);
+ }
}
// Cerr << str << ": " << HexText(TStringBuf{result.c_str(), result.size()}) << Endl;
@@ -231,25 +265,29 @@ TMaybe<TString> DyNumberToString(TStringBuf buffer) {
return out;
}
const bool negative = !*s++;
- if (negative)
+ if (negative) {
out << '-';
+ }
if (0U >= --l) {
return Nothing();
}
auto power = ui8(*s++);
- if (negative)
+ if (negative) {
power = '\xFF' - power;
+ }
out << '.';
const auto digits = negative ? "FEDCBA9876543210" : "0123456789ABCDEF";
while (--l) {
const auto c = *s++;
out << digits[(c >> '\x04') & '\x0F'];
- if (const auto digit = c & '\x0F'; digit != (negative ? '\x0F' : '\x00') || l > 1U)
+ if (const auto digit = c & '\x0F'; digit != (negative ? '\x0F' : '\x00') || l > 1U) {
out << digits[digit];
+ }
}
- if (const auto e = power - 129)
+ if (const auto e = power - 129) {
out << 'e' << e;
+ }
return out;
}
-}
+} // namespace NKikimr::NDyNumber
diff --git a/yql/essentials/types/dynumber/dynumber.h b/yql/essentials/types/dynumber/dynumber.h
index f64d1a294f3..b8a88311e85 100644
--- a/yql/essentials/types/dynumber/dynumber.h
+++ b/yql/essentials/types/dynumber/dynumber.h
@@ -32,4 +32,4 @@ TMaybe<TString> ParseDyNumberString(TStringBuf str);
*/
TMaybe<TString> DyNumberToString(TStringBuf buffer);
-} \ No newline at end of file
+} // namespace NKikimr::NDyNumber
diff --git a/yql/essentials/types/dynumber/ut/dynumber_ut.cpp b/yql/essentials/types/dynumber/ut/dynumber_ut.cpp
index 6b7d388a75c..5eae66700cc 100644
--- a/yql/essentials/types/dynumber/ut/dynumber_ut.cpp
+++ b/yql/essentials/types/dynumber/ut/dynumber_ut.cpp
@@ -9,175 +9,175 @@
using namespace NKikimr::NDyNumber;
namespace {
- void TestDyNumber(TStringBuf test) {
- UNIT_ASSERT(IsValidDyNumberString(test));
+void TestDyNumber(TStringBuf test) {
+ UNIT_ASSERT(IsValidDyNumberString(test));
- const auto dyNumber = ParseDyNumberString(test);
- UNIT_ASSERT(dyNumber.Defined());
- UNIT_ASSERT(IsValidDyNumber(*dyNumber));
+ const auto dyNumber = ParseDyNumberString(test);
+ UNIT_ASSERT(dyNumber.Defined());
+ UNIT_ASSERT(IsValidDyNumber(*dyNumber));
- const auto restoredTest = DyNumberToString(*dyNumber);
- UNIT_ASSERT(restoredTest.Defined());
- UNIT_ASSERT(IsValidDyNumberString(*restoredTest));
+ const auto restoredTest = DyNumberToString(*dyNumber);
+ UNIT_ASSERT(restoredTest.Defined());
+ UNIT_ASSERT(IsValidDyNumberString(*restoredTest));
- const auto dyNumberAfterString = ParseDyNumberString(*restoredTest);
- UNIT_ASSERT(dyNumberAfterString.Defined());
- UNIT_ASSERT(IsValidDyNumber(*dyNumberAfterString));
+ const auto dyNumberAfterString = ParseDyNumberString(*restoredTest);
+ UNIT_ASSERT(dyNumberAfterString.Defined());
+ UNIT_ASSERT(IsValidDyNumber(*dyNumberAfterString));
- UNIT_ASSERT_EQUAL(*dyNumber, *dyNumberAfterString);
- }
+ UNIT_ASSERT_EQUAL(*dyNumber, *dyNumberAfterString);
+}
- template <typename T>
- void TestCast(TStringBuf test, TMaybe<T> value) {
- UNIT_ASSERT_C(IsValidDyNumberString(test), test);
+template <typename T>
+void TestCast(TStringBuf test, TMaybe<T> value) {
+ UNIT_ASSERT_C(IsValidDyNumberString(test), test);
- const auto dyNumber = ParseDyNumberString(test);
- UNIT_ASSERT(dyNumber.Defined());
- UNIT_ASSERT(IsValidDyNumber(*dyNumber));
+ const auto dyNumber = ParseDyNumberString(test);
+ UNIT_ASSERT(dyNumber.Defined());
+ UNIT_ASSERT(IsValidDyNumber(*dyNumber));
- const auto casted = TryFromDyNumber<T>(*dyNumber);
+ const auto casted = TryFromDyNumber<T>(*dyNumber);
- if constexpr (std::is_integral<T>::value) {
- UNIT_ASSERT_VALUES_EQUAL(casted, value);
- } else if (casted && value) {
- UNIT_ASSERT_DOUBLES_EQUAL(*casted, *value, 1e-9);
- } else {
- UNIT_ASSERT_C(!casted && !value, "Casted: " << casted << ", value: " << value);
- }
+ if constexpr (std::is_integral<T>::value) {
+ UNIT_ASSERT_VALUES_EQUAL(casted, value);
+ } else if (casted && value) {
+ UNIT_ASSERT_DOUBLES_EQUAL(*casted, *value, 1e-9);
+ } else {
+ UNIT_ASSERT_C(!casted && !value, "Casted: " << casted << ", value: " << value);
}
}
+} // namespace
Y_UNIT_TEST_SUITE(TDyNumberTests) {
- Y_UNIT_TEST(ParseAndRestore) {
- TestDyNumber("0");
- TestDyNumber(".0");
- TestDyNumber("1");
- TestDyNumber("18");
- TestDyNumber("181");
- TestDyNumber("1817");
- TestDyNumber("-1");
- TestDyNumber("-18");
- TestDyNumber("-181");
- TestDyNumber("-1817");
- TestDyNumber(".023");
- TestDyNumber("0.93");
- TestDyNumber("724.1");
- TestDyNumber("150e2");
- TestDyNumber("15e3");
- TestDyNumber("0.150e4");
- TestDyNumber("0.15e4");
- TestDyNumber("1E-130");
- TestDyNumber("9.9999999999999999999999999999999999999E+125");
- TestDyNumber("9.9999999999999999999999999999999999999000E+125");
- TestDyNumber("-1E-130");
- TestDyNumber("-9.9999999999999999999999999999999999999E+125");
- TestDyNumber("-9.9999999999999999999999999999999999999000E+125");
- }
+Y_UNIT_TEST(ParseAndRestore) {
+ TestDyNumber("0");
+ TestDyNumber(".0");
+ TestDyNumber("1");
+ TestDyNumber("18");
+ TestDyNumber("181");
+ TestDyNumber("1817");
+ TestDyNumber("-1");
+ TestDyNumber("-18");
+ TestDyNumber("-181");
+ TestDyNumber("-1817");
+ TestDyNumber(".023");
+ TestDyNumber("0.93");
+ TestDyNumber("724.1");
+ TestDyNumber("150e2");
+ TestDyNumber("15e3");
+ TestDyNumber("0.150e4");
+ TestDyNumber("0.15e4");
+ TestDyNumber("1E-130");
+ TestDyNumber("9.9999999999999999999999999999999999999E+125");
+ TestDyNumber("9.9999999999999999999999999999999999999000E+125");
+ TestDyNumber("-1E-130");
+ TestDyNumber("-9.9999999999999999999999999999999999999E+125");
+ TestDyNumber("-9.9999999999999999999999999999999999999000E+125");
+}
- Y_UNIT_TEST(Cast) {
- TestCast<int>("0", 0);
-
- TestCast<int>("1", 1);
- TestCast<int>("-1", -1);
-
- TestCast<int>("12", 12);
- TestCast<int>("-12", -12);
- TestCast<int>("123", 123);
- TestCast<int>("-123", -123);
- TestCast<int>("1234", 1234);
- TestCast<int>("-1234", -1234);
-
- TestCast<int>(ToString(Max<int>()), Max<int>());
- TestCast<int>(ToString(Min<int>()), Min<int>());
-
- TestCast<i8> ("200", Nothing());
- TestCast<i16>("40000", Nothing());
- TestCast<i32>("3000000000", Nothing());
-
- TestCast<ui8> ("300", Nothing());
- TestCast<ui16>("70000", Nothing());
- TestCast<ui32>("5000000000", Nothing());
-
- // int to floating point
- TestCast<double>("1", 1);
- TestCast<double>("12", 12);
- TestCast<double>("123", 123);
-
- // floating point to int
- TestCast<int>("0.1", Nothing());
- TestCast<int>("0.23", Nothing());
- TestCast<int>("1.2", Nothing());
- TestCast<int>("1.23", Nothing());
- TestCast<int>("12.3", Nothing());
- TestCast<int>("123.4", Nothing());
-
- // double
- TestCast<double>("0.1", 0.1);
- TestCast<double>("0.23", 0.23);
- TestCast<double>("-1.23", -1.23);
- TestCast<double>("12.3", 12.3);
- TestCast<double>("123.4", 123.4);
- TestCast<double>("1.23E20", 1.23E20);
- TestCast<double>("1.23E-20", 1.23E-20);
-
- // float
- TestCast<float>("-0.1", -0.1f);
- TestCast<float>("-0.23", -0.23f);
- TestCast<float>("1.23", 1.23f);
- TestCast<float>("-12.3", -12.3f);
- TestCast<float>("-123.4", -123.4f);
- TestCast<float>("-1.23E10", -1.23E10f);
- TestCast<float>("-1.23E-10", -1.23E-10f);
-
- // unsigned Max
- TestCast<ui8> (ToString(Max<ui8>()), Max<ui8>());
- TestCast<ui16>(ToString(Max<ui16>()), Max<ui16>());
- TestCast<ui32>(ToString(Max<ui32>()), Max<ui32>());
- TestCast<ui64>(ToString(Max<ui64>()), Max<ui64>());
-
- // signed Max
- TestCast<i8> (ToString(Max<i8>()), Max<i8>());
- TestCast<i16>(ToString(Max<i16>()), Max<i16>());
- TestCast<i32>(ToString(Max<i32>()), Max<i32>());
- TestCast<i64>(ToString(Max<i64>()), Max<i64>());
-
- // signed Min
- TestCast<i8> (ToString(Min<i8>()), Min<i8>());
- TestCast<i16>(ToString(Min<i16>()), Min<i16>());
- TestCast<i32>(ToString(Min<i32>()), Min<i32>());
- TestCast<i64>(ToString(Min<i64>()), Min<i64>());
-
- // unsigned out of range
- TestCast<ui8> (ToString(static_cast<ui64>(Max<ui8>()) + 1), Nothing());
- TestCast<ui16>(ToString(static_cast<ui64>(Max<ui16>()) + 1), Nothing());
- TestCast<ui32>(ToString(static_cast<ui64>(Max<ui32>()) + 1), Nothing());
-
- // signed out of range (right)
- TestCast<i8> (ToString(static_cast<i64>(Max<i8>()) + 1), Nothing());
- TestCast<i16>(ToString(static_cast<i64>(Max<i16>()) + 1), Nothing());
- TestCast<i32>(ToString(static_cast<i64>(Max<i32>()) + 1), Nothing());
-
- // signed out of range (left)
- TestCast<i8> (ToString(static_cast<i64>(Min<i8>()) - 1), Nothing());
- TestCast<i16>(ToString(static_cast<i64>(Min<i16>()) - 1), Nothing());
- TestCast<i32>(ToString(static_cast<i64>(Min<i32>()) - 1), Nothing());
-
- // positive signed to unsigned
- TestCast<ui8> (ToString(Max<i8>()), Max<i8>());
- TestCast<ui16>(ToString(Max<i16>()), Max<i16>());
- TestCast<ui32>(ToString(Max<i32>()), Max<i32>());
- TestCast<ui64>(ToString(Max<i64>()), Max<i64>());
-
- // negative signed to unsigned
- TestCast<ui8> (ToString(Min<i8>()), Nothing());
- TestCast<ui16>(ToString(Min<i16>()), Nothing());
- TestCast<ui32>(ToString(Min<i32>()), Nothing());
- TestCast<ui64>(ToString(Min<i64>()), Nothing());
-
- // DyNumber limits
- TestCast<ui64>("9.9999999999999999999999999999999999999E+125", Nothing());
- TestCast<ui64>("-9.9999999999999999999999999999999999999E+125", Nothing());
- TestCast<double>("1E-130", 1E-130);
- TestCast<double>("-1E-130", -1E-130);
- }
+Y_UNIT_TEST(Cast) {
+ TestCast<int>("0", 0);
+
+ TestCast<int>("1", 1);
+ TestCast<int>("-1", -1);
+
+ TestCast<int>("12", 12);
+ TestCast<int>("-12", -12);
+ TestCast<int>("123", 123);
+ TestCast<int>("-123", -123);
+ TestCast<int>("1234", 1234);
+ TestCast<int>("-1234", -1234);
+
+ TestCast<int>(ToString(Max<int>()), Max<int>());
+ TestCast<int>(ToString(Min<int>()), Min<int>());
+
+ TestCast<i8>("200", Nothing());
+ TestCast<i16>("40000", Nothing());
+ TestCast<i32>("3000000000", Nothing());
+
+ TestCast<ui8>("300", Nothing());
+ TestCast<ui16>("70000", Nothing());
+ TestCast<ui32>("5000000000", Nothing());
+
+ // int to floating point
+ TestCast<double>("1", 1);
+ TestCast<double>("12", 12);
+ TestCast<double>("123", 123);
+
+ // floating point to int
+ TestCast<int>("0.1", Nothing());
+ TestCast<int>("0.23", Nothing());
+ TestCast<int>("1.2", Nothing());
+ TestCast<int>("1.23", Nothing());
+ TestCast<int>("12.3", Nothing());
+ TestCast<int>("123.4", Nothing());
+
+ // double
+ TestCast<double>("0.1", 0.1);
+ TestCast<double>("0.23", 0.23);
+ TestCast<double>("-1.23", -1.23);
+ TestCast<double>("12.3", 12.3);
+ TestCast<double>("123.4", 123.4);
+ TestCast<double>("1.23E20", 1.23E20);
+ TestCast<double>("1.23E-20", 1.23E-20);
+
+ // float
+ TestCast<float>("-0.1", -0.1f);
+ TestCast<float>("-0.23", -0.23f);
+ TestCast<float>("1.23", 1.23f);
+ TestCast<float>("-12.3", -12.3f);
+ TestCast<float>("-123.4", -123.4f);
+ TestCast<float>("-1.23E10", -1.23E10f);
+ TestCast<float>("-1.23E-10", -1.23E-10f);
+
+ // unsigned Max
+ TestCast<ui8>(ToString(Max<ui8>()), Max<ui8>());
+ TestCast<ui16>(ToString(Max<ui16>()), Max<ui16>());
+ TestCast<ui32>(ToString(Max<ui32>()), Max<ui32>());
+ TestCast<ui64>(ToString(Max<ui64>()), Max<ui64>());
+
+ // signed Max
+ TestCast<i8>(ToString(Max<i8>()), Max<i8>());
+ TestCast<i16>(ToString(Max<i16>()), Max<i16>());
+ TestCast<i32>(ToString(Max<i32>()), Max<i32>());
+ TestCast<i64>(ToString(Max<i64>()), Max<i64>());
+
+ // signed Min
+ TestCast<i8>(ToString(Min<i8>()), Min<i8>());
+ TestCast<i16>(ToString(Min<i16>()), Min<i16>());
+ TestCast<i32>(ToString(Min<i32>()), Min<i32>());
+ TestCast<i64>(ToString(Min<i64>()), Min<i64>());
+
+ // unsigned out of range
+ TestCast<ui8>(ToString(static_cast<ui64>(Max<ui8>()) + 1), Nothing());
+ TestCast<ui16>(ToString(static_cast<ui64>(Max<ui16>()) + 1), Nothing());
+ TestCast<ui32>(ToString(static_cast<ui64>(Max<ui32>()) + 1), Nothing());
+
+ // signed out of range (right)
+ TestCast<i8>(ToString(static_cast<i64>(Max<i8>()) + 1), Nothing());
+ TestCast<i16>(ToString(static_cast<i64>(Max<i16>()) + 1), Nothing());
+ TestCast<i32>(ToString(static_cast<i64>(Max<i32>()) + 1), Nothing());
+
+ // signed out of range (left)
+ TestCast<i8>(ToString(static_cast<i64>(Min<i8>()) - 1), Nothing());
+ TestCast<i16>(ToString(static_cast<i64>(Min<i16>()) - 1), Nothing());
+ TestCast<i32>(ToString(static_cast<i64>(Min<i32>()) - 1), Nothing());
+
+ // positive signed to unsigned
+ TestCast<ui8>(ToString(Max<i8>()), Max<i8>());
+ TestCast<ui16>(ToString(Max<i16>()), Max<i16>());
+ TestCast<ui32>(ToString(Max<i32>()), Max<i32>());
+ TestCast<ui64>(ToString(Max<i64>()), Max<i64>());
+
+ // negative signed to unsigned
+ TestCast<ui8>(ToString(Min<i8>()), Nothing());
+ TestCast<ui16>(ToString(Min<i16>()), Nothing());
+ TestCast<ui32>(ToString(Min<i32>()), Nothing());
+ TestCast<ui64>(ToString(Min<i64>()), Nothing());
+
+ // DyNumber limits
+ TestCast<ui64>("9.9999999999999999999999999999999999999E+125", Nothing());
+ TestCast<ui64>("-9.9999999999999999999999999999999999999E+125", Nothing());
+ TestCast<double>("1E-130", 1E-130);
+ TestCast<double>("-1E-130", -1E-130);
}
+} // Y_UNIT_TEST_SUITE(TDyNumberTests)
diff --git a/yql/essentials/types/dynumber/ut/ya.make b/yql/essentials/types/dynumber/ut/ya.make
index b632325e5b4..196ee912d53 100644
--- a/yql/essentials/types/dynumber/ut/ya.make
+++ b/yql/essentials/types/dynumber/ut/ya.make
@@ -1,5 +1,7 @@
UNITTEST_FOR(yql/essentials/types/dynumber)
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
dynumber_ut.cpp
)
diff --git a/yql/essentials/types/dynumber/ya.make b/yql/essentials/types/dynumber/ya.make
index 5d372e0c314..f58b6173376 100644
--- a/yql/essentials/types/dynumber/ya.make
+++ b/yql/essentials/types/dynumber/ya.make
@@ -1,5 +1,7 @@
LIBRARY()
+ENABLE(YQL_STYLE_CPP)
+
PEERDIR(
library/cpp/containers/stack_vector
)
diff --git a/yql/essentials/types/uuid/uuid.cpp b/yql/essentials/types/uuid/uuid.cpp
index 4a7f2bd406d..e735b56ac2c 100644
--- a/yql/essentials/types/uuid/uuid.cpp
+++ b/yql/essentials/types/uuid/uuid.cpp
@@ -8,8 +8,7 @@ namespace NUuid {
static void WriteHexDigit(ui8 digit, IOutputStream& out) {
if (digit <= 9) {
out << char('0' + digit);
- }
- else {
+ } else {
out << char('a' + digit - 10);
}
}
@@ -77,6 +76,5 @@ void UuidHalfsToByteString(ui64 low, ui64 hi, IOutputStream& out) {
out.Write(buf.Bytes, 16);
}
-}
-}
-
+} // namespace NUuid
+} // namespace NKikimr
diff --git a/yql/essentials/types/uuid/uuid.h b/yql/essentials/types/uuid/uuid.h
index 8f771d3753d..3fed9d383ce 100644
--- a/yql/essentials/types/uuid/uuid.h
+++ b/yql/essentials/types/uuid/uuid.h
@@ -23,20 +23,17 @@ inline bool GetDigit(char c, ui32& digit) {
digit = 0;
if ('0' <= c && c <= '9') {
digit = c - '0';
- }
- else if ('a' <= c && c <= 'f') {
+ } else if ('a' <= c && c <= 'f') {
digit = c - 'a' + 10;
- }
- else if ('A' <= c && c <= 'F') {
+ } else if ('A' <= c && c <= 'F') {
digit = c - 'A' + 10;
- }
- else {
+ } else {
return false; // non-hex character
}
return true;
}
-template<typename T>
+template <typename T>
inline bool IsValidUuid(const T& buf) {
if (buf.Size() != 36) {
return false;
@@ -57,7 +54,7 @@ inline bool IsValidUuid(const T& buf) {
return true;
}
-template<typename T>
+template <typename T>
bool ParseUuidToArray(const T& buf, ui16* dw, bool shortForm) {
if (buf.size() != (shortForm ? 32 : 36)) {
return false;
@@ -99,7 +96,7 @@ bool ParseUuidToArray(const T& buf, ui16* dw, bool shortForm) {
return true;
}
-inline void UuidHalfsToBytes(char *dst, size_t dstSize, ui64 hi, ui64 low) {
+inline void UuidHalfsToBytes(char* dst, size_t dstSize, ui64 hi, ui64 low) {
union {
char Bytes[UUID_LEN];
ui64 Half[2];
@@ -110,7 +107,7 @@ inline void UuidHalfsToBytes(char *dst, size_t dstSize, ui64 hi, ui64 low) {
memcpy(dst, buf.Bytes, sizeof(buf));
}
-inline void UuidBytesToHalfs(const char *str, size_t sz, ui64 &high, ui64 &low) {
+inline void UuidBytesToHalfs(const char* str, size_t sz, ui64& high, ui64& low) {
union {
char Bytes[UUID_LEN];
ui64 Half[2];
@@ -121,5 +118,5 @@ inline void UuidBytesToHalfs(const char *str, size_t sz, ui64 &high, ui64 &low)
high = buf.Half[1];
}
-}
-}
+} // namespace NUuid
+} // namespace NKikimr
diff --git a/yql/essentials/types/uuid/ya.make b/yql/essentials/types/uuid/ya.make
index 15cd576d234..1103b8e83d4 100644
--- a/yql/essentials/types/uuid/ya.make
+++ b/yql/essentials/types/uuid/ya.make
@@ -1,5 +1,7 @@
LIBRARY()
+ENABLE(YQL_STYLE_CPP)
+
SRCS(
uuid.cpp
)