擅长:python、mysql、java
<p>我相信,通过添加第三级,他们说的是,与其为每个键都有一个值,不如有一个列表。在</p>
<p>所以我们换套:</p>
<pre><code>def set(aMap, key, value):
"""Sets the key to the value, only adds new values"""
bucket = get_bucket(aMap, key)
i, k, vlist = get_slot(aMap, key)
if i >= 0:
# check if value is already in list, if so, do nothing
if value in vlist:
return
# the key exists, so just add they value to it
vlist.append(value)
else:
# the key is not in table, add a list for the key
# allows multiple values for each key
bucket.append((key, list(value)))
</code></pre>
<p>我相信其他函数没有改变。注意get()将返回一个列表,而不是一个值。在</p>