{"id":15998907,"url":"https://github.com/nikolaydubina/go-bitset-example","last_synced_at":"2025-08-09T02:06:15.991Z","repository":{"id":205137927,"uuid":"713491729","full_name":"nikolaydubina/go-bitset-example","owner":"nikolaydubina","description":"Go Bitset: benchmarks, examples, analysis ","archived":false,"fork":false,"pushed_at":"2024-05-09T04:51:44.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T01:14:16.899Z","etag":null,"topics":["benchmarking","bitset","example","go","golang","static-analysis"],"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/nikolaydubina.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-02T16:18:27.000Z","updated_at":"2024-05-09T04:51:48.000Z","dependencies_parsed_at":"2023-12-17T07:30:53.374Z","dependency_job_id":"d368aa3d-7647-4c92-b93a-1ad1ebab05a2","html_url":"https://github.com/nikolaydubina/go-bitset-example","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"2548137a658449310c77dc68fd1f01ee309134c0"},"previous_names":["nikolaydubina/go-bitset-example"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nikolaydubina/go-bitset-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolaydubina%2Fgo-bitset-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolaydubina%2Fgo-bitset-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolaydubina%2Fgo-bitset-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolaydubina%2Fgo-bitset-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikolaydubina","download_url":"https://codeload.github.com/nikolaydubina/go-bitset-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikolaydubina%2Fgo-bitset-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269518731,"owners_count":24430644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"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":["benchmarking","bitset","example","go","golang","static-analysis"],"created_at":"2024-10-08T08:23:03.202Z","updated_at":"2025-08-09T02:06:15.939Z","avatar_url":"https://github.com/nikolaydubina.png","language":"Go","readme":"### How to make bitset in Go?\n\n* *zero overhead*\n* short syntax for creating sets from values\n* set membership, equality, subset\n* compile time\n   * block of accidental arithmetics\n   * block of implicit cast of untyped constants\n   * block of all operators except `==` and `!=`\n   * block of creating new values\n* extending on the idea of [Go Enum](https://github.com/nikolaydubina/go-enum-example)\n\n```go\npackage permission\n\nvar (\n\tRead    = Permission{0x1}\n\tWrite   = Permission{0x2}\n\tExecute = Permission{0x4}\n)\n\n// Permission is a set implemented as a bitset of single byte.\ntype Permission struct{ v uint8 }\n\nvar ss = map[Permission]string{\n\t{}:                           \"---\",\n\tRead:                         \"r--\",\n\tWrite:                        \"-w-\",\n\tExecute:                      \"--e\",\n\tRead.Add(Write):              \"rw-\",\n\tRead.Add(Execute):            \"r-e\",\n\tWrite.Add(Execute):           \"-we\",\n\tRead.Add(Write).Add(Execute): \"rwe\",\n}\n\nfunc (a Permission) String() string { return ss[a] }\n\nfunc (a Permission) Add(b Permission) Permission { return Permission{a.v | b.v} }\n\nfunc (a Permission) Contains(b Permission) bool { return b.v\u0026(a.v\u0026b.v) == b.v }\n```\n\n### Benchmarks\n\n```bash\n$ go test -bench=. -benchmem ./permission\ngoos: darwin\ngoarch: arm64\npkg: github.com/nikolaydubina/go-bitset-example/permission\nBenchmarkPermission_Add-10         \t1000000000\t         0.7463 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkPermission_Contains-10    \t1000000000\t         0.4688 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkPermission_String-10      \t132117963\t         9.080 ns/op\t       0 B/op\t       0 allocs/op\nPASS\nok  \tgithub.com/nikolaydubina/go-bitset-example/permission\t3.552s\n```\n\n### References\n\n* https://en.wikipedia.org/wiki/Bit_array\n* https://en.cppreference.com/w/cpp/utility/bitset\n* https://docs.oracle.com/javase/8/docs/api/java/util/BitSet.html\n* https://godbolt.org\n* https://github.com/nikolaydubina/go-enum-example\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolaydubina%2Fgo-bitset-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikolaydubina%2Fgo-bitset-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikolaydubina%2Fgo-bitset-example/lists"}