package main // hasher defines the methods required to hash a string type hasher struct { next int } // newHasher returns a hasher type func newHasher() hasher { return hasher{} } // run processes each step of the hasher for each char in a string func (h hasher) run(in string) int { hash := 0 for _, r := range in { h.next = hash + int(r) hash = h.multiply().modulus() } return hash } func (h hasher) multiply() hasher { h.next *= 17 return h } func (h hasher) modulus() int { return h.next % 256 }