diff options
author | khvostikovao <khvostikovao@yandex-team.ru> | 2022-02-10 16:52:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:06 +0300 |
commit | 06189cb2ee513c85b125b5bd1c879a5a4f05ca77 (patch) | |
tree | b1d025e74b437ef31f6dcfde01766663c842197b /util/generic/guid.cpp | |
parent | e1eef5fd2ea964227b9be2c182415857c35e1290 (diff) | |
download | ydb-06189cb2ee513c85b125b5bd1c879a5a4f05ca77.tar.gz |
Restoring authorship annotation for <khvostikovao@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/guid.cpp')
-rw-r--r-- | util/generic/guid.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..ef023aa5e2 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(); } |