module Renoir::CRC16

This is the CRC16 algorithm used by Redis Cluster to hash keys. Implementation according to CCITT standards.

This is actually the XMODEM CRC 16 algorithm, using the following parameters:

Constants

XMODEM_CRC16_LOOKUP

Public Class Methods

crc16(bytes) click to toggle source
# File lib/renoir/crc16.rb, line 17
def self.crc16(bytes)
  crc = 0
  bytes.each_byte do |b|
    crc = ((crc << 8) & 0xffff) ^ XMODEM_CRC16_LOOKUP[((crc >> 8) ^ b) & 0xff]
  end
  crc
end