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: add generic Set implementation #8149

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

knqyf263
Copy link
Collaborator

What

  • Add generic Set[T] interface and its implementation using map[T]struct{} under the hood
  • Add convenient functions like New(), Clone(), and set operations (Union, Intersection, Difference)
  • Add linter rule to suggest using this set package instead of raw map[T]struct{}

Why

  • There are many occurrences of using map[T]struct{} as sets in our codebase, which could benefit from a more readable and feature-rich implementation
  • While several existing libraries provide the set implementations, I chose to implement it in our project because:
    1. The implementation is sufficiently simple and maintainable
    2. Avoiding additional external dependencies keeps our project more manageable
    3. We can customize the implementation to fit our specific needs
    4. It's easier to modify and extend the functionality as needed

Implementation Details

  • The Set interface is generic and accepts any comparable type
  • The implementation (unsafeSet) is not thread-safe by design, as that matches our current usage patterns

Additional Information

  • Added linter rule will help team members discover this package when they try to use map[T]struct{}
  • The implementation is intentionally kept minimal but extensible
  • Future improvements could include:
    • Thread-safe implementation if needed
    • Additional set operations (SymmetricDifference, IsSubset, etc.)

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@knqyf263 knqyf263 self-assigned this Dec 20, 2024
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