class Crc32
Crc32
is a pure ruby implementation of CRC32. Copied from:
Constants
- CRC_TABLE
- INIT_CRC
- XOR_MASK
Public Class Methods
checksum(string, crc = INIT_CRC)
click to toggle source
# File lib/geoengineer/utils/crc32.rb, line 46 def self.checksum(string, crc = INIT_CRC) string.each_byte do |byte| crc = (((crc >> 8) & 0x00ffffff) ^ CRC_TABLE[(crc ^ byte) & 0xff]) end crc ^ XOR_MASK end
hashcode(string)
click to toggle source
# File lib/geoengineer/utils/crc32.rb, line 53 def self.hashcode(string) return 0 unless string value = checksum(string).to_i return value if value >= 0 return -value if value <= 0 0 end