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

Wildcard tree search enhancement and tests #4781

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

ramon-bernardo
Copy link
Contributor

@ramon-bernardo ramon-bernardo commented Sep 6, 2024

Pull Request Prelude

  • I have followed [proper The Forgotten Server code styling][code].
  • I have read and understood the [contribution guidelines][cont] before making this PR.
  • I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.

Changes Proposed:

  • Tests: Added comprehensive unit tests to verify the functionality of the WildcardTree.

  • Code modernization: Utilized auto in appropriate places to enhance code readability and maintainability. For further insights, please refer to Herb Sutter's explanation.

  • Function renaming: Updated function names to follow snake_case for consistency with modern C++.

  • Search behavior refinement: Modified the search function to return a more descriptive result using a pair consisting of a custom SearchResult enum and the matched string. This change eliminates the need for the previous ReturnValue.

  • Namespace: Removed the instantiation of a root, updating all usages to directly utilize the tfs::game::wildcardtree namespace, which enhances clarity and reduces potential errors.

Memory management improvements

  • Transitioned from raw pointers to std::shared_ptr for improved memory safety, significantly reducing the risk of memory leaks and ensuring proper resource management throughout the WildcardTree implementation.

Usage

// Example of adding and searching for strings in the WildcardTree
tfs::game::wildcardtree::add("hello");
tfs::game::wildcardtree::add("world");

// Search for an exact match for "hello".
auto search_result = tfs::game::wildcardtree::search("hello");
if (search_result.first == WildcardTreeSearchResult::Found) {
    // Found exact match
}

// Search for a non-existing string.
search_result = tfs::game::wildcardtree::search("nonexistent");
if (search_result.first == WildcardTreeSearchResult::NotFound) {
    // The string was not found
}

// Remove the string "world" from the WildcardTree.
tfs::game::wildcardtree::remove("world");

@ramon-bernardo
Copy link
Contributor Author

Ready for review and merge! @ranisalt ;)

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