feat(container/gset): add generic set feature#4492
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a generic set implementation TSet[T] to the gset package, refactoring existing type-specific sets (Set, StrSet, IntSet) to use this new generic implementation. This eliminates code duplication while maintaining backward compatibility through wrapper types with lazy initialization.
Key changes:
- Added new generic
TSet[T comparable]type with full set operations - Refactored
Set,StrSet, andIntSetto embedTSetwith lazy initialization viasync.Once - Reduced code duplication by delegating operations to the generic implementation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
| container/gset/gset_t_set.go | New generic set implementation with all core set operations |
| container/gset/gset_str_set.go | Refactored to wrap TSet[string] with lazy initialization |
| container/gset/gset_int_set.go | Refactored to wrap TSet[int] with lazy initialization |
| container/gset/gset_any_set.go | Refactored to wrap TSet[any] with lazy initialization |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (2)
container/gset/gset_str_set.go:113
- After refactoring,
set.muandset.dataare no longer direct fields ofStrSet. This code should be updated to delegate toset.TSet.Remove(item)instead of directly accessing the mutex and data map.
set.mu.Lock()
if set.data != nil {
delete(set.data, item)
}
set.mu.Unlock()
container/gset/gset_str_set.go:254
- After refactoring,
set.muandset.dataare no longer direct fields ofStrSet. This Walk implementation should delegate toset.TSet.Walk(f)instead of directly accessing the embedded type's fields.
set.mu.Lock()
defer set.mu.Unlock()
m := make(map[string]struct{}, len(set.data))
for k, v := range set.data {
m[f(k)] = v
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add generic set featrue: TSet[T]