Question: Is there any hash function that generates the same bucket for vectors having the same elements, with the same relative positions but shifted **k** times?

For example:

```
hash([1,9,8,7]) -> b1
hash([9,8,7,1]) -> b1

hash([1,8,9,7]) -> b2
hash([1,9,8,5]) -> b3

```

**v1** = [1,9,8,7] **v2** = [9,8,7,1] Both vectors should get the same hash since **v2** is **v1** left shifted k=3 times.

But **v3** = [1,8,9,7] doesn't keep the same relative order and **v4** = [1,9,8,5] has different values so neither of them get the hash b1.

My initial approach was to calculte the max value for each vector and consider its position as a reference (offset = 0). Having that I would only have to shift each vector so that the maximun value would be always at the first position. This way shifted vectors would look the same. However, vectors can have repeated elements and thus the maximun value has different positions.

Answer: 
1. Find the lexicographically minimal array rotation.

The native way is to check all rotations in O(n2), but it can be done in linear time using Booth's Algorithm, Shiloach's Fast Canonization Algorithm or Duval's Lyndon Factorization Algorithm.

See [this](http://en.wikipedia.org/wiki/Lexicographically_minimal_string_rotation) for more.
2. Calculate the hash of the rotated array.

This can be done in various ways. Java, for example, would do it as follows:

```
hash = s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

```

It's not impossible that arrays with different elements will hash to the same value (this is inevitable with hashing), but all rotations of the same array will have the same hash.
assuming that you always have numbers as vector components, compute:

* the product of all components
* the product of all differences `d_i` of neighboring components (`i`, `(i+1) mod n`),
where 1 is added for all non-negative differences

and multiply both. 

the first product abstracts away from the order of the elements, which is re-introduced by the second product modulo component rotation. adding 1 to each difference avoids mapping to 0 if there are 2 adjacent components of the same value.

the standalone first product does not suffice, as it maps all component permutations to the same hash value.
the standalone second product does not suffice, as it maps all vectors offset along (1,...,1) to the same value.