mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
parent
5977fc994d
commit
9636459124
|
@ -97,7 +97,7 @@
|
|||
" # TODO: Implement me\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
" def hash_function(self, key):\n",
|
||||
" def _hash_function(self, key):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
|
|
|
@ -132,11 +132,11 @@
|
|||
" self.size = size\n",
|
||||
" self.table = [[] for _ in range(self.size)]\n",
|
||||
"\n",
|
||||
" def hash_function(self, key):\n",
|
||||
" def _hash_function(self, key):\n",
|
||||
" return key % self.size\n",
|
||||
"\n",
|
||||
" def set(self, key, value):\n",
|
||||
" hash_index = self.hash_function(key)\n",
|
||||
" hash_index = self._hash_function(key)\n",
|
||||
" for item in self.table[hash_index]:\n",
|
||||
" if item.key == key:\n",
|
||||
" item.value = value\n",
|
||||
|
@ -144,14 +144,14 @@
|
|||
" self.table[hash_index].append(Item(key, value))\n",
|
||||
"\n",
|
||||
" def get(self, key):\n",
|
||||
" hash_index = self.hash_function(key)\n",
|
||||
" hash_index = self._hash_function(key)\n",
|
||||
" for item in self.table[hash_index]:\n",
|
||||
" if item.key == key:\n",
|
||||
" return item.value\n",
|
||||
" raise KeyError('Key not found')\n",
|
||||
"\n",
|
||||
" def remove(self, key):\n",
|
||||
" hash_index = self.hash_function(key)\n",
|
||||
" hash_index = self._hash_function(key)\n",
|
||||
" for index, item in enumerate(self.table[hash_index]):\n",
|
||||
" if item.key == key:\n",
|
||||
" del self.table[hash_index][index]\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user