github.com/quay/claircore@v1.5.28/rpm/ndb/murmur.go (about)

     1  package ndb
     2  
     3  // This is a port of the rpm murmur hash, which uses a single constant rather than a few of them.
     4  func murmur(s string) (h uint32) {
     5  	const m = 0x5bd1e995
     6  	h = uint32(len(s) * m)
     7  	for ; len(s) >= 4; s = s[4:] {
     8  		h += uint32(s[0]) | uint32(s[1])<<8 | uint32(s[2])<<16 | uint32(s[3])<<24
     9  		h *= m
    10  		h ^= h >> 16
    11  	}
    12  	switch len(s) {
    13  	case 3:
    14  		h += uint32(s[2]) << 16
    15  		fallthrough
    16  	case 2:
    17  		h += uint32(s[1]) << 8
    18  		fallthrough
    19  	case 1:
    20  		h += uint32(s[0])
    21  		h *= m
    22  		h ^= h >> 16
    23  	}
    24  	h *= m
    25  	h ^= h >> 10
    26  	h *= m
    27  	h ^= h >> 17
    28  	return h
    29  }