dict.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef XML_DICT_H_PRIVATE__
  2. #define XML_DICT_H_PRIVATE__
  3. #include <libxml/dict.h>
  4. /*
  5. * Values are ANDed with 0xFFFFFFFF to support platforms where
  6. * unsigned is larger than 32 bits. With 32-bit unsigned values,
  7. * modern compilers should optimize the operation away.
  8. */
  9. #define HASH_ROL(x,n) ((x) << (n) | ((x) & 0xFFFFFFFF) >> (32 - (n)))
  10. #define HASH_ROR(x,n) (((x) & 0xFFFFFFFF) >> (n) | (x) << (32 - (n)))
  11. /*
  12. * GoodOAAT: One of a smallest non-multiplicative One-At-a-Time functions
  13. * that passes SMHasher.
  14. *
  15. * Author: Sokolov Yura aka funny-falcon
  16. */
  17. #define HASH_INIT(h1, h2, seed) \
  18. do { \
  19. h1 = seed ^ 0x3b00; \
  20. h2 = HASH_ROL(seed, 15); \
  21. } while (0)
  22. #define HASH_UPDATE(h1, h2, ch) \
  23. do { \
  24. h1 += ch; \
  25. h1 += h1 << 3; \
  26. h2 += h1; \
  27. h2 = HASH_ROL(h2, 7); \
  28. h2 += h2 << 2; \
  29. } while (0)
  30. /* Result is in h2 */
  31. #define HASH_FINISH(h1, h2) \
  32. do { \
  33. h1 ^= h2; \
  34. h1 += HASH_ROL(h2, 14); \
  35. h2 ^= h1; h2 += HASH_ROR(h1, 6); \
  36. h1 ^= h2; h1 += HASH_ROL(h2, 5); \
  37. h2 ^= h1; h2 += HASH_ROR(h1, 8); \
  38. h2 &= 0xFFFFFFFF; \
  39. } while (0)
  40. typedef struct {
  41. unsigned hashValue;
  42. const xmlChar *name;
  43. } xmlHashedString;
  44. XML_HIDDEN void
  45. xmlInitDictInternal(void);
  46. XML_HIDDEN void
  47. xmlCleanupDictInternal(void);
  48. XML_HIDDEN unsigned
  49. xmlDictComputeHash(const xmlDict *dict, const xmlChar *string);
  50. XML_HIDDEN unsigned
  51. xmlDictCombineHash(unsigned v1, unsigned v2);
  52. XML_HIDDEN xmlHashedString
  53. xmlDictLookupHashed(xmlDictPtr dict, const xmlChar *name, int len);
  54. XML_HIDDEN void
  55. xmlInitRandom(void);
  56. XML_HIDDEN void
  57. xmlCleanupRandom(void);
  58. XML_HIDDEN unsigned
  59. xmlRandom(void);
  60. #endif /* XML_DICT_H_PRIVATE__ */