Module: BitsCount::File
- Defined in:
- lib/bits_count/file.rb
Class Method Summary collapse
Class Method Details
.bits_count(path) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/bits_count/file.rb', line 21 def bits_count(path) f_size = ::File.size(path) bit1_count = population_count(path) { bit0_count: f_size*8 - bit1_count, bit1_count: bit1_count } end |
.population_count(path, alg = :str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bits_count/file.rb', line 6 def population_count(path, alg = :str) ::File.open(path, "rb") do |f| case alg when :int32 IO.population_count_int32(f) when :str IO.population_count_str(f) when :map IO.population_count_map(f) else raise NotImplementedError, "#{alg} algorithm is not implemented" end end end |