pair

ソースコード

from titan_pylib.data_structures.others.pair import Pair

view on github

展開済みコード

 1# from titan_pylib.data_structures.others.pair import Pair
 2class Pair:
 3
 4    # pair<unsigned int, unsigned int>
 5
 6    def __init__(self, first: int, second: int):
 7        self.d = (first << 32) | second
 8
 9    def __getitem__(self, k: int):
10        return self.d >> 32 if k == 0 else self.d & 4294967295
11
12    def __setitem__(self, k: int, v: int):
13        self.d = (v << 32) | (self.d & 4294967295) if k == 0 else self.d >> 32 << 32 | v
14
15    @property
16    def first(self) -> int:
17        return self.d >> 32
18
19    @property
20    def second(self) -> int:
21        return self.d & 4294967295
22
23    @first.setter
24    def first(self, v: int):
25        self.d = (v << 32) | (self.d & 4294967295)
26
27    @second.setter
28    def second(self, v: int):
29        self.d = self.d >> 32 << 32 | v
30
31    def __hash__(self):
32        return self.d
33
34    def __str__(self):
35        return f"[{self.d >> 32}, {self.d & 4294967295}]"
36
37    def __repr__(self):
38        return f"Pair({self.first}, {self.second})"

仕様

class Pair(first: int, second: int)[source]

Bases: object

property first: int
property second: int