From ebc0272dcf5c5086f58d10fd3aba90d8674a1b80 Mon Sep 17 00:00:00 2001 From: Medium Fries Date: Thu, 28 Mar 2019 14:03:49 -0700 Subject: [PATCH] first pass of chaining function in python --- 370/samples/chaining.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 370/samples/chaining.py diff --git a/370/samples/chaining.py b/370/samples/chaining.py new file mode 100644 index 0000000..01fcfb0 --- /dev/null +++ b/370/samples/chaining.py @@ -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