Algorithm 5 Hash table class HashMapBase (MapBase): definit__(self, cap=11, p=109345121): self._table = cap [None] self.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Algorithm 5 Hash table class HashMapBase (MapBase): definit__(self, cap=11, p=109345121): self._table = cap [None] self.

Post by answerhappygod »

Algorithm 5 Hash Table Class Hashmapbase Mapbase Definit Self Cap 11 P 109345121 Self Table Cap None Self 1
Algorithm 5 Hash Table Class Hashmapbase Mapbase Definit Self Cap 11 P 109345121 Self Table Cap None Self 1 (115.22 KiB) Viewed 114 times
Question: Review the generic hash tableimplementation in Algorithm 5.
Explain why attribute _n is updated in __delitem__(self, k) butnot updated in __setitem__(self, k, v).
Algorithm 5 Hash table class HashMapBase (MapBase): definit__(self, cap=11, p=109345121): self._table = cap [None] self. n = 0 self. prime = p self._scale = 1 + randrange (p-1) self. shift = randrange (p) def hash_function(self, k): return (hash (k) *self._scale + self._shift) \ % self._prime % len (self._table) deflen(self): return self._n def getitem_(self, k): j= self._hash_function (k) return self._bucket_getitem (j, k) def setitem(self, k, v): j = self._hash_function (k) self._bucket_setitem (j, k, v) if self._n > len(self._table) // 2: self._resize (2 def delitem_(self, k): j = self._hash_function (k) self._bucket_delitem (j, k) self. n = 1 def resize (self, c): old len(self._table) - 1) list (self.items ()) self._table = c* [None] self._n = 0 for (k, v) in old: self [k] = V
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply