Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Hashtable - Linear probing __setitem__ not considering updates. #78

Open
@ManuMathewVarghese

Description

@ManuMathewVarghese

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp