hash.h 563 B

12345678910111213141516171819202122232425262728
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef HASH_H
  3. #define HASH_H
  4. static inline unsigned int hash_str(const char *s)
  5. {
  6. /* fnv32 hash */
  7. unsigned int hash = 2166136261U;
  8. for (; *s; s++)
  9. hash = (hash ^ *s) * 0x01000193;
  10. return hash;
  11. }
  12. /* simplified version of functions from include/linux/hash.h */
  13. #define GOLDEN_RATIO_32 0x61C88647
  14. static inline unsigned int hash_32(unsigned int val)
  15. {
  16. return 0x61C88647 * val;
  17. }
  18. static inline unsigned int hash_ptr(const void *ptr)
  19. {
  20. return hash_32((unsigned int)(unsigned long)ptr);
  21. }
  22. #endif /* HASH_H */