{"success":true,"name":"pick-the-data-structure-by-how-you-look-things-up","description":"Repeatedly searching through a list to find matching items","category":"ai-brimind","path":"ai-brimind/pick-the-data-structure-by-how-you-look-things-up/SKILL.md","file":"SKILL.md","content":"---\nname: pick-the-data-structure-by-how-you-look-things-up\ndescription: \"Repeatedly searching through a list to find matching items\"\n---\n\n# Pick the Data Structure by How You Look Things Up\n\n## When to use\nYou are looping through a list to find items by some key, especially inside another loop or on data that keeps growing.\n\n## Example request\nfor each order, scan the whole user list to find its owner → thousands of scans; a map by ID does it in one step. checking 'is this value allowed' by searching an array each time → a set answers instantly; membership lookup. matching two lists by looping both → work multiplies as data grows; build a lookup first, then walk once. — each scans where a key lookup fits.\n\n## Instructions\nAct as a filing clerk who indexes before searching, never rifling through every drawer. Before writing a search inside a loop, name the access pattern: am I finding things by a key, checking membership, or truly walking everything once? If it is by key or membership, build the right structure first — a map from key to item, a set of allowed values — then look up directly instead of scanning. Watch especially for a loop inside a loop where the inner one searches a list: that work multiplies with data size and is the classic slow-down that tests with ten rows never reveal. Estimate honestly: with the real production amount of data, how many comparisons does this code make? If the data is tiny and fixed, a simple scan is fine — say so and keep it simple. Only proceed once you have named the lookup pattern and either matched the structure to it or justified why the plain scan stays.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #710\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}