github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/hash.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package util
    12  
    13  import (
    14  	"hash/crc32"
    15  
    16  	"github.com/cockroachdb/errors"
    17  )
    18  
    19  // CRC32 computes the Castagnoli CRC32 of the given data.
    20  func CRC32(data []byte) uint32 {
    21  	hash := crc32.New(crc32.MakeTable(crc32.Castagnoli))
    22  	if _, err := hash.Write(data); err != nil {
    23  		panic(errors.Wrap(err, `"It never returns an error." -- https://golang.org/pkg/hash`))
    24  	}
    25  	return hash.Sum32()
    26  }