码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 分享一个生成哈希值的C代码


    代码是我在阅读assimp源码时看到的,不依赖任何第三方,可直接集成。

    1. #pragma once
    2. #ifndef AI_HASH_H_INCLUDED
    3. #define AI_HASH_H_INCLUDED
    4. #ifdef __GNUC__
    5. # pragma GCC system_header
    6. #endif
    7. #include
    8. #include
    9. #include
    10. // ------------------------------------------------------------------------------------------------
    11. // Hashing function taken from
    12. // http://www.azillionmonkeys.com/qed/hash.html
    13. // (incremental version)
    14. //
    15. // This code is Copyright 2004-2008 by Paul Hsieh. It is used here in the belief that
    16. // Assimp's license is considered compatible with Pauls's derivative license as specified
    17. // on his web page.
    18. //
    19. // (stdint.h should have been been included here)
    20. // ------------------------------------------------------------------------------------------------
    21. #undef get16bits
    22. #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
    23. || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
    24. #define get16bits(d) (*((const uint16_t *) (d)))
    25. #endif
    26. #if !defined (get16bits)
    27. #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
    28. +(uint32_t)(((const uint8_t *)(d))[0]) )
    29. #endif
    30. // ------------------------------------------------------------------------------------------------
    31. inline uint32_t SuperFastHash (const char * data, uint32_t len = 0, uint32_t hash = 0) {
    32. uint32_t tmp;
    33. int rem;
    34. if (!data) return 0;
    35. if (!len)len = (uint32_t)::strlen(data);
    36. rem = len & 3;
    37. len >>= 2;
    38. /* Main loop */
    39. for (;len > 0; len--) {
    40. hash += get16bits (data);
    41. tmp = (get16bits (data+2) << 11) ^ hash;
    42. hash = (hash << 16) ^ tmp;
    43. data += 2*sizeof (uint16_t);
    44. hash += hash >> 11;
    45. }
    46. /* Handle end cases */
    47. switch (rem) {
    48. case 3: hash += get16bits (data);
    49. hash ^= hash << 16;
    50. hash ^= abs(data[sizeof(uint16_t)]) << 18;
    51. hash += hash >> 11;
    52. break;
    53. case 2: hash += get16bits (data);
    54. hash ^= hash << 11;
    55. hash += hash >> 17;
    56. break;
    57. case 1: hash += *data;
    58. hash ^= hash << 10;
    59. hash += hash >> 1;
    60. }
    61. /* Force "avalanching" of final 127 bits */
    62. hash ^= hash << 3;
    63. hash += hash >> 5;
    64. hash ^= hash << 4;
    65. hash += hash >> 17;
    66. hash ^= hash << 25;
    67. hash += hash >> 6;
    68. return hash;
    69. }
    70. #endif // !! AI_HASH_H_INCLUDED

  • 相关阅读:
    python爬虫入门教程(非常详细):如何快速入门Python爬虫?
    游戏设计模式专栏(六):在Cocos游戏开发中运用适配器模式
    人工智能知识
    golang操作ES
    java计算机毕业设计智能推荐的医药知识推广平台统源码+数据库+系统+lw文档
    【计算机网络笔记二】网络层
    【正点原子STM32连载】 第三十一章 睡眠模式实验 摘自【正点原子】APM32F407最小系统板使用指南
    数据驭王: PostgreSQL教程指南解密
    36 数据增广【李沐动手学深度学习v2课程笔记】
    探店通系统源码。短视频矩阵源码,here here here。
  • 原文地址:https://blog.csdn.net/u013001137/article/details/134536410
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号