refactor: Follow the PEP 585 Typing standard (#439)

* Follow the PEP 585 Typing standard

* Update list.py
This commit is contained in:
Yudong Jin
2023-03-23 18:51:56 +08:00
committed by GitHub
parent f4e01ea32e
commit 8918ec9079
43 changed files with 256 additions and 342 deletions

View File

@ -4,10 +4,6 @@ Created Time: 2022-12-14
Author: msk397 (machangxinq@gmail.com)
"""
import sys, os.path as osp
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
from modules import *
class Entry:
""" 键值对 int->String """
def __init__(self, key: int, val: str):
@ -19,7 +15,7 @@ class ArrayHashMap:
def __init__(self):
""" 构造方法 """
# 初始化数组,包含 100 个桶
self.buckets: List[Optional[Entry]] = [None] * 100
self.buckets: list[Entry | None] = [None] * 100
def hash_func(self, key: int) -> int:
""" 哈希函数 """
@ -46,25 +42,25 @@ class ArrayHashMap:
# 置为 None ,代表删除
self.buckets[index] = None
def entry_set(self) -> List[Entry]:
def entry_set(self) -> list[Entry]:
""" 获取所有键值对 """
result: List[Entry] = []
result: list[Entry] = []
for pair in self.buckets:
if pair is not None:
result.append(pair)
return result
def key_set(self) -> List[int]:
def key_set(self) -> list[int]:
""" 获取所有键 """
result: List[int] = []
result: list[int] = []
for pair in self.buckets:
if pair is not None:
result.append(pair.key)
return result
def value_set(self) -> List[str]:
def value_set(self) -> list[str]:
""" 获取所有值 """
result: List[str] = []
result: list[str] = []
for pair in self.buckets:
if pair is not None:
result.append(pair.val)