HashMap.c 424 B

123456789101112131415161718192021222324
  1. #include "core/HashMap.h"
  2. size_t hashString(const char* key) {
  3. size_t h = 0;
  4. while(*key != '\0') {
  5. h = 2'120'251'889lu * h + (size_t)(*(key++));
  6. }
  7. return h;
  8. }
  9. size_t roundUp2(size_t n) {
  10. n -= n != 0;
  11. n |= n >> 1;
  12. n |= n >> 2;
  13. n |= n >> 4;
  14. n |= n >> 8;
  15. if(sizeof(n) >= 4) {
  16. n |= n >> 16;
  17. }
  18. if(sizeof(n) >= 8) {
  19. n |= n >> 32;
  20. }
  21. return n + 1;
  22. }