Last active
          April 3, 2020 19:27 
        
      - 
      
- 
        Save jshahbazi/5941740 to your computer and use it in GitHub Desktop. 
    Daniel J. Bernstein's hash algorithm written in Fortran
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | integer function djb_hash(str) result(hash) | |
| implicit none | |
| character(len=*),intent(in) :: str | |
| integer :: hash | |
| integer :: i | |
| hash = 5381 | |
| do i=1,len(str) | |
| hash = (ishft(hash,5) + hash) + ichar(str(i:i)) | |
| end do | |
| end function DJB_hash | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
I actually tried this and you still get hash collisions under certain circumstances:
I think that by the nature of hashing, there will always be cases where collisions occur. You will probably always need some kind of "tiebreaker" algorithm to resolve collisions.