MCPcopy
hub / github.com/tdewolff/minify / ToHash

Function ToHash

html/hash.go:562–594  ·  view source on GitHub ↗

ToHash returns a hash Hash for a given []byte. Hash is a uint32 that is associated with the text in []byte. It returns zero if no match found.

(s []byte)

Source from the content-addressed store, hash-verified

560
561// ToHash returns a hash Hash for a given []byte. Hash is a uint32 that is associated with the text in []byte. It returns zero if no match found.
562func ToHash(s []byte) Hash {
563 if len(s) == 0 || len(s) > _Hash_maxLen {
564 return 0
565 }
566 //if 3 < len(s) {
567 // return HashMap[string(s)]
568 //}
569 h := uint32(_Hash_hash0)
570 for i := 0; i < len(s); i++ {
571 h ^= uint32(s[i])
572 h *= 16777619
573 }
574 if i := _Hash_table[h&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
575 t := _Hash_text[i>>8 : i>>8+i&0xff]
576 for i := 0; i < len(s); i++ {
577 if t[i] != s[i] {
578 goto NEXT
579 }
580 }
581 return i
582 }
583NEXT:
584 if i := _Hash_table[(h>>16)&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
585 t := _Hash_text[i>>8 : i>>8+i&0xff]
586 for i := 0; i < len(s); i++ {
587 if t[i] != s[i] {
588 return 0
589 }
590 }
591 return i
592 }
593 return 0
594}
595
596const _Hash_hash0 = 0x87d8a7d9
597const _Hash_maxLen = 24

Callers 1

readMethod · 0.70

Calls 1

lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…