Skip to content

trie: make deletion of Trie more readable when match shortNode #31889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

AshinGau
Copy link

@AshinGau AshinGau commented May 23, 2025

This PR refactors the delete logic for shortNode in the MPT implementation to improve code readability and consistency with the insert function.

Motivation
Previously, the code used:

dirty, child, err := t.delete(n.Val, append(prefix, key[:len(n.Key)]...), key[len(n.Key):])

However, at this point in the code, matchlen is always equal to len(n.Key), so using key[:matchlen] and key[matchlen:] is both clearer and stylistically consistent with the insert function. This change makes the code easier to read and maintain, and reduces potential confusion for future contributors.

@AshinGau AshinGau requested a review from rjl493456442 as a code owner May 23, 2025 12:48
@rjl493456442 rjl493456442 self-assigned this May 25, 2025
@rjl493456442
Copy link
Member

Thanks for the contribution, however, I think the change is unnecessary.

If matchLen equals to n.Key, it implies that the entire shortNode has been crossed. It's fine to use n.Key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants