tb_hash.cpp 714 B

1234567891011121314151617181920212223242526272829
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #include "tb_hash.h"
  6. namespace tb {
  7. #ifndef TB_SUPPORT_CONSTEXPR
  8. uint32 TBGetHash(const char *str)
  9. {
  10. if (!str || !*str)
  11. return 0;
  12. // FNV hash
  13. uint32 hash = 2166136261U;
  14. int i = 0;
  15. while (str[i])
  16. {
  17. char c = str[i++];
  18. hash = (16777619U * hash) ^ c;
  19. }
  20. return hash;
  21. }
  22. #endif // !TB_SUPPORT_CONSTEXPR
  23. }; // namespace tb