{"id":37175903,"url":"https://github.com/neox5/btmp","last_synced_at":"2026-01-14T20:31:55.632Z","repository":{"id":316407334,"uuid":"1063206068","full_name":"neox5/btmp","owner":"neox5","description":"Pure Go bitmap library designed as a building block for data structures. 64-bit words, efficient range operations, validated API with overlap-safe copies.","archived":false,"fork":false,"pushed_at":"2025-10-27T14:54:22.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-27T16:25:11.056Z","etag":null,"topics":["bitmap","bitset","data-structures","golang","pure-go","range"],"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/neox5.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-09-24T10:03:35.000Z","updated_at":"2025-10-27T14:57:14.000Z","dependencies_parsed_at":"2025-09-24T13:05:27.969Z","dependency_job_id":"b3461fbb-52bd-41b1-a8db-9979aed9b5b5","html_url":"https://github.com/neox5/btmp","commit_stats":null,"previous_names":["neox5/btmp"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/neox5/btmp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neox5%2Fbtmp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neox5%2Fbtmp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neox5%2Fbtmp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neox5%2Fbtmp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neox5","download_url":"https://codeload.github.com/neox5/btmp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neox5%2Fbtmp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["bitmap","bitset","data-structures","golang","pure-go","range"],"created_at":"2026-01-14T20:31:55.012Z","updated_at":"2026-01-14T20:31:55.619Z","avatar_url":"https://github.com/neox5.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbr/\u003e\n\u003cbr/\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"logo.png\" alt=\"btmp\" width=\"500\"/\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n# btmp\n\nbtmp (\"bitmap\") is a pure Go bitmap library designed as a building block for your data structures. It provides tested, validated operations for manipulating dense boolean data without implementing bit math yourself.\n\nGrid serves as a full-featured reference implementation, demonstrating how to build zero-copy 2D data structures on the bitmap foundation.\n\n### When NOT to use\n\n- **Sparse data** (\u003c 1% density) → use `map[int]struct{}` or RoaringBitmap\n- **Unknown/unpredictable growth** → use bits-and-blooms/bitset with auto-grow\n- **Need compression** → use RoaringBitmap\n\n### When to use\n\n- **Building data structures** on top of bitmap operations\n- **Size is known** or grows predictably\n- **Explicit control** over bounds and validation\n- **Range operations** - bulk sets, clears, copies\n\n### Implementation\n\nbtmp abstracts away 64-bit word boundaries so you can work with bit positions directly. The library uses panics for validation failures - incorrect usage fails immediately at the source rather than propagating errors through your code.\n\n## Install\n\n```bash\ngo get github.com/neox5/btmp\n```\n\n## Quick start\n\n```go\nimport \"github.com/neox5/btmp\"\n\n// Create and manipulate bitmap\nb := btmp.New(1024)\n\n// Range operations (the key feature)\nb.SetRange(100, 50)              // Set bits [100, 150)\nb.ClearRange(110, 10)            // Clear bits [110, 120)\nb.CopyRange(b, 0, 500, 100)      // Copy bits [0, 100) to [500, 600)\n\n// Single-bit operations\nb.SetBit(42).ClearBit(43).FlipBit(44)\n\n// Multi-bit operations\nb.SetBits(200, 8, 0xFF)          // Insert 8 bits at position 200\n\n// Boolean operations\nb2 := btmp.New(1024).SetRange(50, 100)\nb.And(b2).Or(b2).Xor(b2).Not()\n\n// Query operations\nif b.Test(42) { /* bit is set */ }\nif b.Any() { /* has any set bits */ }\nif b.All() { /* all bits set */ }\ncount := b.Count()                    // Number of set bits\ncount = b.CountRange(100, 50)         // Count in range [100, 150)\nif b.AnyRange(200, 10) { /* ... */ }  // Any bits set in range\n\n// Grid - zero-copy 2D view (row-major)\ng := btmp.NewGridWithSize(10, 16) // 10 rows, 16 columns\ng.SetRect(2, 3, 4, 5)             // Set 4×5 rectangle at row 2, col 3\nif g.IsFree(5, 8, 3, 3) {         // Check if 3×3 region is available at row 5, col 8\n    g.SetRect(5, 8, 3, 3)\n}\n```\n\n## Examples\n\nThe `examples/` directory contains complete working examples:\n\n- **[bitmap_print](examples/bitmap_print/)** - Bitmap formatting and visualization (binary, hexadecimal, grouped output)\n- **[grid_print](examples/grid_print/)** - Grid visualization and pattern creation\n\nTo run an example:\n\n```bash\ngo run examples/bitmap_print/main.go\n```\n\n## API\n\n### Bitmap (40 methods)\n\n| Category             | Method                                                                                         |\n| -------------------- | ---------------------------------------------------------------------------------------------- |\n| **Construction** (1) | `New(n uint) *Bitmap`                                                                          |\n| **Access** (2)       | `Len() int`                                                                                    |\n|                      | `Words() []uint64`                                                                             |\n| **Growth** (2)       | `EnsureBits(n int) *Bitmap`                                                                    |\n|                      | `AddBits(n int) *Bitmap`                                                                       |\n| **Query** (15)       | `Test(pos int) bool`                                                                           |\n|                      | `Any() bool`                                                                                   |\n|                      | `All() bool`                                                                                   |\n|                      | `Count() int`                                                                                  |\n|                      | `AnyRange(start, count int) bool`                                                              |\n|                      | `AllRange(start, count int) bool`                                                              |\n|                      | `CountRange(start, count int) int`                                                             |\n|                      | `NextZero(pos int) int`                                                                        |\n|                      | `NextOne(pos int) int`                                                                         |\n|                      | `NextZeroInRange(pos, count int) int`                                                          |\n|                      | `NextOneInRange(pos, count int) int`                                                           |\n|                      | `CountZerosFrom(pos int) int`                                                                  |\n|                      | `CountOnesFrom(pos int) int`                                                                   |\n|                      | `CountZerosFromInRange(pos, count int) int`                                                    |\n|                      | `CountOnesFromInRange(pos, count int) int`                                                     |\n| **Validation** (2)   | `ValidateInBounds(pos int) error`                                                              |\n|                      | `ValidateRange(start, count int) error`                                                        |\n| **Single-bit** (3)   | `SetBit(pos int) *Bitmap`                                                                      |\n|                      | `ClearBit(pos int) *Bitmap`                                                                    |\n|                      | `FlipBit(pos int) *Bitmap`                                                                     |\n| **Multi-bit** (1)    | `SetBits(pos, n int, val uint64) *Bitmap`                                                      |\n| **Range** (4)        | `SetRange(start, count int) *Bitmap`                                                           |\n|                      | `ClearRange(start, count int) *Bitmap`                                                         |\n|                      | `CopyRange(src *Bitmap, srcStart, dstStart, count int) *Bitmap`                                |\n|                      | `MoveRange(srcStart, dstStart, count int) *Bitmap`                                             |\n| **Bulk** (2)         | `SetAll() *Bitmap`                                                                             |\n|                      | `ClearAll() *Bitmap`                                                                           |\n| **Logic** (4)        | `And(other *Bitmap) *Bitmap`                                                                   |\n|                      | `Or(other *Bitmap) *Bitmap`                                                                    |\n|                      | `Xor(other *Bitmap) *Bitmap`                                                                   |\n|                      | `Not() *Bitmap`                                                                                |\n| **Print** (4)        | `Print() string`                                                                               |\n|                      | `PrintRange(start, count int) string`                                                          |\n|                      | `PrintFormat(base int, grouped bool, groupSize int, sep string) string`                        |\n|                      | `PrintRangeFormat(start, count int, base int, grouped bool, groupSize int, sep string) string` |\n\n### Grid (29 methods)\n\n| Category                   | Method                                          |\n| -------------------------- | ----------------------------------------------- |\n| **Construction** (2)       | `NewGrid() *Grid`                               |\n|                            | `NewGridWithSize(rows, cols int) *Grid`         |\n| **Access** (3)             | `Rows() int`                                    |\n|                            | `Cols() int`                                    |\n|                            | `Index(r, c int) int`                           |\n| **Growth** (4)             | `EnsureRows(rows int) *Grid`                    |\n|                            | `GrowRows(delta int) *Grid`                     |\n|                            | `EnsureCols(cols int) *Grid`                    |\n|                            | `GrowCols(delta int) *Grid`                     |\n| **Query** (11)             | `RectZero(r, c, h, w int) bool`                 |\n|                            | `RectOne(r, c, h, w int) bool`                  |\n|                            | `NextZeroInRow(r, c int) int`                   |\n|                            | `NextOneInRow(r, c int) int`                    |\n|                            | `NextZeroInRowRange(r, c, count int) int`       |\n|                            | `NextOneInRowRange(r, c, count int) int`        |\n|                            | `CountZerosFromInRow(r, c int) int`             |\n|                            | `CountOnesFromInRow(r, c int) int`              |\n|                            | `CountZerosFromInRowRange(r, c, count int) int` |\n|                            | `CountOnesFromInRowRange(r, c, count int) int`  |\n|                            | `AllRow(r int) bool`                            |\n| **Validation** (2)         | `ValidateCoordinate(r, c int) error`            |\n|                            | `ValidateRect(r, c, h, w int) error`            |\n| **Rectangle Mutators** (6) | `SetRect(r, c, h, w int) *Grid`                 |\n|                            | `ClearRect(r, c, h, w int) *Grid`               |\n|                            | `ShiftRectRight(r, c, h, w int) *Grid`          |\n|                            | `ShiftRectLeft(r, c, h, w int) *Grid`           |\n|                            | `ShiftRectUp(r, c, h, w int) *Grid`             |\n|                            | `ShiftRectDown(r, c, h, w int) *Grid`           |\n| **Print** (1)              | `Print() string`                                |\n\n## License\n\nMIT. See `LICENSE`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneox5%2Fbtmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneox5%2Fbtmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneox5%2Fbtmp/lists"}