{"id":47496776,"url":"https://github.com/kawasin73/bitset","last_synced_at":"2026-03-27T02:35:40.803Z","repository":{"id":88478357,"uuid":"156555117","full_name":"kawasin73/bitset","owner":"kawasin73","description":"Bi-Endian Bit Vector (Array) in Golang","archived":false,"fork":false,"pushed_at":"2019-01-22T12:14:22.000Z","size":51,"stargazers_count":8,"open_issues_count":5,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-15T01:18:57.227Z","etag":null,"topics":["bitarray","bitvector","go","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/kawasin73.png","metadata":{"files":{"readme":"README.ja.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}},"created_at":"2018-11-07T14:03:02.000Z","updated_at":"2023-11-08T15:00:00.000Z","dependencies_parsed_at":"2023-03-03T02:15:42.079Z","dependency_job_id":null,"html_url":"https://github.com/kawasin73/bitset","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kawasin73/bitset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasin73%2Fbitset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasin73%2Fbitset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasin73%2Fbitset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasin73%2Fbitset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kawasin73","download_url":"https://codeload.github.com/kawasin73/bitset/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasin73%2Fbitset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31010632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T02:33:22.146Z","status":"ssl_error","status_checked_at":"2026-03-27T02:33:21.763Z","response_time":164,"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":["bitarray","bitvector","go","golang"],"created_at":"2026-03-27T02:35:40.242Z","updated_at":"2026-03-27T02:35:40.795Z","avatar_url":"https://github.com/kawasin73.png","language":"Go","readme":"# Bi-endianess Bit Vector\n\n[![Build Status](https://travis-ci.com/kawasin73/bitset.svg?branch=master)](https://travis-ci.com/kawasin73/bitset)\n[![GoDoc](https://godoc.org/github.com/kawasin73/bitset?status.svg)](https://godoc.org/github.com/kawasin73/bitset)\n\nbitset は、ビッグエンディアン、リトルエンディアンの両方に対応したビットベクトルのGo言語で実装されたライブラリです。\n\nマシンのエンディアンに関わらず初期化時に指定されたエンディアンでビットベクトルを構築することで、ファイルに保存したバイト列を異なるエンディアンのマシン上で利用することができます。\n\n内部では uint64 で操作を行い、同じ振る舞いをするようにマシンのエンディアンを検出して最適化された処理に切り替えます。\n\nこのパッケージの個々の操作は、[github.com/willf/bitset](https://github.com/willf/bitset) を参考にして作られています。\n\n## 特徴\n\n- Zero Copy : `unsafe` パッケージを利用して渡された `[]byte` を `[]uint64` に型変換するためメモリコピーが発生しない。\n- Bie-Endian : バイト列を指定されたエンディアンで操作するために、マシンのエンディアンを検出してそれぞれに最適化された処理に切り替える。\n- Compatibility : 異なるエンディアンのマシンにファイルを転送して利用する時に変換をする必要がない。\n\n## 使用例\n\n```go\nfunc main() {\n\t// in memory usage\n\tbuf := make([]byte, 2*8)\n\tb, _ := bitset.New(buf, binary.LittleEndian, true)\n\tfor _, v := range []uint{0, 1, 3, 6, 10, 64, 127, 128} {\n\t\tb.Set(v) // when v == 128 auto extend vector and it returns true\n\t}\n\tfmt.Println(buf) // [75 4 0 0 0 0 0 0 1 0 0 0 0 0 0 128]\n\n\tb.Unset(127)\n\tfmt.Println(b.Get(127)) // false\n\n\tfor v, ok := b.FindFirstOne(0); ok; v, ok = b.FindFirstOne(v + 1) {\n\t\tfmt.Println(v) // 0 1 3 6 10 64\n\t}\n\n\t// File + mmap usage\n\tconst pageSize = 4 * 1024\n\tf, _ := os.OpenFile(\"example.bit\", os.O_RDWR|os.O_CREATE, 0666)\n\tf.Truncate(pageSize)\n\tbuf, _ = syscall.Mmap(int(f.Fd()), 0, pageSize,\n\t\tsyscall.PROT_READ|syscall.PROT_WRITE,\n\t\tsyscall.MAP_SHARED)\n\tdefer func() {\n\t\tf.Sync()\n\t\tsyscall.Munmap(buf)\n\t\tf.Close()\n\t}()\n\n\tb, _ = bitset.New(buf, binary.BigEndian, false)\n\tfor v, ok := b.FindFirstOne(0); ok; v, ok = b.FindFirstOne(v + 1) {\n\t\tfmt.Println(v) // 0 1 3 6 10 64  if executed twice\n\t}\n\tfor _, v := range []uint{0, 1, 3, 6, 10, 64, 127, 128} {\n\t\tb.Set(v) // when v == 128 returns false because overflow. not extend vector\n\t}\n\tfmt.Println(buf) // [0 0 0 0 0 0 4 75 128 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 ....\n}\n```\n\n## インストール方法\n\n```bash\ngo get github.com/kawasin73/bitset\n```\n\n## 制限\n\n- 初期化時に渡すバイト列の長さは、8 の倍数であることが要求されます。8 で割り切れない長さのバイト列で初期化された場合は `bitset.ErrInvalidLength` エラーを発生させます。\n- マシンのエンディアン・バイト列を操作するエンディアンは、それぞれビッグエンディアンとリトルエンディアンのみに対応しています。ミドルエンディアンなど他のエンディアンには対応していません。\n- `New()` の引数 `extend` に `false` を設定した時、サイズの自動拡張を行いません。バイト列に保存できるサイズを超えた場合は、新しいバイト列を確保して `bitset.BitVec` を作成しなおしてください。\n- Go 1.9 以上をサポートしています。内部で、`math/bits` パッケージを利用しているためです。\n\n## ライセンス\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawasin73%2Fbitset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkawasin73%2Fbitset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawasin73%2Fbitset/lists"}