Generic k-way hashing function