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