aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorkhvostikovao <khvostikovao@yandex-team.ru>2022-02-10 16:52:06 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:52:06 +0300
commitc6c60f8a1120937fbf449f6d47c8df1595a5df66 (patch)
treeab7fbbf3253d4c0e2793218f09378908beb025fb /util
parent06189cb2ee513c85b125b5bd1c879a5a4f05ca77 (diff)
downloadydb-c6c60f8a1120937fbf449f6d47c8df1595a5df66.tar.gz
Restoring authorship annotation for <khvostikovao@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/generic/guid.cpp34
-rw-r--r--util/generic/guid.h12
-rw-r--r--util/generic/guid_ut.cpp12
3 files changed, 29 insertions, 29 deletions
diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp
index ef023aa5e2..8b907457bc 100644
--- a/util/generic/guid.cpp
+++ b/util/generic/guid.cpp
@@ -48,23 +48,23 @@ void CreateGuid(TGUID* res) {
WriteUnaligned<ui64>(&dw[1], RandomNumber<ui64>());
}
-TGUID TGUID::CreateTimebased() {
- TGUID result;
- // GUID_EPOCH_OFFSET is the number of 100-ns intervals between the
- // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
- constexpr ui64 GUID_EPOCH_OFFSET = 0x01b21dd213814000;
- const ui64 timestamp = Now().NanoSeconds() / 100 + GUID_EPOCH_OFFSET;
- result.dw[0] = ui32(timestamp & 0xffffffff); // time low
- const ui32 timeMid = ui32((timestamp >> 32) & 0xffff);
- constexpr ui32 UUID_VERSION = 1;
- const ui32 timeHighAndVersion = ui16((timestamp >> 48) & 0x0fff) | (UUID_VERSION << 12);
- result.dw[1] = (timeMid << 16) | timeHighAndVersion;
- const ui32 clockSeq = RandomNumber<ui32>(0x3fff) | 0x8000;
- result.dw[2] = (clockSeq << 16) | RandomNumber<ui16>();
- result.dw[3] = RandomNumber<ui32>() | (1 << 24);
- return result;
-}
-
+TGUID TGUID::CreateTimebased() {
+ TGUID result;
+ // GUID_EPOCH_OFFSET is the number of 100-ns intervals between the
+ // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
+ constexpr ui64 GUID_EPOCH_OFFSET = 0x01b21dd213814000;
+ const ui64 timestamp = Now().NanoSeconds() / 100 + GUID_EPOCH_OFFSET;
+ result.dw[0] = ui32(timestamp & 0xffffffff); // time low
+ const ui32 timeMid = ui32((timestamp >> 32) & 0xffff);
+ constexpr ui32 UUID_VERSION = 1;
+ const ui32 timeHighAndVersion = ui16((timestamp >> 48) & 0x0fff) | (UUID_VERSION << 12);
+ result.dw[1] = (timeMid << 16) | timeHighAndVersion;
+ const ui32 clockSeq = RandomNumber<ui32>(0x3fff) | 0x8000;
+ result.dw[2] = (clockSeq << 16) | RandomNumber<ui16>();
+ result.dw[3] = RandomNumber<ui32>() | (1 << 24);
+ return result;
+}
+
TString GetGuidAsString(const TGUID& g) {
return g.AsGuidString();
}
diff --git a/util/generic/guid.h b/util/generic/guid.h
index 8267935bcc..2bf6c8ad99 100644
--- a/util/generic/guid.h
+++ b/util/generic/guid.h
@@ -36,12 +36,12 @@ struct TGUID {
TString AsUuidString() const;
static TGUID Create();
-
- /**
- * Generate time based UUID version 1 RFC4122 GUID
- * https://datatracker.ietf.org/doc/html/rfc4122#section-4.1
- **/
- static TGUID CreateTimebased();
+
+ /**
+ * Generate time based UUID version 1 RFC4122 GUID
+ * https://datatracker.ietf.org/doc/html/rfc4122#section-4.1
+ **/
+ static TGUID CreateTimebased();
};
constexpr bool operator==(const TGUID& a, const TGUID& b) noexcept {
diff --git a/util/generic/guid_ut.cpp b/util/generic/guid_ut.cpp
index a8fb32ea5f..048354ff39 100644
--- a/util/generic/guid_ut.cpp
+++ b/util/generic/guid_ut.cpp
@@ -119,10 +119,10 @@ Y_UNIT_TEST_SUITE(TGuidTest) {
UNIT_ASSERT_VALUES_EQUAL(guid.AsGuidString(), "5612-12000000-123-0");
UNIT_ASSERT_VALUES_EQUAL(guid.AsUuidString(), "00005612-1200-0000-0000-012300000000");
}
-
- Y_UNIT_TEST(TimeBased) {
- TString guid = TGUID::CreateTimebased().AsUuidString();
- UNIT_ASSERT(!guid.empty());
- UNIT_ASSERT_EQUAL(guid[14], '1');
- }
+
+ Y_UNIT_TEST(TimeBased) {
+ TString guid = TGUID::CreateTimebased().AsUuidString();
+ UNIT_ASSERT(!guid.empty());
+ UNIT_ASSERT_EQUAL(guid[14], '1');
+ }
}