Skip to content
Snippets Groups Projects
bytes.go 26.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • 		hash = hash*primeRK + uint32(sep[i])
    	}
    	var pow, sq uint32 = 1, primeRK
    	for i := len(sep); i > 0; i >>= 1 {
    		if i&1 != 0 {
    			pow *= sq
    		}
    		sq *= sq
    	}
    	return hash, pow
    }
    
    
    // hashStrRev returns the hash of the reverse of sep and the
    // appropriate multiplicative factor for use in Rabin-Karp algorithm.
    func hashStrRev(sep []byte) (uint32, uint32) {
    	hash := uint32(0)
    	for i := len(sep) - 1; i >= 0; i-- {
    		hash = hash*primeRK + uint32(sep[i])
    	}
    	var pow, sq uint32 = 1, primeRK
    	for i := len(sep); i > 0; i >>= 1 {
    		if i&1 != 0 {
    			pow *= sq
    		}
    		sq *= sq
    	}
    	return hash, pow
    }