Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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