MCPcopy Index your code
hub / github.com/RustPython/RustPython / uuid6

Function uuid6

Lib/uuid.py:795–829  ·  view source on GitHub ↗

Similar to :func:`uuid1` but where fields are ordered differently for improved DB locality. More precisely, given a 60-bit timestamp value as specified for UUIDv1, for UUIDv6 the first 48 most significant bits are stored first, followed by the 4-bit version (same position), followed

(node=None, clock_seq=None)

Source from the content-addressed store, hash-verified

793_last_timestamp_v6 = None
794
795def uuid6(node=None, clock_seq=None):
796 """Similar to :func:`uuid1` but where fields are ordered differently
797 for improved DB locality.
798
799 More precisely, given a 60-bit timestamp value as specified for UUIDv1,
800 for UUIDv6 the first 48 most significant bits are stored first, followed
801 by the 4-bit version (same position), followed by the remaining 12 bits
802 of the original 60-bit timestamp.
803 """
804 global _last_timestamp_v6
805 import time
806 nanoseconds = time.time_ns()
807 # 0x01b21dd213814000 is the number of 100-ns intervals between the
808 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
809 timestamp = nanoseconds // 100 + 0x01b21dd213814000
810 if _last_timestamp_v6 is not None and timestamp <= _last_timestamp_v6:
811 timestamp = _last_timestamp_v6 + 1
812 _last_timestamp_v6 = timestamp
813 if clock_seq is None:
814 import random
815 clock_seq = random.getrandbits(14) # instead of stable storage
816 time_hi_and_mid = (timestamp >> 12) & 0xffff_ffff_ffff
817 time_lo = timestamp & 0x0fff # keep 12 bits and clear version bits
818 clock_s = clock_seq & 0x3fff # keep 14 bits and clear variant bits
819 if node is None:
820 node = getnode()
821 # --- 32 + 16 --- -- 4 -- -- 12 -- -- 2 -- -- 14 --- 48
822 # time_hi_and_mid | version | time_lo | variant | clock_seq | node
823 int_uuid_6 = time_hi_and_mid << 80
824 int_uuid_6 |= time_lo << 64
825 int_uuid_6 |= clock_s << 48
826 int_uuid_6 |= node & 0xffff_ffff_ffff
827 # by construction, the variant and version bits are already cleared
828 int_uuid_6 |= _RFC_4122_VERSION_6_FLAGS
829 return UUID._from_int(int_uuid_6)
830
831
832_last_timestamp_v7 = None

Callers

nothing calls this directly

Calls 3

getnodeFunction · 0.85
_from_intMethod · 0.80
getrandbitsMethod · 0.45

Tested by

no test coverage detected