bitary 0.1.7 → 0.1.8

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: 537a58c702f90bfeade22439d4134d921df709d4d474279f29adae869ff08b0d
4
- data.tar.gz: 90910632d7a7f40f89774a8d0ba2b1a6bbf04f5b281454ab18313359151f58b0
3
+ metadata.gz: 293fa51d8a5a4b4cda3a7a283737d0695b84cfcb55414afde3b9c5bb6f9688aa
4
+ data.tar.gz: 6d6541faa0fed549f62a3a1b99a293ca4422511c34527a7278ea7459683f506a
5
5
  SHA512:
6
- metadata.gz: 3c65d9bcd2b757bf0a3e2d8b25b51b6a50b239e589efba142eb3c1c7539d42ac88c311361aa934f6ecf5be06c18da53c4e3c138dda801f0c89330da7c030a745
7
- data.tar.gz: 10169aa8520c4d2dc4ddc92e419b77b745688c14bc08214770f9da25ed35b66d66655db37ef32daa7967119514ad3cacb618d06be5bd3c69df45e2ed435e9fb1
6
+ metadata.gz: 0a81bd80568d6b5fcb20d951f0b193f98941adafd448a896f0a68ae8c97eabecca07a34a2db1d48f4e630a64d1be165ed4efe5f370bc1aabd36f78de4a5b0e7d
7
+ data.tar.gz: 94f16667978d9d9be2ccf141c6539834d7f3502397db12feee83424eb0586ace151be1ca7bee960b5bc40ba0ec6e9e12c0879c74f700d1cd86c35e21f85337bb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.1.7] - 2024-04-01
2
+
3
+ - loads of refactoring and perf improvements
4
+ - Bitary now acts as the logical layer, whereas Bitwarr acts as the business layer
5
+
1
6
  ## [0.1.6] - 2024-03-31
2
7
 
3
8
  - enhance global perf by remove useless and heavy error handling
@@ -13,15 +13,20 @@ class Bitary
13
13
  end
14
14
 
15
15
  def [](bit_index) = @array[item_index(bit_index)]
16
- def bit_at(index) = operate_bit_at(:get, index)
17
- def bit_at!(index) = operate_bit_at!(:set, index)
18
- def unbit_at!(index) = operate_bit_at!(:unset, index)
19
- def to_s = @array.map { |item| to_binstr(item) }.join(' ')
20
16
 
21
17
  def []=(bit_index, value)
22
18
  @array[item_index(bit_index)] = value
23
19
  end
24
20
 
21
+ def bit_at(index) = (self[index] >> (@bpi - (index % @bpi) - 1)) & 0x1
22
+ def bit_at!(index) = self[index] |= 2**(@bpi - (index % @bpi) - 1)
23
+
24
+ def unbit_at!(index)
25
+ self[index] &= ((2**@bpi) - 1 - (2**(@bpi - (index % @bpi) - 1)))
26
+ end
27
+
28
+ def to_s = @array.map { |item| to_binstr(item) }.join(' ')
29
+
25
30
  def each_byte(&proc)
26
31
  @array.each do |item|
27
32
  explode_item(item, Bitary::BYTE, @bpi, &proc)
@@ -87,10 +92,7 @@ class Bitary
87
92
  end
88
93
 
89
94
  def append_bits(item, bpi, addend)
90
- Factory.make('Handler::Append', item).execute(
91
- offset: bpi,
92
- value: addend
93
- )
95
+ (item << bpi) | addend
94
96
  end
95
97
 
96
98
  def increase_items_size(array, new_size, bpi)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bitary
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
data/lib/bitary.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative 'bitary/size'
4
4
  require_relative 'bitary/version'
5
- require_relative 'bitary/handler'
6
5
  require_relative 'bitary/factory'
7
6
  require_relative 'bitary/bitwarr'
8
7
  require_relative 'bitary/decorator'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximilien Ballesteros
@@ -29,11 +29,6 @@ files:
29
29
  - lib/bitary/decorator/single_method.rb
30
30
  - lib/bitary/decorator/single_method/non_nil_enforcer.rb
31
31
  - lib/bitary/factory.rb
32
- - lib/bitary/handler.rb
33
- - lib/bitary/handler/append.rb
34
- - lib/bitary/handler/get.rb
35
- - lib/bitary/handler/set.rb
36
- - lib/bitary/handler/unset.rb
37
32
  - lib/bitary/mapper.rb
38
33
  - lib/bitary/mapper/int_to_bit.rb
39
34
  - lib/bitary/mapper/obj_to_bit.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Bitary
4
- class Handler
5
- class Append < Bitary::Handler
6
- def execute(**kwargs)
7
- (@value << kwargs[:offset]) | kwargs[:value]
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Bitary
4
- class Handler
5
- class Get < Bitary::Handler
6
- def execute(**kwargs)
7
- (@value >> (kwargs[:size] - kwargs[:index] - 1)) & 0x1
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Bitary
4
- class Handler
5
- class Set < Bitary::Handler
6
- def execute(**kwargs)
7
- @value | (2**(kwargs[:size] - kwargs[:index] - 1))
8
- end
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Bitary
4
- class Handler
5
- class Unset < Bitary::Handler
6
- def execute(**kwargs)
7
- size = kwargs[:size]
8
- index = kwargs[:index]
9
- @value & ((2**size) - 1 - (2**(size - index - 1)))
10
- end
11
- end
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'handler/set'
4
- require_relative 'handler/unset'
5
- require_relative 'handler/get'
6
- require_relative 'handler/append'
7
-
8
- class Bitary
9
- class Handler
10
- attr_reader :value
11
-
12
- def initialize(value)
13
- @value = value
14
- end
15
-
16
- def execute(**kwargs)
17
- raise NotImplementedError
18
- end
19
- end
20
- end