string_bits 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +22 -0
- data/ext/string_bits/extconf.rb +5 -0
- data/ext/string_bits/string_bits.c +1802 -0
- data/lib/benchmark_driver/output/faster.rb +37 -0
- data/lib/string_bits.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3455701bd07156e53114ca6183b8323d16d56f07d406374585ba9b1d12d54d0b
|
|
4
|
+
data.tar.gz: 73a554f7f5132692757c37b086a743f87ff86f7582882ba5d9820a86bc69feaf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f7ea60d8373ac45b5dddb31fa35ecce329e9a791f245ac781a6ed14c5af343d851a1839c4fc6abacd80d5cd5ef9bae22411b11cf3bc5d475532c07f97e033594
|
|
7
|
+
data.tar.gz: 4572936ba8afbb890df9d790b2f007c6dfbe0246dc2f8a76b77484f1d04f7b511281a4885281bbef62cf4f3743cf56c2ba8ec3a5096e81455ce4c06a38a26222
|
data/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# string_bits gem
|
|
2
|
+
|
|
3
|
+
Ruby's `String` is already a byte sequence. This gem extends it one level lower: **a bit sequence** --- making packed binary buffers first-class values without any new class.
|
|
4
|
+
|
|
5
|
+
The methods are designed for real workloads: Apache Arrow validity bitmaps, bitmap font glyph data, and any protocol buffer where bits carry meaning. Many methods read or modify the existing string bytes directly; methods such as `bit_slice`, `bit_not`, `bit_and`, `bit_or`, `bit_xor`, `bits`, `set_bit_offsets`, `bit_runs`, and `Array#mask` allocate a derived result object. Because the API relies solely on `String`, the same methods would benefit memory-constrained implementations such as mruby and PicoRuby once adopted into CRuby.
|
|
6
|
+
|
|
7
|
+
A single keyword, `lsb_first:`, controls bit ordering across the API: it selects intra-byte numbering wherever positions are exchanged with the caller, and intra-byte scan direction wherever the API walks the sequence. Across-byte order is always `byte[0]` first, and result Strings from `bit_slice` are always packed LSB-first regardless, so `data.each_set_bit_offset(lsb_first: false).all? { |n| data.bit_at(n, lsb_first: false) }` stays true.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
gem install string_bits
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
require "string_bits"
|
|
17
|
+
puts "\xAA\xAA\xAA\xAA".bit_at(10)
|
|
18
|
+
#=> false
|
|
19
|
+
|
|
20
|
+
puts "\xAA".each_bit(lsb_first: false).to_a.inspect
|
|
21
|
+
#=> [true, false, true, false, true, false, true, false]
|
|
22
|
+
```
|