golang-data-structureslisted
Install: claude install-skill reagin/agent-skills
# Go Data Structures
Choose the simplest representation that satisfies the operation, ownership, and lifecycle requirements. Internal runtime layouts and growth policies are implementation details unless the current toolchain documents them as API.
## Gather requirements
Before changing a representation, inspect nearby code, `go.mod`, tests, serialization contracts, concurrency, and performance evidence. Determine:
- dominant operations and their required complexity;
- expected and worst-case size;
- insertion, deletion, and ordering requirements;
- uniqueness and key equality rules;
- mutation and ownership across API boundaries;
- whether nil, empty, and absent have distinct external meaning;
- whether the structure is shared concurrently;
- whether allocation or retention is a measured concern.
Do not replace a familiar built-in type with a custom container solely for theoretical complexity at small sizes.
## Selection guide
| Need | Starting point | Important trade-off |
| --- | --- | --- |
| Ordered, indexable sequence | Slice | Append can replace the backing array; subslices can retain or alias data |
| Fixed-size comparable value | Array | Assignment copies the full value; size is part of the type |
| Keyed lookup | Map | Iteration order is unspecified; map access is not safe with concurrent writes |
| Set membership | `map[T]struct{}` or project type | Decide whether a named abstraction improves the API |
| Priority queue | `container/heap` | Interface adapter