MCPcopy Create free account
hub / github.com/catboost/catboost / CreateTimebased

Method CreateTimebased

util/generic/guid.cpp:51–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51TGUID TGUID::CreateTimebased() {
52 TGUID result;
53 // GUID_EPOCH_OFFSET is the number of 100-ns intervals between the
54 // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
55 constexpr ui64 GUID_EPOCH_OFFSET = 0x01b21dd213814000;
56 const ui64 timestamp = Now().NanoSeconds() / 100 + GUID_EPOCH_OFFSET;
57 result.dw[0] = ui32(timestamp & 0xffffffff); // time low
58 const ui32 timeMid = ui32((timestamp >> 32) & 0xffff);
59 constexpr ui32 UUID_VERSION = 1;
60 const ui32 timeHighAndVersion = ui16((timestamp >> 48) & 0x0fff) | (UUID_VERSION << 12);
61 result.dw[1] = (timeMid << 16) | timeHighAndVersion;
62 const ui32 clockSeq = RandomNumber<ui32>(0x3fff) | 0x8000;
63 result.dw[2] = (clockSeq << 16) | RandomNumber<ui16>();
64 result.dw[3] = RandomNumber<ui32>() | (1 << 24);
65 return result;
66}
67
68TString GetGuidAsString(const TGUID& g) {
69 return g.AsGuidString();

Callers

nothing calls this directly

Calls 2

NanoSecondsMethod · 0.80
NowFunction · 0.50

Tested by

no test coverage detected