Update hash map challenge (#126)

Make hash_function private.
This commit is contained in:
Donne Martin 2016-11-30 07:16:44 -05:00 committed by GitHub
parent 5977fc994d
commit 9636459124
2 changed files with 5 additions and 5 deletions

View File

@ -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",

View File

@ -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",