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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c21407d901f599aa0d33fe0bad85d39f4729da08c656cab3556fc087198394f2
4
- data.tar.gz: e4c8912125bfd9f4a6fcfce0be0d78f528f0bb87369064cfc1c96b4d3f5b7ac9
3
+ metadata.gz: 94ef1efad2a1a13cfe6e2ece151103c4140e92fb1e320e21f5e174c2e1a2aabf
4
+ data.tar.gz: d787e35927e1a5dd4b1c056cfaf59f8cb4cb2df0e7d0f3018fe19f9a56d9a218
5
5
  SHA512:
6
- metadata.gz: 8d73669323a7e9cee148d96775e8d9269b2c3c990906ad62e03d20466f93f3f2b7cafb911778fed607f7bdc561eaae57ac35770910de97f893addceb68e122bb
7
- data.tar.gz: 359fd91c4eb04d4338850de1e38e2162c0d308a2697f86d2ef8ddbf200656384f62e81aa5eabac2c44c5afc79bde0383bc5b672a4a16ad50ab44fa0bcb195323
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(true, lsb_first: false).all? { |n| data.bit_set?(n, lsb_first: false) }` stays true.
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
- #=> [true, false, true, false, true, false, true, false]
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 ? Qtrue : Qfalse);
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 ? Qtrue : Qfalse);
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/1/0) to 0 or 1 */
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 Integer field values is a qualitatively
1413
- * different contract from the rest of the API, and that difference is expected
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 ? Qtrue : Qfalse, SSIZET2NUM(offset), SSIZET2NUM(run));
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 ? Qtrue : Qfalse, SSIZET2NUM(offset), SSIZET2NUM(run));
1729
+ SB_EMIT_TRIPLE(INT2FIX(bit), SSIZET2NUM(offset), SSIZET2NUM(run));
1729
1730
  offset += run;
1730
1731
  }
1731
1732
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_bits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASUMI Hitoshi