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

Merged
merged 16 commits into from
Dec 24, 2024
Merged

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
@knqyf263 knqyf263 marked this pull request as ready for review December 23, 2024 05:22
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"pkgconf": {}, // pkgconfig => pkgconf
"musl": {},
},
want: set.New(
Copy link
Contributor

@DmitriyLewen DmitriyLewen Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Let's use same fmt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep a comment in this test case. Instead, I reverted others. a69fd66

@knqyf263 knqyf263 added this pull request to the merge queue Dec 24, 2024
Merged via the queue into aquasecurity:main with commit b5859d3 Dec 24, 2024
12 checks passed
@knqyf263 knqyf263 deleted the add_set branch December 24, 2024 05:08
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.

3 participants