Class: FastCache::CRC32
- Inherits:
-
Object
- Object
- FastCache::CRC32
- Defined in:
- lib/fastcache/hash/crc32.rb
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #digest ⇒ Object
- #hexdigest ⇒ Object
-
#initialize(string = nil) ⇒ CRC32
constructor
A new instance of CRC32.
Constructor Details
#initialize(string = nil) ⇒ CRC32
Returns a new instance of CRC32.
3 4 5 6 |
# File 'lib/fastcache/hash/crc32.rb', line 3 def initialize(string = nil) @crc = 0xFFFFFFFF self << string if string end |
Instance Method Details
#<<(string) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fastcache/hash/crc32.rb', line 8 def <<(string) string.size.times do |i| @crc ^= string[i] 8.times do if (@crc & 1).zero? @crc >>= 1 else @crc = (@crc >> 1) ^ 0xEDB88320 end end end self end |
#digest ⇒ Object
22 23 24 |
# File 'lib/fastcache/hash/crc32.rb', line 22 def digest [@crc ^ 0xFFFFFFFF].pack('N') end |
#hexdigest ⇒ Object
26 27 28 |
# File 'lib/fastcache/hash/crc32.rb', line 26 def hexdigest (@crc ^ 0xFFFFFFFF).to_s(16) end |