Skip to content
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

refactor: optimize Matcher algorithm #56

Merged
merged 1 commit into from
Sep 23, 2024
Merged

refactor: optimize Matcher algorithm #56

merged 1 commit into from
Sep 23, 2024

Conversation

qwqcode
Copy link
Owner

@qwqcode qwqcode commented Sep 23, 2024

The PR included:

Separation of Concerns

  • Isolated the algorithm logic layer from the view layer by no longer using the MatchItem from the SubRenamer.Model namespace in the view layer.
  • Before calling the Execute function, the view layer's MatchItem is converted to the algorithm layer's MatchItem using MatcherDataConverter.ConvertMatchItems. After execution, the returned MatchItem is converted back to the view layer's format.

Use of Records:

  • Replaced classes with C# 9.0 Records for MatchItem and DiffResult data structures. This change emphasizes immutability, making testing easier.

Function Behavior:

  • Some functions now do not modify the input List in place. Instead, they return a new List copy. The input is defined as an immutable IReadOnlyList, promoting idempotency and simplifying testing.

Diff Result Calculation:

  • The GetDiffResult method has been modified to use a double loop, where i and j approach from both ends towards the center. It prioritizes matching the first and last items instead of adjacent ones. This aims to prevent incorrect DiffResult prefixes and suffixes when multiple identical filenames in different languages are encountered.

Improvements to FindCommonSuffix:

  • The input value Prefix has been removed from FindCommonSuffix.
  • The algorithm has been improved to use a two-pointer approach to skip over non-matching characters.

Type and Variable Modifications:

  • Various types have been modified, and some variable names have been renamed for clarity.

@qwqcode qwqcode merged commit d9dc4ab into main Sep 23, 2024
@qwqcode qwqcode deleted the refactor branch September 23, 2024 13:11
@qwqcode qwqcode linked an issue Sep 23, 2024 that may be closed by this pull request
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.

无法匹配
1 participant