vrshoot

view libs/assimp/Hash.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 #ifndef AI_HASH_H_INCLUDED
42 #define AI_HASH_H_INCLUDED
44 // ------------------------------------------------------------------------------------------------
45 // Hashing function taken from
46 // http://www.azillionmonkeys.com/qed/hash.html
47 // (incremental version)
48 //
49 // This code is Copyright 2004-2008 by Paul Hsieh. It is used here in the belief that
50 // Assimp's license is considered compatible with Pauls's derivative license as specified
51 // on his web page.
52 //
53 // (stdint.h should have been been included here)
54 // ------------------------------------------------------------------------------------------------
55 #undef get16bits
56 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
57 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
58 #define get16bits(d) (*((const uint16_t *) (d)))
59 #endif
61 #if !defined (get16bits)
62 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
63 +(uint32_t)(((const uint8_t *)(d))[0]) )
64 #endif
66 // ------------------------------------------------------------------------------------------------
67 inline uint32_t SuperFastHash (const char * data, uint32_t len = 0, uint32_t hash = 0) {
68 uint32_t tmp;
69 int rem;
71 if (!data) return 0;
72 if (!len)len = (uint32_t)::strlen(data);
74 rem = len & 3;
75 len >>= 2;
77 /* Main loop */
78 for (;len > 0; len--) {
79 hash += get16bits (data);
80 tmp = (get16bits (data+2) << 11) ^ hash;
81 hash = (hash << 16) ^ tmp;
82 data += 2*sizeof (uint16_t);
83 hash += hash >> 11;
84 }
86 /* Handle end cases */
87 switch (rem) {
88 case 3: hash += get16bits (data);
89 hash ^= hash << 16;
90 hash ^= data[sizeof (uint16_t)] << 18;
91 hash += hash >> 11;
92 break;
93 case 2: hash += get16bits (data);
94 hash ^= hash << 11;
95 hash += hash >> 17;
96 break;
97 case 1: hash += *data;
98 hash ^= hash << 10;
99 hash += hash >> 1;
100 }
102 /* Force "avalanching" of final 127 bits */
103 hash ^= hash << 3;
104 hash += hash >> 5;
105 hash ^= hash << 4;
106 hash += hash >> 17;
107 hash ^= hash << 25;
108 hash += hash >> 6;
110 return hash;
111 }
113 #endif // !! AI_HASH_H_INCLUDED