golang-data-structures

Analyze Go slice and map internals to optimize data structure selection.

2|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/adibfirman/dotfiles --skill golang-data-structures-adibfirman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/adibfirman/dotfiles/tree/main/claude/.claude/skills/technical/golang/golang-data-structures
Command: npx skills add https://github.com/adibfirman/dotfiles --skill golang-data-structures-adibfirman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps Go engineers pick and implement the correct data structures by reasoning about memory layout, allocation and growth behavior, and real-world performance tradeoffs.

Core Features & Use Cases

  • Slice internals and capacity strategy: explains slice headers, backing-array sharing, growth costs, and when to preallocate or use slices utilities.
  • Map internals and performance: covers bucketed hash table behavior, preallocation to avoid rehashing, and practical guidance on map usage patterns.
  • Standard containers and string/data building: guides when to use container/list, container/heap, container/ring, bufio, strings.Builder vs bytes.Buffer, plus generics and pointer safety.
  • Safety-focused pitfalls: highlights common bugs like append aliasing, defensive copying needs, unsafe.Pointer usage rules, nil map traps, and GC-safe weak.Pointer cache patterns.

Quick Start

Use the golang-data-structures skill to help you decide whether to use a slice vs array, a map vs pointer-to-map value, or container/heap vs a custom structure for a given hot-path in a Go service.

Frequently Asked Questions about golang-data-structures

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

FAQPage Schema
How do I preallocate Go slices and maps to avoid rehashing and growth costs?

Preallocate Go slices and maps using capacity hints to prevent dynamic backing-array reallocation and bucket rehashing, reducing memory allocation overhead and improving performance-critical hot path execution speed.

What is the best way to avoid append aliasing bugs with Go slice backing arrays?

Avoid Go slice append aliasing by applying defensive copying when sharing backing arrays, ensuring modifications to appended elements do not corrupt original slice data through unintended memory layout sharing.

When should I use container/heap or container/list instead of custom Go data structures?

Use standard library containers like container/heap for priority queues or container/list for linked lists when generic standard-library container selection satisfies your requirements without needing custom low-level memory management.

How do I implement weak pointer cache patterns in Go that are GC-safe?

Implement GC-safe weak pointer cache patterns in Go by adhering to safe unsafe.Pointer usage rules, preventing memory leaks while allowing garbage collection of unreferenced cache entries during runtime.

strings.Builder vs bytes.Buffer: which is best for building strings in Go?

Choose strings.Builder over bytes.Buffer for Go string building when read-only string output is required, as it avoids unnecessary memory allocation copies during the final string conversion step.

Does using unsafe.Pointer in Go data structures have safety limitations?

Using unsafe.Pointer in Go data structures carries safety limitations requiring strict adherence to unsafe.Pointer patterns to prevent memory corruption, invalid pointer conversion, and garbage collector instability issues.