golang-data-structures

Analyze Go slices, maps, and containers to recommend optimal data structures.

Updated Oct 1, 2024
One-click install
npx skills add https://github.com/mrlorentx/.files --skill golang-data-structures-mrlorentx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/mrlorentx/.files/tree/main/ai/claude/skills/golang-data-structures
Command: npx skills add https://github.com/mrlorentx/.files --skill golang-data-structures-mrlorentx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle to choose optimal data structures because understanding the internals of slices, maps, and standard containers is essential for writing memory-efficient and fast Go code. This skill explains Go's data-structure internals and provides practical guidance to select the right structure for a given workload.

Core Features & Use Cases

  • Slice internals, capacity growth, preallocation, and the slices package fundamentals.
  • Map internals, hash buckets, and when to preallocate to avoid rehashing.
  • Arrays and fixed-size patterns; container/list/heap/ring usage scenarios.
  • Strings.Builder vs bytes.Buffer; practical guidance for string assembly vs I/O buffering.
  • Generic collections and pointers (unsafe.Pointer, weak.Pointer); safety considerations and patterns.
  • Real-world scenarios: memory-conscious containers, performance-critical code, and implementing or tuning standard library patterns.

Quick Start

Analyze a Go project and recommend optimal data structures based on internals, including slices, maps, arrays, and container packages.

Frequently Asked Questions about golang-data-structures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do Go slices grow and when should I preallocate capacity?

Go slices grow dynamically by doubling capacity until a threshold, then increasing by a smaller factor. Preallocate slice capacity using make() when the final size is known to prevent memory allocation overhead and repeated copying during append operations.

What are the internals of Go maps and how do hash buckets work?

Go maps use hash tables with buckets holding up to eight key-value pairs. When buckets overflow, Go rehashes elements into larger bucket arrays, so preallocating map size avoids rehashing overhead during heavy insertion workloads.

When do I use strings.Builder vs bytes.Buffer in Go?

Use strings.Builder for efficient string concatenation without memory copying. Use bytes.Buffer for I/O buffering and byte slice manipulation. Builder is specialized for string assembly, while Buffer supports broader read-write operations.

Can I use unsafe.Pointer and weak.Pointer with generic collections in Go?

You can use unsafe.Pointer for manual memory layout manipulation and weak.Pointer for garbage collector-aware references. Both require strict safety considerations to prevent memory corruption when implementing generic container patterns.

What is the best way to choose between container/list, heap, and ring in Go?

Use container/list for doubly linked lists, heap for priority queues, and ring for circular buffers. Select based on your insertion and deletion patterns to achieve optimal memory layout and performance for specific workloads.

Why does my Go application have high memory usage with dynamic data structures?

High memory usage often results from slice and map growth behavior causing over-allocation. Analyze internal mechanics and apply preallocation guidance to optimize memory layout and reduce garbage collection pressure.