github.com/blend/go-sdk@v1.20220411.3/consistenthash/stable_hash.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package consistenthash
     9  
    10  import (
    11  	"hash/crc64"
    12  )
    13  
    14  var (
    15  	// stableCRC implements a stable crc64 hash table.
    16  	// this allows us to have a consistent hash assignment
    17  	// between process restarts.
    18  	stableCRC = crc64.MakeTable(0xC96C5795D7870F42)
    19  )
    20  
    21  // HashFunction is a function that can be used to hash items.
    22  type HashFunction func([]byte) uint64
    23  
    24  // StableHash implements the default hash function with
    25  // a stable crc64 table checksum.
    26  func StableHash(data []byte) uint64 {
    27  	return crc64.Checksum(data, stableCRC)
    28  }