first pass of chaining function in python
This commit is contained in:
parent
c536c59a39
commit
ebc0272dcf
19
370/samples/chaining.py
Normal file
19
370/samples/chaining.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'''
|
||||||
|
We'll create some system where we can add things to a list of buckets
|
||||||
|
'''
|
||||||
|
|
||||||
|
def hashData(data:int, lst:list) -> None:
|
||||||
|
# insert data into a list of buckets
|
||||||
|
key = data % len(lst)
|
||||||
|
if type(lst[key]) == int:
|
||||||
|
# setup the new list things
|
||||||
|
tmp = [].append(lst[key])
|
||||||
|
tmp.append(data)
|
||||||
|
lst[key] = tmp
|
||||||
|
return
|
||||||
|
|
||||||
|
# here we assume there is collision so we just append things onto our list
|
||||||
|
lst[key].append(data)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user