test-case-insensitive 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. . $(dirname $(readlink -f $0))/framework.sh
  3. WORDS="Halllo\nH-lllo\nHalll1"
  4. # Case-insensitive test
  5. testsuccessequal "#include \"/dev/null\"
  6. #ifdef __GNUC__
  7. typedef uint16_t __attribute__((aligned (1))) triehash_uu16;
  8. typedef char static_assert16[__alignof__(triehash_uu16) == 1 ? 1 : -1];
  9. typedef uint32_t __attribute__((aligned (1))) triehash_uu32;
  10. typedef char static_assert32[__alignof__(triehash_uu32) == 1 ? 1 : -1];
  11. typedef uint64_t __attribute__((aligned (1))) triehash_uu64;
  12. typedef char static_assert64[__alignof__(triehash_uu64) == 1 ? 1 : -1];
  13. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  14. #define onechar(c, s, l) (((uint64_t)(c)) << (s))
  15. #else
  16. #define onechar(c, s, l) (((uint64_t)(c)) << (l-8-s))
  17. #endif
  18. #if (!defined(__ARM_ARCH) || defined(__ARM_FEATURE_UNALIGNED)) && !defined(TRIE_HASH_NO_MULTI_BYTE)
  19. #define TRIE_HASH_MULTI_BYTE
  20. #endif
  21. #endif /*GNUC */
  22. #ifdef TRIE_HASH_MULTI_BYTE
  23. static enum PerfectKey PerfectHash6(const char *string)
  24. {
  25. switch(string[0] | 0x20) {
  26. case 0| onechar('h', 0, 8):
  27. switch(string[1]) {
  28. case 0| onechar('-', 0, 8):
  29. switch(*((triehash_uu32*) &string[2]) | 0x20202020) {
  30. case 0| onechar('l', 0, 32)| onechar('l', 8, 32)| onechar('l', 16, 32)| onechar('o', 24, 32):
  31. return H_lllo;
  32. }
  33. break;
  34. case 0| onechar('a', 0, 8):
  35. case 0| onechar('A', 0, 8):
  36. switch(*((triehash_uu16*) &string[2]) | 0x2020) {
  37. case 0| onechar('l', 0, 16)| onechar('l', 8, 16):
  38. switch(string[4] | 0x20) {
  39. case 0| onechar('l', 0, 8):
  40. switch(string[5]) {
  41. case 0| onechar('1', 0, 8):
  42. return Halll1;
  43. break;
  44. case 0| onechar('o', 0, 8):
  45. case 0| onechar('O', 0, 8):
  46. return Halllo;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. return Unknown;
  53. }
  54. #else
  55. static enum PerfectKey PerfectHash6(const char *string)
  56. {
  57. switch(string[0] | 0x20) {
  58. case 'h':
  59. switch(string[1]) {
  60. case '-':
  61. switch(string[2] | 0x20) {
  62. case 'l':
  63. switch(string[3] | 0x20) {
  64. case 'l':
  65. switch(string[4] | 0x20) {
  66. case 'l':
  67. switch(string[5] | 0x20) {
  68. case 'o':
  69. return H_lllo;
  70. }
  71. }
  72. }
  73. }
  74. break;
  75. case 'a':
  76. case 'A':
  77. switch(string[2] | 0x20) {
  78. case 'l':
  79. switch(string[3] | 0x20) {
  80. case 'l':
  81. switch(string[4] | 0x20) {
  82. case 'l':
  83. switch(string[5]) {
  84. case '1':
  85. return Halll1;
  86. break;
  87. case 'o':
  88. case 'O':
  89. return Halllo;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. return Unknown;
  97. }
  98. #endif /* TRIE_HASH_MULTI_BYTE */
  99. enum PerfectKey PerfectHash(const char *string, size_t length)
  100. {
  101. switch (length) {
  102. case 6:
  103. return PerfectHash6(string);
  104. default:
  105. return Unknown;
  106. }
  107. }" triehash --multi-byte=3210 --ignore-case -H /dev/null /dev/stdin