chash implementation (ported from https://github.com/dgryski/libchash)