golang-data-structures
Golang data structures — slices (internals, capacity growth, preallocation, slices package), maps (internals, hash buckets, maps package), arrays, container/list/heap/ring, strings.Builder vs bytes.Buffer, generic collections, pointers (unsafe.Pointer, weak.Pointer), and copy semantics. Use when choosing or optimizing Go data structures, implementing generic containers, using container/ packages, unsafe or weak pointers, or questioning slice/map internals.
Security Assessment
About golang-data-structures
The `golang-data-structures` skill provides a comprehensive understanding of Go's built-in and standard library data structures, including slices, maps, arrays, and specialized collections such as lists, heaps, and rings. It focuses on the internal mechanics of these structures, helping developers reason about memory layout, allocation costs, access patterns, and correct usage. This skill addresses common pitfalls in Go programming, such as slice and map aliasing, preallocation, and copy semantics, enabling developers to write more efficient and robust code.
Key features of this skill include detailed insights into slice and map internals, growth strategies, preallocation techniques, and use of the `slices` package introduced in Go 1.21. It provides guidance on when to prefer arrays over slices, best practices for using standard library containers like `container/heap`, `container/list`, and `container/ring`, and the proper use of `strings.Builder` versus `bytes.Buffer`. Additionally, it covers generic collections with appropriate constraints, safe usage of `unsafe.Pointer`, and use of `weak.Pointer` for cache or canonicalization purposes in Go 1.24+.
This skill is intended for Go developers, software engineers, and coding agents who need to optimize data structure usage in their applications. It is particularly valuable for those implementing generic containers, working with unsafe or weak pointers, or aiming to understand the performance characteristics of slices and maps. The skill is compatible with Claude Code and similar AI coding agents, making it useful both for human programmers seeking guidance and AI systems assisting in Go development projects.
FAQ
How do I preallocate slices and maps using this skill?
You can preallocate slices and maps when the size is known or estimable using `make(T, 0, n)` for slices and `make(map[K]V, n)` for maps. This avoids repeated growth copies and rehashing, improving performance.
Which Go versions are compatible with features like `slices.Grow` and `weak.Pointer`?
`slices.Grow` is available starting with Go 1.21, and `weak.Pointer[T]` requires Go 1.24 or later.
Can I rely on slice capacity growth to predict allocations?
No. The slice growth algorithm has changed between Go versions and may change again. Code should not depend on the timing of new backing array allocations.
What containers should I use for priority queues or frequent middle insertions?
Use `container/heap` for priority queues, `container/list` for frequent middle insertions, and `container/ring` for fixed-size circular buffers.
Is this skill compatible with AI coding agents?
Yes. It is designed for Claude Code or similar AI coding agents and can be used in projects using the Go programming language.
Install golang-data-structures
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
samber/cc-skills-golang