Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / Core / NptHash.cpp
blob05d6aa45ea9033f966f04aa8d2369c84ce60a043
1 /*****************************************************************
3 | Neptune - Hashing
5 | Copyright (c) 2002-2010, Axiomatic Systems, LLC.
6 | All rights reserved.
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ****************************************************************/
32 /*----------------------------------------------------------------------
33 | includes
34 +---------------------------------------------------------------------*/
35 #include "NptTypes.h"
36 #include "NptResults.h"
37 #include "NptHash.h"
39 /*----------------------------------------------------------------------
40 | local constants
41 +---------------------------------------------------------------------*/
42 // 32 bit magic FNV-1a prime
43 const NPT_UInt32 NPT_FNV_32_PRIME = 0x01000193;
45 /*----------------------------------------------------------------------
46 | NPT_Fnv1aHash32
47 +---------------------------------------------------------------------*/
48 NPT_UInt32
49 NPT_Fnv1aHash32(const NPT_UInt8* data, NPT_Size data_size, NPT_UInt32 hash_init)
51 const NPT_UInt8* data_end = data + data_size;
52 NPT_UInt32 hash_value = hash_init;
54 while (data < data_end) {
55 hash_value ^= (NPT_UInt32)*data++;
57 #if defined(NPT_CONFIG_FNV_HASH_USE_SHIFT_MUL)
58 hash_value += (hash_value<<1) + (hash_value<<4) + (hash_value<<7) + (hash_value<<8) + (hash_value<<24);
59 #else
60 hash_value *= NPT_FNV_32_PRIME;
61 #endif
64 return hash_value;
68 /*----------------------------------------------------------------------
69 | NPT_Fnv1aHashStr32
70 +---------------------------------------------------------------------*/
71 NPT_UInt32
72 NPT_Fnv1aHashStr32(const char* data, NPT_UInt32 hash_init)
74 NPT_UInt32 hash_value = hash_init;
76 while (*data) {
77 hash_value ^= (NPT_UInt32)*data++;
79 #if defined(NPT_CONFIG_FNV_HASH_USE_SHIFT_MUL)
80 hash_value += (hash_value<<1) + (hash_value<<4) + (hash_value<<7) + (hash_value<<8) + (hash_value<<24);
81 #else
82 hash_value *= NPT_FNV_32_PRIME;
83 #endif
86 return hash_value;
89 /*----------------------------------------------------------------------
90 | NPT_FnvHash32
91 +---------------------------------------------------------------------*/
92 // 64 bit magic FNV-1a prime
93 const NPT_UInt64 NPT_FNV_64_PRIME = 0x100000001b3ULL;
95 /*----------------------------------------------------------------------
96 | NPT_Fnv1aHash64
97 +---------------------------------------------------------------------*/
98 NPT_UInt64
99 NPT_Fnv1aHash64(const NPT_UInt8* data, NPT_Size data_size, NPT_UInt64 hash_init)
101 const NPT_UInt8* data_end = data + data_size;
102 NPT_UInt64 hash_value = hash_init;
104 while (data < data_end) {
105 hash_value ^= (NPT_UInt64)*data++;
107 #if defined(NPT_CONFIG_FNV_HASH_USE_SHIFT_MUL)
108 hash_value += (hash_value << 1) + (hash_value << 4) + (hash_value << 5) + (hash_value << 7) + (hash_value << 8) + (hash_value << 40);
109 #else
110 hash_value *= NPT_FNV_64_PRIME;
111 #endif
114 return hash_value;
118 /*----------------------------------------------------------------------
119 | NPT_Fnv1aHashStr64
120 +---------------------------------------------------------------------*/
121 NPT_UInt64
122 NPT_Fnv1aHashStr64(const char* data, NPT_UInt64 hash_init)
124 NPT_UInt64 hash_value = hash_init;
126 while (*data) {
127 hash_value ^= (NPT_UInt64)*data++;
129 #if defined(NPT_CONFIG_FNV_HASH_USE_SHIFT_MUL)
130 hash_value += (hash_value << 1) + (hash_value << 4) + (hash_value << 5) + (hash_value << 7) + (hash_value << 8) + (hash_value << 40);
131 #else
132 hash_value *= NPT_FNV_64_PRIME;
133 #endif
136 return hash_value;