Coding
AI Prompt for Custom Data Structures
Design custom data structures with this AI prompt: operation-driven design, implementation with invariants, and honest build-vs-buy guidance.
The prompt
Role: You are a data structures designer who builds custom structures only when justified — and builds them correctly. Context: Problem: [PROBLEM]. Language: [LANGUAGE]. Required operations: [OPERATIONS with complexity targets]. Task: 1) Verdict first: build custom or use existing (library/combination)? Justify honestly — custom structures are a maintenance cost. 2) If custom: design the structure — internal representation, invariants, and each operation's algorithm with complexity. 3) Provide the [LANGUAGE] implementation with invariant checks/assertions. 4) Write tests targeting the invariants and edge cases. 5) Document when this structure should be REPLACED by something standard as requirements evolve. Format: Verdict first, then design, then implementation, then tests, then the replacement guidance. Ask the AI to write a property-based test sketch: random operation sequences checked against a naive reference implementation. Custom structures earn trust through adversarial testing, not just unit tests. Constraints: Prove the standard options inadequate before building custom. Invariants must be explicit and asserted. The API should be minimal — only the operations in [OPERATIONS].
Variables to fill in
Replace each [variable] in the prompt with your own details:
[PROBLEM] [LANGUAGE] [OPERATIONS]
Example input
PROBLEM=autocomplete with typo tolerance for 500k product names, LANGUAGE=TypeScript, NEEDS=prefix search + fuzzy match within 50ms
How to use this prompt
Describe the operations the structure must support — design follows the API. Ask for the build-vs-buy verdict explicitly; custom structures are expensive.
Tips for the best results
- Take the build-vs-buy verdict seriously — most 'custom' needs are solved by combining standard structures.
- Ask it to prove the complexity claims with the operation algorithms.
- Document the invariants in the code; future maintainers need them.
Frequently asked questions
Should I really build custom?
It designs the structure around your operations, compares against off-the-shelf options, and is honest when you should NOT build custom.
How do I prove my custom structure is correct?
Invariant assertions plus differential testing against a simple reference. The prompt builds both into the implementation plan.