skills/data-structures/SKILL.md
Use this skill when designing or implementing custom data structures optimized for a specific internal use case. Triggers when the user needs a data structure that outperforms stdlib defaults for their access pattern — things like 'I need a fast lookup for X,' 'this map is too slow,' 'I need to intersect/union/diff these sets efficiently,' 'what's the best structure for this query pattern,' 'this is O(n) and needs to be O(1),' 'I need a cache/index/queue/pool/ring buffer/trie/bloom filter,' or any discussion of internal data structure design for performance-sensitive code. Also triggers when profiling reveals a hot path bottleneck in data access. Primarily targets TypeScript and Go. Do NOT use for general coding tasks, API design, or database schema design unless a custom in-memory data structure is the solution.
npx skillsauth add kylejryan/better-code data-structuresInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Stdlib data structures are general-purpose by design — they optimize for the average case across all possible use cases. Internal tooling has specific, known access patterns. When you know exactly how data will be read, written, searched, and iterated, you can build a data structure that is dramatically faster than the general-purpose default.
The threshold question: if the code runs once during startup, use whatever is simplest. If it runs on every request, in a tight loop, or on a hot path identified by profiling — that's when custom structures earn their keep.
Never start from "what data structure should I use?" Start from "what operations does my code actually perform on this data, and at what frequency?"
Step 1: Profile the Access Pattern. Answer questions about write patterns, read patterns, size/lifecycle, concurrency, and derived operations. The answers determine the optimal structure. See references/method-access-pattern-profiling.md for the full question set.
Step 2: Match the Pattern to a Structure. Use the decision trees for exact key lookup, collection membership, ordered data, and specialized patterns. See references/method-pattern-matching.md for the complete decision map.
Step 3: Evaluate Build vs Use Stdlib. Not every access pattern needs a custom structure. Apply the build-vs-stdlib test and the 10x rule. See references/method-build-vs-stdlib.md.
Step 4: Implement, Benchmark, Validate. Interface first. Benchmark before and after. Property-test invariants. Document the contract. See references/method-build-vs-stdlib.md.
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Design Method | CRITICAL | method- |
| 2 | Structure Implementations | HIGH | structure- |
| 3 | Language Performance | MEDIUM-HIGH | lang- |
| 4 | Fundamentals Reference | MEDIUM | fundamental- |
| Structure | When to Use | Reference |
|-----------|-------------|-----------|
| Multi-Index Map | O(1) lookup by multiple fields on the same collection | structure-multi-index-map.md |
| LRU Cache | Bounded cache with least-recently-used eviction | structure-lru-cache.md |
| Bloom Filter | Fast "definitely not in set" checks on massive sets | structure-bloom-filter.md |
| Ring Buffer | Fixed-capacity FIFO with automatic overwrite | structure-ring-buffer.md |
| Trie / Prefix Tree | Prefix-based string operations (autocomplete, routing) | structure-trie.md |
| Sorted Slice | Read-heavy ordered data with excellent cache locality | structure-sorted-slice.md |
| Concurrent Map (Go) | Read-optimized map for high-concurrency goroutine access | structure-concurrent-map.md |
| Bitset | Membership and set operations on small bounded universes | structure-bitset.md |
| Object Pool (Go) | Reducing GC pressure by reusing hot-path allocations | structure-object-pool.md |
references/lang-go-performance.md — Maps, slices, strings, allocations, concurrency primitivesreferences/lang-typescript-performance.md — Objects vs Maps, arrays, TypedArrays, V8 JIT behaviorreferences/fundamental-arrays-lists.md — Arrays, linked lists, stacks, queues, dequesreferences/fundamental-hash-trees.md — Hash tables, sets, BSTs, heaps, B-trees, tries, segment treesreferences/fundamental-graphs-advanced.md — Graphs, sets/maps, union-find, bloom filters, persistent structuresBefore building a custom data structure, verify:
The fastest data structure is the one you don't need. The second fastest is the right stdlib structure used correctly. Custom structures are the third option — powerful, but they carry maintenance cost. Build them when the evidence demands it.
development
Use this skill when performing the actual vulnerability analysis AFTER a threat model has been established (see threat-model skill). Triggers when the user asks to find vulnerabilities, audit code for security, hunt for bugs, or perform security review of source code AND a threat model already exists or the codebase context is clear. This skill enforces depth-first, exploitability-proven analysis — it actively prevents the breadth-first pattern-matching that produces lists of theoretical vulnerabilities. Do NOT use without a threat model; use threat-model skill first. Do NOT use for general code quality review.
development
Staff+ engineering patterns for maximum leverage per line of code. Use this skill when designing abstractions, building reusable primitives, creating shared libraries, reducing code through architecture, reviewing code for leverage and reuse potential, choosing between building vs configuring, or establishing conventions and patterns across a codebase.
development
Use this skill when designing test strategies, writing tests beyond basic unit tests, verifying software for production readiness, or improving test coverage and reliability. Triggers when the user asks about testing strategy, integration tests, end-to-end tests, contract tests, property-based tests, load tests, chaos testing, test architecture, flaky tests, test confidence, 'how do I test this,' 'how do I know this is safe to deploy,' 'my tests are flaky,' 'what should I test,' 'test coverage,' CI/CD test pipelines, or any question about software verification and validation. Also triggers when the user is shipping a change and wants confidence it won't break production. Primarily targets TypeScript and Go but principles apply universally. Do NOT use for writing basic unit tests for simple functions — this skill is for the harder testing questions.
development
Use this skill when debugging software issues, performing root cause analysis, triaging errors from logs or alerts, or investigating why code isn't working as expected. Triggers when the user shares an error message, stack trace, log output, failing test, unexpected behavior, crash report, performance degradation, or says things like 'this isn't working,' 'I'm getting an error,' 'help me debug,' 'why is this failing,' 'something broke,' or 'I can't figure out what's wrong.' Also use when the user has been going back and forth trying fixes that aren't working — this is the signal to stop guessing and start systematically diagnosing. Do NOT use for writing new code from scratch, general code review, or feature development unless a bug is involved.