fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. unsigned int hash_function(const char *k){
  5. unsigned int current = 0;
  6. unsigned int rot = 0;
  7. int i = 0;
  8. int r = 0;
  9. for(i = 0; i < strlen(k); i++){
  10. for(r = 0; r < 3; r++){
  11. rot = (rot & (1 << 31)) >> 31 | (rot << 1);
  12. }
  13. rot += k[i];
  14. current ^= rot;
  15. rot = current;
  16. }
  17. return current;
  18. }
  19.  
  20. int main() {
  21. printf("gimme: %d\n", hash_function("gimme"));
  22. printf("shelter: %d\n", hash_function("shelter"));
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
gimme: 477003
shelter: 41540041