module BitsCount::IO

Constants

BIN_STR_END
BUFFER_SIZE
UNPACK_PATTERN

Public Class Methods

population_count_int32(io) click to toggle source
# File lib/bits_count/io.rb, line 10
def population_count_int32(io)
  count = 0
  each_int32(io) {|int| count += Primitive.population_count_int32(int) }
  count
end
population_count_map(io) click to toggle source
# File lib/bits_count/io.rb, line 16
def population_count_map(io)
  count = 0
  each_int32(io) {|int| count += Primitive.population_count_map(int) }
  count
end
population_count_str(io) click to toggle source
# File lib/bits_count/io.rb, line 22
def population_count_str(io)
  count = 0 
  while binstr = io.read(BUFFER_SIZE)
    count += Primitive.population_count_str(binstr) 
  end
  count
end

Private Class Methods

each_int32(io, &block) click to toggle source
# File lib/bits_count/io.rb, line 31
def each_int32(io, &block)
  while binstr = io.read(BUFFER_SIZE)
    binstr << BIN_STR_END if binstr.bytesize < BUFFER_SIZE
    binstr.unpack(UNPACK_PATTERN).each(&block)
  end
end