{"id":47974766,"url":"https://github.com/spenserblack/lookup.go","last_synced_at":"2026-04-04T10:53:35.201Z","repository":{"id":327823733,"uuid":"1110603955","full_name":"spenserblack/lookup.go","owner":"spenserblack","description":"A type for looking up the presence of a value. Either a slice or a set depending on the collection size.","archived":false,"fork":false,"pushed_at":"2025-12-06T01:39:49.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T10:53:31.528Z","etag":null,"topics":["data-structures","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spenserblack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-05T12:51:36.000Z","updated_at":"2025-12-06T01:39:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/spenserblack/lookup.go","commit_stats":null,"previous_names":["spenserblack/lookup.go"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/spenserblack/lookup.go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spenserblack%2Flookup.go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spenserblack%2Flookup.go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spenserblack%2Flookup.go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spenserblack%2Flookup.go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spenserblack","download_url":"https://codeload.github.com/spenserblack/lookup.go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spenserblack%2Flookup.go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31397055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","golang"],"created_at":"2026-04-04T10:53:32.313Z","updated_at":"2026-04-04T10:53:35.085Z","avatar_url":"https://github.com/spenserblack.png","language":"Go","readme":"# `lookup.go`\n\nA type for looking up the presence of a value. Either a slice or a set depending on the\ncollection size.\n\nFor very small collections (around 10 or less items), it can be faster to find a\nvalue by iterating over a slice rather than using a map. The `Lookup` type abstracts\nslices and maps so that you have one interface for both.\n\n## When to use this\n\n- The size of the collection is known and not subject to much change.\n- The order of the elements does not matter.\n- You are primarily using the collection to look for the presence of a value.\n\n## When to *not* use this\n\n- You will be frequently adding or removing elements from the collection after\n  populating its initial values.\n- You need to preserve the order of the elements in the collection.\n\n## Example\n\n```go\nconst sizeThreshold int = 10\n\n// This will be backed by a slice because the number of items is below the threshold.\ncolorDisplayChoices := lookup.New[string](sizeThreshold, \"auto\", \"on\", \"off\")\ncolorDisplayChoice := getUserInput()\nif !colorDisplayChoices.Has(colorDisplayChoice) {\n\tfmt.Printf(\"%q is not a valid choice!\\n\", colorDisplayChoice)\n}\n\nconst minYear int = 1900\nconst maxYear int = 2025\nconst size int = maxYear - minYear + 1\n// This will be backed by a map because the size is above the threshold.\nyearChoices := lookup.WithSize[int](sizeThreshold, size)\nfor i := minYear; i \u003c= maxYear; i++ {\n\tyearChoices.Add(i)\n}\nyearChoice := getUserIntInput()\nif !yearChoices.Has(yearChoice) {\n\tfmt.Printf(\"%d is not a valid year!\\n\", yearChoice)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspenserblack%2Flookup.go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspenserblack%2Flookup.go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspenserblack%2Flookup.go/lists"}