hash.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package css
  2. // generated by hasher -type=Hash -file=hash.go; DO NOT EDIT, except for adding more constants to the list and rerun go generate
  3. // uses github.com/tdewolff/hasher
  4. //go:generate hasher -type=Hash -file=hash.go
  5. // Hash defines perfect hashes for a predefined list of strings
  6. type Hash uint32
  7. // Unique hash definitions to be used instead of strings
  8. const (
  9. Document Hash = 0x8 // document
  10. Font_Face Hash = 0x809 // font-face
  11. Keyframes Hash = 0x1109 // keyframes
  12. Media Hash = 0x2105 // media
  13. Page Hash = 0x2604 // page
  14. Supports Hash = 0x1908 // supports
  15. )
  16. // String returns the hash' name.
  17. func (i Hash) String() string {
  18. start := uint32(i >> 8)
  19. n := uint32(i & 0xff)
  20. if start+n > uint32(len(_Hash_text)) {
  21. return ""
  22. }
  23. return _Hash_text[start : start+n]
  24. }
  25. // ToHash returns the hash whose name is s. It returns zero if there is no
  26. // such hash. It is case sensitive.
  27. func ToHash(s []byte) Hash {
  28. if len(s) == 0 || len(s) > _Hash_maxLen {
  29. return 0
  30. }
  31. h := uint32(_Hash_hash0)
  32. for i := 0; i < len(s); i++ {
  33. h ^= uint32(s[i])
  34. h *= 16777619
  35. }
  36. if i := _Hash_table[h&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  37. t := _Hash_text[i>>8 : i>>8+i&0xff]
  38. for i := 0; i < len(s); i++ {
  39. if t[i] != s[i] {
  40. goto NEXT
  41. }
  42. }
  43. return i
  44. }
  45. NEXT:
  46. if i := _Hash_table[(h>>16)&uint32(len(_Hash_table)-1)]; int(i&0xff) == len(s) {
  47. t := _Hash_text[i>>8 : i>>8+i&0xff]
  48. for i := 0; i < len(s); i++ {
  49. if t[i] != s[i] {
  50. return 0
  51. }
  52. }
  53. return i
  54. }
  55. return 0
  56. }
  57. const _Hash_hash0 = 0x9acb0442
  58. const _Hash_maxLen = 9
  59. const _Hash_text = "documentfont-facekeyframesupportsmediapage"
  60. var _Hash_table = [1 << 3]Hash{
  61. 0x1: 0x2604, // page
  62. 0x2: 0x2105, // media
  63. 0x3: 0x809, // font-face
  64. 0x5: 0x1109, // keyframes
  65. 0x6: 0x1908, // supports
  66. 0x7: 0x8, // document
  67. }