golang-data-structures

Select Go data structures for performance, safety, and idiomatic correctness.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-data-structures-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-data-structures
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-data-structures-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you choose and use the right Go data structures with confidence, avoiding performance traps, memory waste, and incorrect tradeoffs in everyday engineering work.

Core Features & Use Cases

  • Slices and maps: Preallocate correctly, reason about growth, avoid aliasing pitfalls, and pick the right value or pointer strategy.
  • Standard containers: Use container/list, container/heap, and container/ring when their access patterns fit better than slices or custom code.
  • Strings, generics, and pointers: Decide between strings.Builder and bytes.Buffer, design type-safe generic containers, and handle pointer semantics, unsafe usage, and weak references safely.
  • Use case: When building a cache, scheduler, parser, or high-throughput API, this Skill helps you justify the data structure choice and produce idiomatic Go code that scales.

Quick Start

Use the golang-data-structures skill to review my Go use case and recommend the best data structure, with an explanation of the tradeoffs and an idiomatic implementation.

Frequently Asked Questions about golang-data-structures

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

FAQPage Schema
How do I choose the right Go data structure for high-throughput API performance?

Choosing the right Go data structure requires evaluating slices, maps, and standard containers for preallocation, growth, and access patterns. This Skill recommends the optimal structure by analyzing your specific use case and explaining the performance tradeoffs and idiomatic implementation details.

What is the difference between strings.Builder and bytes.Buffer in Go?

The difference between strings.Builder and bytes.Buffer lies in their memory allocation and copy behavior. This Skill helps you decide between them based on your need for string concatenation versus mutable byte manipulation, ensuring safe pointer semantics and performance optimization.

When should I use container/heap or container/list instead of slices in Go?

You should use container/heap or container/list instead of slices when your access patterns require priority queue operations or doubly linked list semantics. This Skill identifies when these standard containers fit better than slices to avoid memory waste and performance traps.

How do I design type-safe generic data structures in Go?

Designing type-safe generic data structures in Go involves using generics to enforce compile-time type safety and map key comparability. This Skill provides idiomatic implementation patterns for generic containers and explains how to handle pointer semantics and unsafe usage safely.

Why does my Go map cause memory waste and how can I preallocate it correctly?

Your Go map causes memory waste due to unexpected growth and aliasing pitfalls when not preallocated correctly. This Skill enforces proper preallocation strategies and helps you reason about map growth, copy behavior, and value versus pointer strategies to optimize performance.

Can I use unsafe pointers with Go slices for optimization without breaking safety?

Using unsafe pointers with Go slices for optimization requires strict adherence to unsafe pointer rules to avoid breaking safety. This Skill guides you through handling pointer semantics, weak references, and unsafe usage correctly, ensuring your optimization design decisions do not compromise idiomatic correctness.