OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / github.com / syndtr / goleveldb / leveldb / util / crc32.go
1 // Copyright 2011 The LevelDB-Go Authors. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 package util
7
8 import (
9         "hash/crc32"
10 )
11
12 var table = crc32.MakeTable(crc32.Castagnoli)
13
14 // CRC is a CRC-32 checksum computed using Castagnoli's polynomial.
15 type CRC uint32
16
17 // NewCRC creates a new crc based on the given bytes.
18 func NewCRC(b []byte) CRC {
19         return CRC(0).Update(b)
20 }
21
22 // Update updates the crc with the given bytes.
23 func (c CRC) Update(b []byte) CRC {
24         return CRC(crc32.Update(uint32(c), table, b))
25 }
26
27 // Value returns a masked crc.
28 func (c CRC) Value() uint32 {
29         return uint32(c>>15|c<<17) + 0xa282ead8
30 }