{"id":36469077,"url":"https://github.com/xaionaro-go/iterate","last_synced_at":"2026-01-15T02:33:18.268Z","repository":{"id":331991768,"uuid":"960138717","full_name":"xaionaro-go/iterate","owner":"xaionaro-go","description":"A collection of generic iterators (currently has only an iterator for a 2D plane)","archived":false,"fork":false,"pushed_at":"2025-04-06T12:38:32.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T02:35:49.973Z","etag":null,"topics":["2d","iter","iterator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaionaro-go.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-04-03T23:27:23.000Z","updated_at":"2025-04-06T12:38:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/xaionaro-go/iterate","commit_stats":null,"previous_names":["xaionaro-go/iterate"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/xaionaro-go/iterate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fiterate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fiterate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fiterate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fiterate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaionaro-go","download_url":"https://codeload.github.com/xaionaro-go/iterate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fiterate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"online","status_checked_at":"2026-01-15T02:00:08.019Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["2d","iter","iterator"],"created_at":"2026-01-12T00:30:18.849Z","updated_at":"2026-01-15T02:33:18.260Z","avatar_url":"https://github.com/xaionaro-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `iterate`\n\nThis package is focused on providing generic iterators. Currently, we have only one iterator:\n* `TwoD` for iterating efficiently over every point on a big 2D plane.\n\nFor example let's say you want to draw two overlapping rectangles, but you need to do it in a performance-optimal way. A naive solution would be to just draw then as a normal human being:\n```go\ndraw.Draw(canvas, image.Rect(100, 100, 300, 300), \u0026image.Uniform{colorFG}, image.Point{}, draw.Src)\ndraw.Draw(canvas, image.Rect(200, 200, 400, 400), \u0026image.Uniform{colorFG}, image.Point{}, draw.Src)\n```\nBut here some computation power is lost due to walking twice in area (20,20)-(30,30) and other stuff may be done suboptimal. To avoid these issues you may use a \"smart\" 2D iterator from this package:\n```go\nfor i := 0; i \u003c b.N; i++ {\n\tfor p, _ := range TwoD(\n\t\tnil,\n\t\tRect[struct{}](100, 100, 300, 300),\n\t\tRect[struct{}](200, 200, 400, 400),\n\t) {\n\t\tcanvasB.SetGray(p.X, p.Y, colorFG)\n\t}\n}\n```\nIn result, you'll get a performance gain:\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/xaionaro-go/iterate\ncpu: AMD Ryzen 9 5900X 12-Core Processor\n                        │    sec/op     │    sec/op      vs base                │\nTwoD/sizeFactor1/-24       161.0n ± ∞ ¹    808.8n ± ∞ ¹  +402.36% (p=0.008 n=5)\nTwoD/sizeFactor2/-24       330.5n ± ∞ ¹   1022.0n ± ∞ ¹  +209.23% (p=0.008 n=5)\nTwoD/sizeFactor4/-24       939.4n ± ∞ ¹   1617.0n ± ∞ ¹   +72.13% (p=0.008 n=5)\nTwoD/sizeFactor8/-24       3.401µ ± ∞ ¹    3.148µ ± ∞ ¹    -7.44% (p=0.008 n=5)\nTwoD/sizeFactor16/-24     13.167µ ± ∞ ¹    7.590µ ± ∞ ¹   -42.36% (p=0.008 n=5)\nTwoD/sizeFactor32/-24      54.62µ ± ∞ ¹    21.87µ ± ∞ ¹   -59.96% (p=0.008 n=5)\nTwoD/sizeFactor64/-24     215.02µ ± ∞ ¹    76.75µ ± ∞ ¹   -64.31% (p=0.008 n=5)\nTwoD/sizeFactor128/-24     842.1µ ± ∞ ¹    280.3µ ± ∞ ¹   -66.71% (p=0.008 n=5)\nTwoD/sizeFactor256/-24     3.340m ± ∞ ¹    1.069m ± ∞ ¹   -68.00% (p=0.008 n=5)\nTwoD/sizeFactor512/-24    13.462m ± ∞ ¹    4.214m ± ∞ ¹   -68.69% (p=0.008 n=5)\nTwoD/sizeFactor1024/-24    54.25m ± ∞ ¹    16.72m ± ∞ ¹   -69.17% (p=0.008 n=5)\n```\n\nThe implementation of the iteration also could be improved, but yet it is already significantly better than the original variant: 3 times faster if the picture is big enough.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Fiterate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaionaro-go%2Fiterate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Fiterate/lists"}