dict1={'name': 'mike', 'dob': '1999-01-01', 'gender': 'male'}
# python3.6之前,散列类型,假设开辟了一个长度为20的空间
entry=[
# ["key的哈希值","key","value"],存在下标是"key的哈希值%20"的位置,如果散列冲突,有一个散列冲突的算法
["None","None","None"],
["None","None","None"],
["None","None","None"],
["-6012638457009940417","name","mike"],
["-4396601579178830235","gender","male"],
["None","None","None"],
["None","None","None"],
["None","None","None"],
["None","None","None"],
["-8437040987111082449","dob","1999-01-01"],
["None","None","None"],
...
]
print('gender'.__hash__()) # 示范取一个哈希值,实际逻辑并不是用这个方法取哈希值
print('gender'.__hash__()%20)
# 访问时,根据key的哈希值取余,找到下标,key值是否相同,如果相同,取出value,如果不一样,根据散列冲突时的方案,找到真正的key
# 3.6之后,序列类型,会建两个列表id通过散列存下标,entry通过序列存哈希值、key、value
# 访问时,根据key的哈希值取余,得到id列表的下标,对应的值就是entry里的下标,找到entry里的元素,取出value
id=[
[],[],[0],[1],[],[],[],[],[3],[],...
]
entry=[
["-6012638457009940417","name","mike"],
["-4396601579178830235","gender","male"],
["-8437040987111082449","dob","1999-01-01"],
]
网友评论