A generic, battle-tested set collection for Go, providing Python-like set operations for comparable types.
golang-set is a Go library that provides a generic set data structure, allowing developers to manage collections of unique items with operations like union, intersection, and difference. It solves the lack of a built-in set type in Go's standard library, offering both threadsafe and non-threadsafe implementations for various use cases.
Go developers who need to work with collections of unique items, especially those coming from languages like Python that have built-in set types, or those building applications requiring efficient set operations.
Developers choose golang-set for its battle-tested reliability, generic type support, and comprehensive feature set that mimics Python's set operations, all while providing both performance-optimized and concurrent-safe implementations.
A simple, battle-tested and generic set type for the Go language. Trusted by GoogleCloudPlatform, Docker, 1Password, Ethereum and Hashicorp.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports any comparable type using Go 1.18+ generics, ensuring compile-time checks and reducing boilerplate for custom types, as highlighted in the usage examples.
Offers both non-threadsafe (for performance) and threadsafe (for concurrency) versions, allowing developers to optimize based on specific needs without switching libraries.
Includes Python-like union, intersection, and difference operations, minimizing manual loops and code duplication, as demonstrated in the comprehensive example.
Provides full marshaling and unmarshaling capabilities, making it easy to persist or transmit set data, though past bugs required fixes as noted in updates.
Requires Go 1.18 or higher, excluding legacy projects and adding migration overhead, which is a barrier for teams on older codebases.
The README admits bugs like JSON unmarshaling problems in past releases, indicating that updates can introduce regressions that need fixes.
For basic deduplication or membership checks, using native maps or slices might be more lightweight and less complex, making golang-set overkill in trivial scenarios.