fork download
  1. // Your First C++ Program
  2.  
  3. #include <iostream>
  4.  
  5. constexpr unsigned int hash(const char *str) {
  6. unsigned int hash = 5381;
  7. int c = 0;
  8.  
  9.  
  10.  
  11. while ((c = *str++)) {
  12. hash = ((hash << 5) + hash) + c; // hash * 33 + c
  13. }
  14.  
  15. return hash;
  16. }
  17.  
  18. int main() {
  19.  
  20. const char *str = "Inventory::getItem";
  21. int a = 5381;
  22.  
  23. for (int c = *str; c; c=*++str) {
  24. a = (((a << 5)+a)+c);
  25. }
  26.  
  27. std::cout << a << std::endl;
  28.  
  29. std::cout << hash("Level::hitResult");
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
846870678
310980725