Skip to content

Commit 8bb930b

Browse files
committed
Make TSID hashable
1 parent 0cbea52 commit 8bb930b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [1.1.5] - 2023-11-28
10+
11+
### Added
12+
13+
- Make `TSID` values hashable.
14+
915
## [1.1.4] - 2023-11-09
1016

1117
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tsidpy"
7-
version = "1.1.4"
7+
version = "1.1.5"
88
authors = [
99
{ name="Luis Medel", email="[email protected]" },
1010
]

src/tsidpy/tsid.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ def __init__(self, number: int) -> None:
7474
"""
7575
self.__number: int = number & 0xffffffffffffffff # 64-bit
7676
self._epoch: float = TSID_EPOCH
77+
78+
def __hash__(self) -> int:
79+
"""
80+
>>> hash(TSID(0))
81+
0
82+
>>> hash(TSID(1))
83+
1
84+
>>> hash(TSID(0xffffffffffffffff)) == hash(0xffffffffffffffff)
85+
True
86+
>>> d = dict()
87+
>>> d[TSID(0)] = 0
88+
>>> d[TSID(1)] = 1
89+
>>> d[TSID(0xffffffffffffffff)] = "big"
90+
>>> d[TSID(0)]
91+
0
92+
>>> d[TSID(1)]
93+
1
94+
>>> d[TSID(0xffffffffffffffff)]
95+
'big'
96+
"""
97+
return self.__number.__hash__()
7798

7899
@property
79100
def timestamp(self) -> float:

0 commit comments

Comments
 (0)