fork download
  1. function djb2gawk(str, n, i, hash, ascii) {
  2.  
  3. hash = 5381
  4. n = length(str)
  5.  
  6. for(i = 1; i <= n; ++i) {
  7. char = substr(str, i, 1)
  8. ascii = alphanum(char)
  9. hash = (hash * 33 + ascii) % ((2^32) - 1)
  10. }
  11.  
  12. return hash
  13. }
  14.  
  15. function alphanum(char) {
  16.  
  17. return index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", char)
  18. }
  19.  
  20. BEGIN {
  21. str = "comp.lang.awk"
  22. print djb2gawk(str)
  23. }
  24.  
Success #stdin #stdout 0.01s 5544KB
stdin
Standard input is empty
stdout
2539534577