Class: ArrowFormat::Bitmap
- Inherits:
-
Object
- Object
- ArrowFormat::Bitmap
- Includes:
- Enumerable
- Defined in:
- lib/arrow-format/bitmap.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #each ⇒ Object
-
#initialize(buffer, offset, n_values) ⇒ Bitmap
constructor
A new instance of Bitmap.
- #popcount ⇒ Object
Constructor Details
#initialize(buffer, offset, n_values) ⇒ Bitmap
Returns a new instance of Bitmap.
21 22 23 24 25 |
# File 'lib/arrow-format/bitmap.rb', line 21 def initialize(buffer, offset, n_values) @buffer = buffer @offset = offset @n_values = n_values end |
Instance Method Details
#[](i) ⇒ Object
27 28 29 30 |
# File 'lib/arrow-format/bitmap.rb', line 27 def [](i) i += @offset (@buffer.get_value(:U8, i / 8) & (1 << (i % 8))) > 0 end |
#each ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/arrow-format/bitmap.rb', line 32 def each return to_enum(__method__) unless block_given? # TODO: Optimize current = -1 n_bytes = (@offset + @n_values) / 8 @buffer.each(:U8, 0, n_bytes) do |offset, value| 8.times do |i| current += 1 next if current < @offset yield((value & (1 << (i % 8))) > 0) end end remained_bits = (@offset + @n_values) % 8 unless remained_bits.zero? value = @buffer.get_value(:U8, n_bytes) remained_bits.times do |i| current += 1 next if current < @offset yield((value & (1 << (i % 8))) > 0) end end end |
#popcount ⇒ Object
56 57 58 59 60 61 |
# File 'lib/arrow-format/bitmap.rb', line 56 def popcount # TODO: Optimize count do |flaged| flaged end end |