File size: 1,783 Bytes
6baed57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef XML_DICT_H_PRIVATE__
#define XML_DICT_H_PRIVATE__

#include <libxml/dict.h>

/*
 * Values are ANDed with 0xFFFFFFFF to support platforms where
 * unsigned is larger than 32 bits. With 32-bit unsigned values,
 * modern compilers should optimize the operation away.
 */

#define HASH_ROL(x,n) ((x) << (n) | ((x) & 0xFFFFFFFF) >> (32 - (n)))
#define HASH_ROR(x,n) (((x) & 0xFFFFFFFF) >> (n) | (x) << (32 - (n)))

/*
 * GoodOAAT: One of a smallest non-multiplicative One-At-a-Time functions
 * that passes SMHasher.
 *
 * Author: Sokolov Yura aka funny-falcon
 */

#define HASH_INIT(h1, h2, seed) \
    do { \
        h1 = seed ^ 0x3b00; \
        h2 = HASH_ROL(seed, 15); \
    } while (0)

#define HASH_UPDATE(h1, h2, ch) \
    do { \
        h1 += ch; \
        h1 += h1 << 3; \
        h2 += h1; \
        h2 = HASH_ROL(h2, 7); \
        h2 += h2 << 2; \
    } while (0)

/* Result is in h2 */
#define HASH_FINISH(h1, h2) \
    do { \
        h1 ^= h2; \
        h1 += HASH_ROL(h2, 14); \
        h2 ^= h1; h2 += HASH_ROR(h1, 6); \
        h1 ^= h2; h1 += HASH_ROL(h2, 5); \
        h2 ^= h1; h2 += HASH_ROR(h1, 8); \
        h2 &= 0xFFFFFFFF; \
    } while (0)

typedef struct {
    unsigned hashValue;
    const xmlChar *name;
} xmlHashedString;

XML_HIDDEN void
xmlInitDictInternal(void);
XML_HIDDEN void
xmlCleanupDictInternal(void);

XML_HIDDEN unsigned
xmlDictComputeHash(const xmlDict *dict, const xmlChar *string);
XML_HIDDEN unsigned
xmlDictCombineHash(unsigned v1, unsigned v2);
XML_HIDDEN xmlHashedString
xmlDictLookupHashed(xmlDict *dict, const xmlChar *name, int len);

XML_HIDDEN void
xmlInitRandom(void);
XML_HIDDEN void
xmlCleanupRandom(void);
XML_HIDDEN unsigned
xmlGlobalRandom(void);
XML_HIDDEN unsigned
xmlRandom(void);

#endif /* XML_DICT_H_PRIVATE__ */