Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. golang-set

golang-set

NOASSERTIONGov2.9.0

A generic, battle-tested set collection for Go, providing Python-like set operations for comparable types.

GitHubGitHub
4.7k stars291 forks0 contributors

What is golang-set?

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.

Target Audience

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.

Value Proposition

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.

Overview

A simple, battle-tested and generic set type for the Go language. Trusted by GoogleCloudPlatform, Docker, 1Password, Ethereum and Hashicorp.

Use Cases

Best For

  • Managing unique collections of comparable types in Go
  • Performing set operations like union, intersection, and difference
  • Deduplicating slices or arrays efficiently
  • Building concurrent applications that require threadsafe collections
  • Replacing manual loops with declarative set operations
  • Working with JSON-serializable collections of unique items

Not Ideal For

  • Projects stuck on Go versions below 1.18, as generics are required
  • Applications where minimal dependencies are critical and a simple map or slice suffices
  • Use cases requiring ordered collections or list-like indexing, since sets are unordered

Pros & Cons

Pros

Generic Type Safety

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.

Dual Implementation Flexibility

Offers both non-threadsafe (for performance) and threadsafe (for concurrency) versions, allowing developers to optimize based on specific needs without switching libraries.

Comprehensive Set Operations

Includes Python-like union, intersection, and difference operations, minimizing manual loops and code duplication, as demonstrated in the comprehensive example.

JSON Serialization Built-in

Provides full marshaling and unmarshaling capabilities, making it easy to persist or transmit set data, though past bugs required fixes as noted in updates.

Cons

Go Version Dependency

Requires Go 1.18 or higher, excluding legacy projects and adding migration overhead, which is a barrier for teams on older codebases.

Occasional Stability Issues

The README admits bugs like JSON unmarshaling problems in past releases, indicating that updates can introduce regressions that need fixes.

Overhead for Simple Use

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.

Frequently Asked Questions

Quick Stats

Stars4,704
Forks291
Contributors0
Open Issues11
Last commit27 days ago
CreatedSince 2013

Tags

#concurrent#go-library#data-structures#golang#threadsafe#generics#concurrency#set#datastructures#collections#go

Built With

G
Go

Included in

Go169.1k
Auto-fetched 17 hours ago

Related Projects

gosetgoset

Set is a useful collection but there is no built-in implementation in Go lang.

Stars53
Forks16
Last commit5 years ago
setset

A simple Set data structure implementation in Go (Golang) using LinkedHashMap.

Stars30
Forks12
Last commit9 months ago
dsudsu

Disjoint Set data structure implementation in Go

Stars18
Forks1
Last commit4 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub