-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: go/types: add set
data type
#61884
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
Comments
|
Hi @Jorropo thanks for your opinion. I understand your concern about where to place the |
I'm going to mark this as a dup of the previous discussion. |
Duplicate of #47331 |
Hi there,
I'd like to propose the addition of a
set
data type to thego/types
package. Sets are a fundamental data structure widely used in various applications for efficient membership testing and eliminating duplicates. By introducing a nativeset
type, we can simplify code, improve readability, and enhance performance.Motivation:
Simplicity: Currently, developers often implement sets using maps or slices, resulting in boilerplate code and reduced clarity. A built-in
set
type would streamline this process.Performance: A dedicated
set
type can be optimized for common set operations like membership checks, union, intersection, and difference, leading to improved runtime efficiency.Code Readability: Introducing a
set
type would enhance code readability by making intentions clearer and reducing the need for workarounds.Design:
The
set
type can be implemented as a wrapper around a map with an empty struct type (map[T]struct{}
), whereT
represents the element type.Methods can include
Add
,Remove
,Contains
,Union
,Intersection
, andDifference
, providing a comprehensive set of operations.Compatibility with the existing
range
loop can be achieved by making theset
type implement theIterable
interface.Example Usage:
Impact:
The introduction of a native
set
type in thego/types
package would lead to more idiomatic and efficient Go code, benefiting both new and experienced developers. It would also align with Go's philosophy of simplicity and efficiency.Thanks,
Andrea Bruno
The text was updated successfully, but these errors were encountered: