golang-data-structures

Guide Go developers in selecting and implementing data structures with correct performance and memory behavior.

Updated May 28, 2026
One-click install
npx skills add https://github.com/vanstinator/semantic-search --skill golang-data-structures-vanstinator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/vanstinator/semantic-search/tree/main/.agents/skills/golang-data-structures
Command: npx skills add https://github.com/vanstinator/semantic-search --skill golang-data-structures-vanstinator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps Go engineers pick the right data structures for performance, memory layout, and correctness by explaining how slices, maps, containers, strings, generics, and pointers actually behave.

Core Features & Use Cases

  • Slices & Maps Internals: Understand capacity growth, preallocation, slice header aliasing risks, map bucket structure, and why maps don’t shrink after deletes.
  • Standard Library Container Guidance: Select among container/list, container/heap, container/ring, and bufio based on access patterns and complexity tradeoffs.
  • Correct String/Byte Buffer Choice: Prefer strings.Builder for building strings and bytes.Buffer for I/O and byte-oriented use cases, including Grow guidance.
  • Generics & Pointer Safety: Use tight constraints (comparable, cmp.Ordered) and apply safe pointer patterns, including unsafe.Pointer’s spec-limited conversions and weak.Pointer usage for GC-friendly caches.
  • Copy Semantics Decisioning: Predict when assignment copies headers vs values, and when shared backing arrays or references can cause subtle bugs.

Quick Start

Ask an AI coding agent to design a Go cache or container for your access pattern (reads/writes ratio, mutation frequency, ordering needs, and expected size) and justify each data-structure choice using slices/maps internals, copy semantics, and safety pitfalls.

Frequently Asked Questions about golang-data-structures

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

FAQPage Schema
Why does my Go map not shrink after deleting keys, and how do I manage memory?

Go maps do not shrink after deletes due to their bucket structure. To manage memory, you must copy remaining keys to a new map or use weak.Pointer for GC-friendly caches to allow garbage collection of unused entries.

What is the best way to choose between strings.Builder and bytes.Buffer in Go?

Choose strings.Builder for building strings and bytes.Buffer for I/O and byte-oriented use cases. Apply Grow guidance to preallocate capacity and reduce allocations during hot-path operations.

How do I prevent slice header aliasing and append bugs in Go?

Prevent slice header aliasing by understanding copy semantics and shared backing arrays. Use the copy function or explicit allocation when appending to slices to avoid subtle bugs where modifications affect aliased data.

When should I use unsafe.Pointer conversions and weak.Pointer in Go generics?

Use unsafe.Pointer for spec-limited valid conversions and weak.Pointer for GC-friendly caches. Apply tight constraints like comparable or cmp.Ordered when building generic containers to ensure type safety.

How do I select the right container package for my Go access pattern?

Select among container/list, container/heap, and container/ring based on access patterns and complexity tradeoffs. Use container/heap for priority queues, container/list for linked lists, and container/ring for circular buffers.

Do I need to preallocate Go slices and maps for better performance?

Preallocate slices and maps during hot-path creation to avoid capacity growth overhead. Understanding slice capacity growth rules and map bucket internals helps optimize memory layout and reduce allocation latency.