gitee.com/lh-her-team/common@v1.5.1/wal/crc32.go (about)

     1  package wal
     2  
     3  import (
     4  	"hash/crc32"
     5  )
     6  
     7  var table = crc32.MakeTable(crc32.Castagnoli)
     8  
     9  // CRC is a CRC-32 checksum computed using Castagnoli's polynomial.
    10  type CRC uint32
    11  
    12  // NewCRC creates a new crc based on the given bytes.
    13  func NewCRC(b []byte) CRC {
    14  	return CRC(0).Update(b)
    15  }
    16  
    17  // Update updates the crc with the given bytes.
    18  func (c CRC) Update(b []byte) CRC {
    19  	return CRC(crc32.Update(uint32(c), table, b))
    20  }
    21  
    22  // Value returns a masked crc.
    23  func (c CRC) Value() uint32 {
    24  	return uint32(c>>15|c<<17) + 0xa282ead8
    25  }