source: icXML/icXML-devel/src/icxercesc/util/Hashers.hpp @ 2721

Last change on this file since 2721 was 2721, checked in by cameron, 6 years ago

Fix imports in icXML modified Xerces files

File size: 3.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: Hashers.hpp 679382 2008-07-24 12:09:39Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_HASHERS_HPP)
23#define XERCESC_INCLUDE_GUARD_HASHERS_HPP
24
25#include <icxercesc/util/XMLString.hpp>
26// #include <icxmlc/murmurhash3.h>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30//
31// Common hashers. Only widely-used hashers should be placed here.
32//
33
34/**
35 * Hasher for keys that are const XMLCh*.
36 */
37struct StringHasher
38{
39        /**
40         * Returns a hash value based on the key
41         *
42         * @param key the key to be hashed
43         * @param mod the modulus the hasher should use
44         */
45        inline XMLSize_t getHashVal(const void* key, XMLSize_t mod) const
46        {
47        return XMLString::hash ((const XMLCh*)key, mod);
48        // return getHashVal(key, XMLString::stringLen((const XMLCh*)key), mod);
49        }
50
51        /**
52         * Returns a hash value based on the key
53         *
54         * @param key the key to be hashed
55         * @param mod the modulus the hasher should use
56         */
57        inline XMLSize_t getHashVal(const void* rawKey, const unsigned int length, XMLSize_t mod) const
58        {
59        return XMLString::hashN((const XMLCh*)rawKey, length, mod);
60        // return (XMLSize_t)(Murmur3<XMLCh>::hash((const XMLCh*)rawKey, length, (XMLSize_t)(0x374a3ea6e0ad6ecb))) % mod;
61        }
62
63        /**
64         * Compares two keys and determines if they are semantically equal
65         *
66         * @param key1 the first key to be compared
67         * @param key2 the second key to be compared
68         *
69         * @return true if they are equal
70         */
71        inline bool equals(const void *const key1, const void *const key2) const
72        {
73                return XMLString::equals ((const XMLCh*)key1, (const XMLCh*)key2);
74        }
75};
76
77/**
78 * Hasher for keys that are pointers.
79 */
80struct PtrHasher
81{
82        /**
83        * Returns a hash value based on the key
84        *
85        * @param key the key to be hashed
86        * @param mod the modulus the hasher should use
87        */
88        inline XMLSize_t getHashVal(const void* key, XMLSize_t mod) const
89        {
90                return ((XMLSize_t)key) % mod;
91        }
92
93        /**
94        * Returns a hash value based on the key
95        *
96        * @param key the key to be hashed
97        * @param mod the modulus the hasher should use
98        */
99        inline XMLSize_t getHashVal(const void* rawKey, const unsigned int, XMLSize_t mod) const
100        {
101                return getHashVal(rawKey, mod);
102        }
103
104
105        /**
106        * Compares two keys and determines if they are semantically equal
107        *
108        * @param key1 the first key to be compared
109        * @param key2 the second key to be compared
110        *
111        * @return true if they are equal
112        */
113        inline bool equals(const void *const key1, const void *const key2) const
114        {
115                return key1 == key2;
116        }
117};
118
119XERCES_CPP_NAMESPACE_END
120
121#endif
Note: See TracBrowser for help on using the repository browser.