agentsclimarketplace

Data structures

Skill kylejryan/better-code/skills/data-structures

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.From its SKILL.md

Install
npx -y skills add kylejryan/better-code --skill data-structures

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

5.9 KB, as published. Nobody here has run it

Data Structures

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.

The Design Method

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.

Structure Catalog by Priority

PriorityCategoryImpactPrefix
1Design MethodCRITICALmethod-
2Structure ImplementationsHIGHstructure-
3Language PerformanceMEDIUM-HIGHlang-
4Fundamentals ReferenceMEDIUMfundamental-

Available Structures

StructureWhen to UseReference
Multi-Index MapO(1) lookup by multiple fields on the same collectionstructure-multi-index-map.md
LRU CacheBounded cache with least-recently-used evictionstructure-lru-cache.md
Bloom FilterFast "definitely not in set" checks on massive setsstructure-bloom-filter.md
Ring BufferFixed-capacity FIFO with automatic overwritestructure-ring-buffer.md
Trie / Prefix TreePrefix-based string operations (autocomplete, routing)structure-trie.md
Sorted SliceRead-heavy ordered data with excellent cache localitystructure-sorted-slice.md
Concurrent Map (Go)Read-optimized map for high-concurrency goroutine accessstructure-concurrent-map.md
BitsetMembership and set operations on small bounded universesstructure-bitset.md
Object Pool (Go)Reducing GC pressure by reusing hot-path allocationsstructure-object-pool.md

Language-Specific Performance

  • references/lang-go-performance.md — Maps, slices, strings, allocations, concurrency primitives
  • references/lang-typescript-performance.md — Objects vs Maps, arrays, TypedArrays, V8 JIT behavior

Fundamentals Reference

  • references/fundamental-arrays-lists.md — Arrays, linked lists, stacks, queues, deques
  • references/fundamental-hash-trees.md — Hash tables, sets, BSTs, heaps, B-trees, tries, segment trees
  • references/fundamental-graphs-advanced.md — Graphs, sets/maps, union-find, bloom filters, persistent structures

Decision Checklist

Before building a custom data structure, verify:

  • Profiling (not intuition) identifies this data access as a bottleneck
  • The access pattern doesn't match any stdlib structure well
  • The expected speedup is 10x+ on the hot operation, OR the custom structure eliminates significant workaround code
  • The data set is large enough that algorithmic complexity matters (not n=50)
  • The structure's contract is clearly defined (what operations, what complexity, what thread-safety)
  • Benchmarks exist comparing the custom structure to the stdlib alternative on realistic data
  • The structure is well-tested, including edge cases (empty, single element, at capacity, concurrent access)
  • Documentation explains when to use this structure and when to stick with stdlib
  • Ownership is clear — someone will maintain this when bugs surface

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.

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.