From cb9633cc38a1d94b912e0d3fa107fd38988b3853 Mon Sep 17 00:00:00 2001 From: Alvarrir <61258288+Alvarrir@users.noreply.github.com> Date: Thu, 15 Oct 2020 20:47:13 +0800 Subject: [PATCH] Added delete function in separate copy of code --- computing_sh/Python11_Hash_Table_Search.ipynb | 98 ++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/computing_sh/Python11_Hash_Table_Search.ipynb b/computing_sh/Python11_Hash_Table_Search.ipynb index 0450863..6b1f01e 100644 --- a/computing_sh/Python11_Hash_Table_Search.ipynb +++ b/computing_sh/Python11_Hash_Table_Search.ipynb @@ -207,4 +207,100 @@ ] } ] -} \ No newline at end of file +} + + +# hash function +def hash(key): + return key % N + +def insert(key, data): + index = hash(key) + if hash_table[index] == -1: # available + hash_table[index] = data + else: # collision + i = index + 1 + while hash_table[i] != -1: + i += 1 + hash_table[i] = data + +def search(key, data): + index = hash(key) + if hash_table[index] == data: # found + return "BINGO!" + elif hash_table[index] == -1: + return "Not found" + else: # collided records + i = index + 1 + if i