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: 
If you do not care so much about the occasional hash collision, you could simply take the sum of all the elements as a hash (but be careful of floating point issues), since that is invariant to any rotation of the vector. Alternatively, you could `xor` or sum all the hashes of the individual elements. You could also calculate something based on the difference of subsequent elements (while wrapping around for the last to the first element). Add a few of these properties that are invariant to rotation together and the chance that two 'unequal' arrays will yield the same hash will be pretty low. Maybe something like

```
n = length(x)
rot_invariant_hash = hash(n) + sum(hash(x[i])) + sum(hash(x[mod(i+1, n)] - x[i]))

```

where you can replace all the sums for any other commutative (?) operation like XOR. Also make sure that the hash-function applied on the differences is not the identity function, or these parts will all add up to zero. All this takes O(n) computation time.

Just a curiosity: what is your intended application?
I have not coded it, but I think it could work:

To get your hash you just need to capture the order of the items, and avoid the offset. Sort the items like this:

```
a = [1,9,8,7]
s = sort(a) = [1,7,8,9]

```

Now capture the order between them:

```
1 => 9
7 => 1
8 => 7
9 => 8

snext = next(s, a) = [9,1,7,8]

```

Now concat s and snext:

```
[1,7,8,9,9,1,7,8]

```

And hash it.

To implement next() function just use vector a as an associative array and iterate through s items.

The array [9,8,7,1] would yield same hash because it shares the same items and their relative order is equal.

Nevertheless, array [1,8,9,7] yields a different hash; it shares the same items but their relative order is not the same.

I hope it helps.