go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/consistenthash/stable_hash.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package consistenthash
     9  
    10  import (
    11  	"crypto/md5"
    12  	"encoding/binary"
    13  )
    14  
    15  // HashFunction is a function that can be used to hash items.
    16  type HashFunction func([]byte) uint64
    17  
    18  // StableHash implements the default hash function with
    19  // a stable crc64 table checksum.
    20  func StableHash(data []byte) uint64 {
    21  	hash := md5.Sum(data)
    22  	return binary.BigEndian.Uint64(hash[8:])
    23  }