string_bits 0.3.0 → 0.4.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 +4 -4
- data/README.md +2 -2
- data/ext/string_bits/string_bits.c +8 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94ef1efad2a1a13cfe6e2ece151103c4140e92fb1e320e21f5e174c2e1a2aabf
|
|
4
|
+
data.tar.gz: d787e35927e1a5dd4b1c056cfaf59f8cb4cb2df0e7d0f3018fe19f9a56d9a218
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0d3bc9a11235cdc5b2c01bec186d265fc90c3f3c56eb0a0a97a56e72caf6fd2732be049bbd5bb834b8984c1e257e355c2f16edee046c7962f9a24bad0957013
|
|
7
|
+
data.tar.gz: 7fbb721347b9a32365de4b280e9ff6776a94314d64738694a470b818c8c327a22ee48d111db7b25c39ab720d32f50276f31afac5788122133b27498f34f6da14
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The methods are designed for real workloads: Apache Arrow validity bitmaps, bitm
|
|
|
6
6
|
|
|
7
7
|
Every method reads the receiver as a raw byte sequence, so the `String`s that `bit_slice` and the non-destructive `bitwise_*` methods return are always `Encoding::BINARY`. The destructive methods leave the receiver's encoding untouched, as `String#setbyte` does.
|
|
8
8
|
|
|
9
|
-
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_bit_offset(
|
|
9
|
+
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_bit_offset(1, lsb_first: false).all? { |n| data.bit_set?(n, lsb_first: false) }` stays true.
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
@@ -22,5 +22,5 @@ puts "\xAA\xAA\xAA\xAA".bit_set?(10)
|
|
|
22
22
|
#=> false
|
|
23
23
|
|
|
24
24
|
puts "\xAA".each_bit(lsb_first: false).to_a.inspect
|
|
25
|
-
#=> [
|
|
25
|
+
#=> [1, 0, 1, 0, 1, 0, 1, 0]
|
|
26
26
|
```
|
|
@@ -762,7 +762,7 @@ emit_bits(const unsigned char *str, ssize_t len, int lsb_first, ssize_t start_of
|
|
|
762
762
|
unsigned char b = str[i];
|
|
763
763
|
int j_start = (i == byte_start) ? bit_start : 0;
|
|
764
764
|
for (int j = j_start; j < 8; j++) {
|
|
765
|
-
SB_EMIT((b >> j) & 1
|
|
765
|
+
SB_EMIT(INT2FIX((b >> j) & 1));
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
} else {
|
|
@@ -770,7 +770,7 @@ emit_bits(const unsigned char *str, ssize_t len, int lsb_first, ssize_t start_of
|
|
|
770
770
|
unsigned char b = str[i];
|
|
771
771
|
int j_end = (i == byte_start) ? (7 - bit_start) : 7;
|
|
772
772
|
for (int j = j_end; j >= 0; j--) {
|
|
773
|
-
SB_EMIT((b >> j) & 1
|
|
773
|
+
SB_EMIT(INT2FIX((b >> j) & 1));
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
776
|
}
|
|
@@ -819,7 +819,7 @@ rb_str_bits(int argc, VALUE *argv, VALUE self)
|
|
|
819
819
|
|
|
820
820
|
/* iterate bit positions matching `bit` ------------------------------------ */
|
|
821
821
|
|
|
822
|
-
/* parse the required `bit` argument (true/false
|
|
822
|
+
/* parse the required `bit` argument (0/1/true/false) to 0 or 1 */
|
|
823
823
|
static int
|
|
824
824
|
parse_bit_target(VALUE bit_val)
|
|
825
825
|
{
|
|
@@ -1409,8 +1409,9 @@ SB_DEFINE_BINARY_METHODS(xor, kern_xor)
|
|
|
1409
1409
|
/*
|
|
1410
1410
|
* NOTE: each_bit_field and bit_fields are implemented here and fully tested,
|
|
1411
1411
|
* but are NOT part of the current core proposal (see FUTURE_PROPOSAL_PLAN.md).
|
|
1412
|
-
* They are deferred because yielding
|
|
1413
|
-
*
|
|
1412
|
+
* They are deferred because yielding multi-bit field values decoded from a
|
|
1413
|
+
* packed layout is a qualitatively different contract from the single-bit
|
|
1414
|
+
* 1/0 values the rest of the API exchanges, and that difference is expected
|
|
1414
1415
|
* to extend core-ruby-dev discussion. The code is kept so the proposal can be
|
|
1415
1416
|
* extended later without re-implementation.
|
|
1416
1417
|
*/
|
|
@@ -1713,7 +1714,7 @@ emit_bit_runs(VALUE self, int lsb_first, ssize_t start_offset, VALUE ary)
|
|
|
1713
1714
|
const unsigned char *src = (const unsigned char *)RSTRING_PTR(self);
|
|
1714
1715
|
int bit = (src[offset >> 3] >> (offset & 7)) & 1;
|
|
1715
1716
|
ssize_t run = count_run_lsb(src, src_len, offset, bit);
|
|
1716
|
-
SB_EMIT_TRIPLE(bit
|
|
1717
|
+
SB_EMIT_TRIPLE(INT2FIX(bit), SSIZET2NUM(offset), SSIZET2NUM(run));
|
|
1717
1718
|
offset += run;
|
|
1718
1719
|
}
|
|
1719
1720
|
}
|
|
@@ -1725,7 +1726,7 @@ emit_bit_runs(VALUE self, int lsb_first, ssize_t start_offset, VALUE ary)
|
|
|
1725
1726
|
while (offset + run < total_bits && logical_get_bit(src, offset + run, 0) == bit) {
|
|
1726
1727
|
run++;
|
|
1727
1728
|
}
|
|
1728
|
-
SB_EMIT_TRIPLE(bit
|
|
1729
|
+
SB_EMIT_TRIPLE(INT2FIX(bit), SSIZET2NUM(offset), SSIZET2NUM(run));
|
|
1729
1730
|
offset += run;
|
|
1730
1731
|
}
|
|
1731
1732
|
}
|