22
22
from typing import NoReturn , Tuple , Union
23
23
24
24
25
- class UInt64 :
25
+ class _UInt64 :
26
26
def __init__ (self , value : int ) -> None :
27
27
self ._value : int = value & 0xFFFFFFFFFFFFFFFF
28
28
@@ -34,43 +34,43 @@ def value(self) -> int:
34
34
def value (self , new_value : int ) -> None :
35
35
self ._value = new_value & 0xFFFFFFFFFFFFFFFF
36
36
37
- def __add__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
38
- result = self .value + (other .value if isinstance (other , UInt64 ) else other )
39
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
37
+ def __add__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
38
+ result = self .value + (other .value if isinstance (other , _UInt64 ) else other )
39
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
40
40
41
- def __sub__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
42
- result = self .value - (other .value if isinstance (other , UInt64 ) else other )
43
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
41
+ def __sub__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
42
+ result = self .value - (other .value if isinstance (other , _UInt64 ) else other )
43
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
44
44
45
- def __mul__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
46
- result = self .value * (other .value if isinstance (other , UInt64 ) else other )
47
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
45
+ def __mul__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
46
+ result = self .value * (other .value if isinstance (other , _UInt64 ) else other )
47
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
48
48
49
- def __xor__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
50
- result = self .value ^ (other .value if isinstance (other , UInt64 ) else other )
51
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
49
+ def __xor__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
50
+ result = self .value ^ (other .value if isinstance (other , _UInt64 ) else other )
51
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
52
52
53
- def __lshift__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
54
- result = self .value << (other .value if isinstance (other , UInt64 ) else other )
55
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
53
+ def __lshift__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
54
+ result = self .value << (other .value if isinstance (other , _UInt64 ) else other )
55
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
56
56
57
- def __rshift__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
58
- result = self .value >> (other .value if isinstance (other , UInt64 ) else other )
59
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
57
+ def __rshift__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
58
+ result = self .value >> (other .value if isinstance (other , _UInt64 ) else other )
59
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
60
60
61
- def __and__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
62
- result = self .value & (other .value if isinstance (other , UInt64 ) else other )
63
- return UInt64 (result & 0xFFFFFFFFFFFFFFFF )
61
+ def __and__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
62
+ result = self .value & (other .value if isinstance (other , _UInt64 ) else other )
63
+ return _UInt64 (result & 0xFFFFFFFFFFFFFFFF )
64
64
65
- def __or__ (self , other : Union [int , 'UInt64 ' ]) -> 'UInt64 ' :
66
- if isinstance (other , UInt64 ):
67
- return UInt64 (self .value | other .value )
65
+ def __or__ (self , other : Union [int , '_UInt64 ' ]) -> '_UInt64 ' :
66
+ if isinstance (other , _UInt64 ):
67
+ return _UInt64 (self .value | other .value )
68
68
if isinstance (other , int ):
69
- return UInt64 (self .value | other )
69
+ return _UInt64 (self .value | other )
70
70
raise TypeError ("Unsupported type for OR operation" )
71
71
72
- def __invert__ (self ) -> 'UInt64 ' :
73
- return UInt64 (~ self .value & 0xFFFFFFFFFFFFFFFF )
72
+ def __invert__ (self ) -> '_UInt64 ' :
73
+ return _UInt64 (~ self .value & 0xFFFFFFFFFFFFFFFF )
74
74
75
75
@staticmethod
76
76
def encode_double_as_uint64 (value : float ) -> int :
@@ -88,62 +88,62 @@ def __int__(self) -> int:
88
88
return self .value
89
89
90
90
91
- class UInt128 :
92
- def __init__ (self , low : Union [int , UInt64 ], high : Union [int , UInt64 ]) -> None :
93
- if isinstance (low , UInt64 ):
91
+ class _UInt128 :
92
+ def __init__ (self , low : Union [int , _UInt64 ], high : Union [int , _UInt64 ]) -> None :
93
+ if isinstance (low , _UInt64 ):
94
94
self .low = low
95
95
else :
96
- self .low = UInt64 (low )
97
- if isinstance (high , UInt64 ):
96
+ self .low = _UInt64 (low )
97
+ if isinstance (high , _UInt64 ):
98
98
self .high = high
99
99
else :
100
- self .high = UInt64 (high )
100
+ self .high = _UInt64 (high )
101
101
102
- def __add__ (self , other : 'UInt128 ' ) -> 'UInt128 ' :
102
+ def __add__ (self , other : '_UInt128 ' ) -> '_UInt128 ' :
103
103
low = self .low + other .low
104
- high = self .high + other .high + UInt64 (int (low .value > 0xFFFFFFFFFFFFFFFF ))
105
- return UInt128 (low & 0xFFFFFFFFFFFFFFFF , high & 0xFFFFFFFFFFFFFFFF )
104
+ high = self .high + other .high + _UInt64 (int (low .value > 0xFFFFFFFFFFFFFFFF ))
105
+ return _UInt128 (low & 0xFFFFFFFFFFFFFFFF , high & 0xFFFFFFFFFFFFFFFF )
106
106
107
- def __sub__ (self , other : 'UInt128 ' ) -> 'UInt128 ' :
108
- borrow = UInt64 (0 )
107
+ def __sub__ (self , other : '_UInt128 ' ) -> '_UInt128 ' :
108
+ borrow = _UInt64 (0 )
109
109
if self .low .value < other .low .value :
110
- borrow = UInt64 (1 )
110
+ borrow = _UInt64 (1 )
111
111
112
112
low = (self .low - other .low ) & 0xFFFFFFFFFFFFFFFF
113
113
high = (self .high - other .high - borrow ) & 0xFFFFFFFFFFFFFFFF
114
- return UInt128 (low , high )
114
+ return _UInt128 (low , high )
115
115
116
- def __mul__ (self , other : 'UInt128 ' ) -> NoReturn :
116
+ def __mul__ (self , other : '_UInt128 ' ) -> NoReturn :
117
117
# Multiplication logic here for 128 bits
118
118
raise NotImplementedError ()
119
119
120
- def __xor__ (self , other : 'UInt128 ' ) -> 'UInt128 ' :
120
+ def __xor__ (self , other : '_UInt128 ' ) -> '_UInt128 ' :
121
121
low = self .low ^ other .low
122
122
high = self .high ^ other .high
123
- return UInt128 (low , high )
123
+ return _UInt128 (low , high )
124
124
125
- def __and__ (self , other : 'UInt128 ' ) -> 'UInt128 ' :
125
+ def __and__ (self , other : '_UInt128 ' ) -> '_UInt128 ' :
126
126
low = self .low & other .low
127
127
high = self .high & other .high
128
- return UInt128 (low , high )
128
+ return _UInt128 (low , high )
129
129
130
- def __or__ (self , other : 'UInt128 ' ) -> 'UInt128 ' :
130
+ def __or__ (self , other : '_UInt128 ' ) -> '_UInt128 ' :
131
131
low = self .low | other .low
132
132
high = self .high | other .high
133
- return UInt128 (low , high )
133
+ return _UInt128 (low , high )
134
134
135
- def __lshift__ (self , shift : 'UInt128 ' ) -> NoReturn :
135
+ def __lshift__ (self , shift : '_UInt128 ' ) -> NoReturn :
136
136
# Left shift logic for 128 bits
137
137
raise NotImplementedError ()
138
138
139
- def __rshift__ (self , shift : 'UInt128 ' ) -> NoReturn :
139
+ def __rshift__ (self , shift : '_UInt128 ' ) -> NoReturn :
140
140
# Right shift logic for 128 bits
141
141
raise NotImplementedError ()
142
142
143
- def get_low (self ) -> UInt64 :
143
+ def get_low (self ) -> _UInt64 :
144
144
return self .low
145
145
146
- def get_high (self ) -> UInt64 :
146
+ def get_high (self ) -> _UInt64 :
147
147
return self .high
148
148
149
149
def as_tuple (self ) -> Tuple [int , int ]:
0 commit comments