- Notifications
You must be signed in to change notification settings - Fork1.6k
Open
Description
Case: Key exists after the first empty slot.
Issue: Code inserts the new (key,value) instead of updating existing (key,value).
Code in question:def find_slot(self, key, index): prob_range = self.get_prob_range(index) for prob_index in prob_range: if self.arr[prob_index] is None: return prob_index if self.arr[prob_index][0] == key: return prob_index raise Exception("Hashmap full") ```Maybe this can fix it:def find_slot(self, key, index): first_slot = None prob_range = self.get_prob_range(index) for prob_index in prob_range: if first_slot == None and self.arr[prob_index] is None: first_slot = prob_index if self.arr[prob_index][0] == key: return prob_index if first_slot is not None: return first_slot raise Exception("Hashmap full")
Metadata
Metadata
Assignees
Labels
No labels