1. Add the building util of Python

for the markdown docs.
2. Update the deploy.sh
This commit is contained in:
krahets
2023-02-06 23:23:21 +08:00
parent 64f251f933
commit ea901af217
28 changed files with 292 additions and 933 deletions

37
docs/chapter_hashing/hash_map.md Normal file → Executable file
View File

@ -523,42 +523,9 @@ $$
=== "Python"
```python title="array_hash_map.py"
""" 键值对 int->String """
class Entry:
def __init__(self, key, val):
self.key = key
self.val = val
[class]{Entry}-[func]{}
""" 基于数组简易实现的哈希表 """
class ArrayHashMap:
def __init__(self):
# 初始化一个长度为 100 的桶(数组)
self.bucket = [None] * 100
""" 哈希函数 """
def hash_func(self, key):
index = key % 100
return index
""" 查询操作 """
def get(self, key):
index = self.hash_func(key)
pair = self.bucket[index]
if pair is None:
return None
return pair.val
""" 添加操作 """
def put(self, key, val):
pair = Entry(key, val)
index = self.hash_func(key)
self.bucket[index] = pair
""" 删除操作 """
def remove(self, key):
index = self.hash_func(key)
# 置为 None ,代表删除
self.bucket[index] = None
[class]{ArrayHashMap}-[func]{}
```
=== "Go"