You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uthash_strcase.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef UTHASH_STRCASE_H_
  17. #define UTHASH_STRCASE_H_
  18. #ifdef UTHASH_H
  19. #error Invalid include order: uthash is already included
  20. #endif
  21. /* Utils for uthash tuning */
  22. #ifndef HASH_CASELESS
  23. #define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
  24. hashv = mum(key, keylen, 0xdeadbabe); \
  25. bkt = (hashv) & (num_bkts-1); \
  26. } while (0)
  27. #define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
  28. #else
  29. #define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
  30. unsigned _len = keylen; \
  31. unsigned _leftover = keylen % 8; \
  32. unsigned _fp, _i; \
  33. const uint8_t* _s = (const uint8_t*)(key); \
  34. union { \
  35. struct { \
  36. unsigned char c1, c2, c3, c4, c5, c6, c7, c8; \
  37. } c; \
  38. uint64_t pp; \
  39. } _u; \
  40. uint64_t _r; \
  41. _fp = _len - _leftover; \
  42. _r = 0xdeadbabe; \
  43. for (_i = 0; _i != _fp; _i += 8) { \
  44. _u.c.c1 = _s[_i], _u.c.c2 = _s[_i + 1], _u.c.c3 = _s[_i + 2], _u.c.c4 = _s[_i + 3]; \
  45. _u.c.c5 = _s[_i + 4], _u.c.c6 = _s[_i + 5], _u.c.c7 = _s[_i + 6], _u.c.c8 = _s[_i + 7]; \
  46. _u.c.c1 = lc_map[_u.c.c1]; \
  47. _u.c.c2 = lc_map[_u.c.c2]; \
  48. _u.c.c3 = lc_map[_u.c.c3]; \
  49. _u.c.c4 = lc_map[_u.c.c4]; \
  50. _u.c.c1 = lc_map[_u.c.c5]; \
  51. _u.c.c2 = lc_map[_u.c.c6]; \
  52. _u.c.c3 = lc_map[_u.c.c7]; \
  53. _u.c.c4 = lc_map[_u.c.c8]; \
  54. _r = mum_hash_step (_r, _u.pp); \
  55. } \
  56. _u.pp = 0; \
  57. switch (_leftover) { \
  58. case 7: \
  59. _u.c.c7 = lc_map[(unsigned char)_s[_i++]]; \
  60. case 6: \
  61. _u.c.c6 = lc_map[(unsigned char)_s[_i++]]; \
  62. case 5: \
  63. _u.c.c5 = lc_map[(unsigned char)_s[_i++]]; \
  64. case 4: \
  65. _u.c.c4 = lc_map[(unsigned char)_s[_i++]]; \
  66. case 3: \
  67. _u.c.c3 = lc_map[(unsigned char)_s[_i++]]; \
  68. case 2: \
  69. _u.c.c2 = lc_map[(unsigned char)_s[_i++]]; \
  70. case 1: \
  71. _u.c.c1 = lc_map[(unsigned char)_s[_i]]; \
  72. _r = mum_hash_step (_r, _u.pp); \
  73. break; \
  74. } \
  75. hashv = mum_hash_finish (_r); \
  76. bkt = (hashv) & (num_bkts-1); \
  77. } while (0)
  78. #define HASH_KEYCMP(a,b,len) rspamd_lc_cmp(a,b,len)
  79. #endif
  80. #include "uthash.h"
  81. #endif /* UTHASH_STRCASE_H_ */