https://github.com/dearblue/mruby-bitset
variable length bit-map/bit-array manipulator
https://github.com/dearblue/mruby-bitset
bitarray bitmap bitset mruby
Last synced: about 2 months ago
JSON representation
variable length bit-map/bit-array manipulator
- Host: GitHub
- URL: https://github.com/dearblue/mruby-bitset
- Owner: dearblue
- License: bsd-2-clause
- Created: 2018-10-11T12:44:07.000Z (over 6 years ago)
- Default Branch: wip
- Last Pushed: 2018-10-11T12:44:57.000Z (over 6 years ago)
- Last Synced: 2025-02-12T11:35:08.963Z (4 months ago)
- Topics: bitarray, bitmap, bitset, mruby
- Language: C
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-bitset - variable length bit map manipulator
mruby の配列をビット値に特化したようなナニカです。
ビット長を固定する機能はありません。
## できること
ビット配列は最上位ビットから連続して最下位ビットへと続きます。0 と 1 から構成される mruby の配列と同じように考えて下さい。
- 初期化 (`Bitset.new`)
- ビット単位の追加 (`Bitset#push` / `Bitset#unshift`)
- ビット単位の削除 (`Bitset#pop` / `Bitset#shift`)
- 任意ビットの取得 (`Bitset#[]`)
- 任意ビットの設定 (`Bitset#[]=`)
- 全てのビットが 0 か 1 か、一つでも 1 が立っているかを確認する (`Bitset#all?` / `Bitset#none?` / `Bitset#any?`)
- 全てのビットを列挙してブロックを呼ぶ (`Bitset#each`)
- ビット長の取得 (`Bitset#size` / `Bitset#len`)
- 二つのビットセットのハミング距離 (`Bitset#hamming`)
- MSB から連続する 0 ビットの数え上げ (NLZ; Number of Leading Zero / CLZ; Counting Leading Zero) (`Bitset#clz`)
- LSB から連続する 0 ビットの数え上げ (NTZ; Number of Trailing Zero / CTZ; Counting Trailing Zero) (`Bitset#ctz`)
- 全体に含まれる 1 ビットの数え上げ (Counting 1 bits; Population Count) (`Bitset#popcount`)
- 1ビットパリティの算出 (`Bitset#parity`)
- 全ビットの反転 (`Bitset#flip` / `Bitset#flip!` / `Bitset#~`)
- ニの補数の算出 (`Bitset#minus` / `Bitset#minus!` / `Bitset#twos_complement` / `Bitset#twos_complement!` / `Bitset#-`)
- MSB を合わせての論理演算 (`Bitset#msb_or` / `Bitset#msb_and` / `Bitset#msb_xor` / `Bitset#msb_nor` / `Bitset#msb_nand` / `Bitset#msb_xnor` / `Bitset#|` / `Bitset#&` / `Bitset#^`)
- LSB を合わせての論理演算 (`Bitset#lsb_or` / `Bitset#lsb_and` / `Bitset#lsb_xor` / `Bitset#lsb_nor` / `Bitset#lsb_nand` / `Bitset#lsb_xnor`)## くみこみかた
`build_config.rb` ファイルに `gem github: "dearblue/mruby-bitset"` を任意の場所に追加して下さい。
```ruby
# build_config.rbMRuby::Build.new do |conf|
...
conf.gem github: "dearblue/mruby-bitset"
...
end
```あるいは `mrbgem.rake` ファイルに依存する mrbgem として追加して下さい。
```ruby
# mrbgem.rakeMRuby::Gem::Specification.new("your-mgem") do |spec|
...
spec.add_dependency "mruby-bitset", github: "dearblue/mruby-bitset"
...
```## つかいかた
```ruby
a = Bitset.new
# => #
83.times { a << rand(2) }; a
# => #
b = Bitset.new("111100001111000011110000111100001111")
# => #
a | b
# => #
a & b
# => #
a ^ b
# => #
a
# => #
a.shift 5
# => 17
a
# => #
a.popcount
# => 39
```## Specification
- Package name: mruby-bitset
- Version: 0.0.0.1.CONCEPT.TRYOUT
- Licensing: [2 clause BSD License](LICENSE)
- Product quality: CONCEPT, ***BUGGY***
- Project page:
- Author: [dearblue](https://github.com/dearblue)
- Support mruby version: ?
- Object code size: +25〜35 kb (depending on how optimization) (on FreeBSD 11.2 AMD64 with clang-6.0)
- Used heap size per object: `sizeof(uintptr_t[3]) + sizeof(uintptr_t[4 * N])` bytes (`N` is zero or more)
- Dependency external mrbgems: (NONE)
- Dependency C libraries: (NONE)