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

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

Changes to icxercesc 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#include <icxmlc/XMLConfig.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31//
32// Common hashers. Only widely-used hashers should be placed here.
33//
34
35/**
36 * Hasher for keys that are const XMLCh*.
37 */
38struct StringHasher
39{
40        /**
41         * Returns a hash value based on the key
42         *
43         * @param key the key to be hashed
44         * @param mod the modulus the hasher should use
45         */
46        inline XMLSize_t getHashVal(const void* key, XMLSize_t mod) const
47        {
48        return XMLString::hash ((const XMLCh*)key, mod);
49        // return getHashVal(key, XMLString::stringLen((const XMLCh*)key), mod);
50        }
51
52        /**
53         * Returns a hash value based on the key
54         *
55         * @param key the key to be hashed
56         * @param mod the modulus the hasher should use
57         */
58        inline XMLSize_t getHashVal(const void* rawKey, const unsigned int length, XMLSize_t mod) const
59        {
60        return XMLString::hashN((const XMLCh*)rawKey, length, mod);
61        // return (XMLSize_t)(Murmur3<XMLCh>::hash((const XMLCh*)rawKey, length, (XMLSize_t)(0x374a3ea6e0ad6ecb))) % mod;
62        }
63
64        /**
65         * Compares two keys and determines if they are semantically equal
66         *
67         * @param key1 the first key to be compared
68         * @param key2 the second key to be compared
69         *
70         * @return true if they are equal
71         */
72        inline bool equals(const void *const key1, const void *const key2) const
73        {
74                return XMLString::equals ((const XMLCh*)key1, (const XMLCh*)key2);
75        }
76};
77
78/**
79 * Hasher for keys that are pointers.
80 */
81struct PtrHasher
82{
83        /**
84        * Returns a hash value based on the key
85        *
86        * @param key the key to be hashed
87        * @param mod the modulus the hasher should use
88        */
89        inline XMLSize_t getHashVal(const void* key, XMLSize_t mod) const
90        {
91                return ((XMLSize_t)key) % mod;
92        }
93
94        /**
95        * Returns a hash value based on the key
96        *
97        * @param key the key to be hashed
98        * @param mod the modulus the hasher should use
99        */
100        inline XMLSize_t getHashVal(const void* rawKey, const unsigned int, XMLSize_t mod) const
101        {
102                return getHashVal(rawKey, mod);
103        }
104
105
106        /**
107        * Compares two keys and determines if they are semantically equal
108        *
109        * @param key1 the first key to be compared
110        * @param key2 the second key to be compared
111        *
112        * @return true if they are equal
113        */
114        inline bool equals(const void *const key1, const void *const key2) const
115        {
116                return key1 == key2;
117        }
118};
119
120XERCES_CPP_NAMESPACE_END
121
122#endif
Note: See TracBrowser for help on using the repository browser.