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)
| 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. |
| 562 | func 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 | } |
| 583 | NEXT: |
| 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 | |
| 596 | const _Hash_hash0 = 0x87d8a7d9 |
| 597 | const _Hash_maxLen = 24 |