Sha256: 5220af400123f4c64c15aa9fd25897cb34e2b76e4fc1c4c1a1ffb88b82d05129

Contents?: true

Size: 700 Bytes

Versions: 1

Compression:

Stored size: 700 Bytes

Contents

module BitsCount
  module File

    class << self

      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

      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
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bits_count-0.0.1 lib/bits_count/file.rb